Lesson 6 of 9 · Building
Connecting a Server to an AI App
Connect an MCP server to AI apps: launch commands, Claude Desktop's config, Claude Code, Cursor and VS Code settings, environment variables and troubleshooting.
- 6 min read
- Intermediate
- Reviewed
- Write the launch command a host uses to start your server
- Connect a server to Claude Desktop, Claude Code, Cursor and VS Code
- Pass settings with environment variables
- Troubleshoot the most common connection problems
One launch command
For a local (stdio) server, every host needs the same thing: a command that starts your server. The Python SDK's recommended launch command uses uv, a fast Python package manager, to run the server with the SDK available:
uv run --with "mcp[cli]" mcp run /absolute/path/to/notes_server.pyRun it yourself in a terminal first. A working stdio server prints nothing and waits for messages. A traceback or immediate exit is the problem to fix before going further.
Host by host
Claude Desktop. The quickest way is uv run mcp install notes_server.py, which writes the configuration for you. Or edit the config file by hand:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
Then fully quit and reopen Claude Desktop. The program below builds that file's content and checks for the most common mistake:
import json
# Where things live on this (example) computer: use ABSOLUTE paths
UV = "/Users/ana/.local/bin/uv"
SERVER = "/Users/ana/projects/notes/notes_server.py"
claude_desktop = {
"mcpServers": {
"notes": {
"command": UV,
"args": ["run", "--with", "mcp[cli]", "mcp", "run", SERVER],
"env": {"NOTES_LANGUAGE": "en"}, # hosts start servers with few environment variables
}
}
}
print("claude_desktop_config.json:")
print(json.dumps(claude_desktop, indent=2))
# A quick check for the most common mistake: relative paths
def check_config(config, key="mcpServers"):
problems = []
for name, server in config[key].items():
for part in [server["command"], *server.get("args", [])]:
if part.endswith(".py") and not part.startswith("/"):
problems.append(f"{name}: '{part}' is a relative path; the host won't find it")
return problems or ["looks fine"]
broken = {"mcpServers": {"notes": {"command": "uv", "args": ["run", "mcp", "run", "notes_server.py"]}}}
print("\nChecking the good config:", check_config(claude_desktop))
print("Checking a broken config:", check_config(broken))Claude Code. Register the server with one command; everything after -- is the launch command. Then type /mcp in a session to check it's connected:
claude mcp add notes -- uv run --with "mcp[cli]" mcp run /absolute/path/to/notes_server.pyCursor. Create .cursor/mcp.json in your project, with the same mcpServers structure as Claude Desktop.
VS Code. Create .vscode/mcp.json, using the key servers (not mcpServers) and adding "type": "stdio" to each entry. It works with Copilot Chat's agent mode.
Remote servers. For a server running over Streamable HTTP, hosts take a URL instead of a command, usually entered in the app's connector settings, and handle sign-in if the server requires it.
When it doesn't connect
| Symptom | Likely cause | Fix |
|---|---|---|
| Server never appears | Relative path, or the host can't find uv or python | Use absolute paths for the script and the command |
| Appears, then disconnects | Something printed to standard output | Log to standard error only |
| Tools fail with missing settings | Environment variables not passed | Add them to the config's env |
| Changes don't show up | The host reads config only at start | Restart the host after every change |
Claude Desktop also writes a log per server (mcp-server-<name>.log) containing the server's error output: the first place to look.
Common mistakes
Write the configuration that tells a code editor how to start your MCP server.
import json
server_path = "/home/li/tools/weather_server.py"
# VS Code reads .vscode/mcp.json. Unlike Claude Desktop it uses the key "servers",
# and each entry needs "type": "stdio". Build the config for a server named "weather"
# that runs: python <server_path>
config = {}
print(json.dumps(config, sort_keys=True))
Your server works when you run it in a terminal but never connects in the AI app. What is the most common cause?
Summary
- A local server needs one launch command; test it in a terminal first.
- Claude Desktop and Cursor use
mcpServerswithcommandandargs; Claude Code usesclaude mcp add; VS Code usesserverswith"type": "stdio". - Use absolute paths, pass settings in env, keep stdout clean, and restart the host after changes.
- Remote servers connect by URL, with sign-in handled by the host.
Next: keeping MCP setups secure.
Finished reading? Tick it off to track your progress.