Start learning free

LESSON 54 OF 129 · AI ENGINEERING: MCP

Use It from Claude Desktop and Claude Code in Python

Practice

Your assistant started the shop's MCP server itself, with a line of Python. Apps like Claude Desktop and Claude Code can use the same server with no code at all. They read a small config file that says how to start it.

The shape of the file: it is JSON. Under the key "mcpServers" each server has a name you choose, a "command" (the program to run) and "args" (the list of what comes after it). Here is the config for a weather server written in JavaScript:

{
  "mcpServers": {
    "weather": {
      "command": "node",
      "args": ["/home/ana/weather/server.js"]
    }
  }
}

The app starts the server from its own folder, not from yours. So a bare file name would not be found: the file needs its absolute path, the full address on the computer. In Python, os.path.abspath("notes.txt") turns a file name into its absolute path, and json.dump(data, f, indent=2) writes a dictionary to an open file as JSON.

Claude Desktop reads a file named claude_desktop_config.json. Claude Code reads the same shape from .mcp.json in a project's folder. The check reads both files, starts the server exactly as they say, from another folder like an app would, and asks it for its tools:

claude_desktop_config.json
  server: corner-shop
    command: python3
    args: <absolute path>/shop_mcp_server.py
    started from another folder: its tools: lookup_order, find_orders
.mcp.json
  server: corner-shop
    command: python3
    args: <absolute path>/shop_mcp_server.py
    started from another folder: its tools: lookup_order, find_orders

Your task: the server's file name is already in server_file. Build the config as a Python dictionary: the file's absolute path, then the "command" and the "args", then "mcpServers" with the name "corner-shop". Write it as JSON to claude_desktop_config.json and to .mcp.json.


Assignment
Follow the Coding Tutorial to write the config file that lets Claude Desktop and Claude Code start the shop's MCP server.


Hint
"args" is a list, even with one item in it. The key is "mcpServers" with a capital S, and json.dump takes the dictionary first and the open file second.


STEP 1 OF 7
    Ctrl + Enter to check

    Ai Mcp Desktop in Python

    Keep going with Python1,600+ step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free