# Python MCP server quickstart: build and connect one locally

> Canonical: https://skillalmanac.com/learn/python-mcp-server-quickstart | Updated: 2026-11-21 | Index status: not offered to search engines

Build a small Python MCP server with the mcp SDK, run it over stdio with uv, and connect it to an MCP client configuration file.

## Facts

- 2026-11-21: The quickstart lists Python 3.10 or higher and MCP Python SDK 2.0.0 or higher as system requirements (https://modelcontextprotocol.io/docs/develop/build-server)
- 2026-11-21: The python-sdk README lists Python 3.11+ and installs with uv add "mcp[cli]" or pip install "mcp[cli]" (https://github.com/modelcontextprotocol/python-sdk)
- 2026-11-21: The quickstart builds the server with MCPServer imported from mcp.server, and tool definitions are generated from type hints and docstrings on functions decorated with @mcp.tool() (https://modelcontextprotocol.io/docs/develop/build-server)
- 2026-11-21: The quickstart starts the server with mcp.run(transport="stdio") inside an if __name__ == "__main__" guard (https://modelcontextprotocol.io/docs/develop/build-server)
- 2026-11-21: The python-sdk README shows uv run mcp dev server.py as the development command and lists stdio, Streamable HTTP, and SSE as transports (https://github.com/modelcontextprotocol/python-sdk)
- 2026-11-21: The quickstart registers a local server under the mcpServers key with command uv and args --directory, run, and the script name (https://modelcontextprotocol.io/docs/develop/build-server)

A Python MCP server is a script that declares tools with the `mcp` SDK and serves them to a client over stdio. You can build a working one in a single file, run it with `uv`, and register it in a client's MCP configuration as of 2026-11-21.

## Steps

1. Install `uv` using the installer from the quickstart. On macOS or Linux, run `curl -LsSf https://astral.sh/uv/install.sh | sh`. On Windows, run `powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"`. Restart the terminal so `uv` is on the path.
2. Create the project and install the SDK. Run `uv init weather`, then `cd weather`, `uv venv`, and `uv add "mcp[cli]"`. The quoted extra pulls in the `mcp` command-line tool. Install plain `mcp` if you do not need that tool.
3. Create `weather.py` in the project folder and import the server class with `from mcp.server import MCPServer`. Create the instance with `mcp = MCPServer("weather")`.
4. Declare each tool as an `async def` decorated with `@mcp.tool()`. Give every parameter a type hint, and write a docstring. The SDK turns the hints and the docstring into the tool's input schema and description, so the docstring is what the model reads when it decides whether to call the tool.
5. Raise an error for failures you want the client to see. The quickstart raises `ToolError` from `mcp.server.mcpserver.exceptions` when an upstream request fails, instead of returning an empty string that looks like a valid answer.
6. End the file with the entry point guard: `if __name__ == "__main__":` followed by `mcp.run(transport="stdio")`.
7. Open the client configuration file. For Claude's local app, the quickstart names `claude_desktop_config.json`. Add an entry under `mcpServers`, using the absolute path to the project folder:

```json
{
  "mcpServers": {
    "weather": {
      "command": "uv",
      "args": ["--directory", "C:\\ABSOLUTE\\PATH\\TO\\weather", "run", "weather.py"]
    }
  }
}
```

On Windows, use double backslashes or forward slashes in the path. If the client cannot find `uv`, put the full output of `where uv` (Windows) or `which uv` (macOS or Linux) in the `command` field.

8. Restart the client so it reads the configuration again.

## Check that it works

Run `uv run mcp dev weather.py` from the project folder. The `mcp` CLI starts a development session for the file, which is a quicker check than waiting for a full client to launch the process. Then restart the client and confirm the server appears in its tool list. Call one tool with a known input. If the server appears but no tools show, the decorator is missing on the function, or the function is defined after the `if __name__` block.

## Pitfalls

- **Logging to stdout breaks the stdio stream.** Over stdio, the protocol messages travel on stdout. A stray `print()` writes text the client cannot parse. Use the `logging` module, which the quickstart writes to stderr, and remove debug prints before connecting a client.
- **Relative paths in the config.** The client starts the process from its own working folder, not yours. Always use the absolute project path with `--directory`, and test with `uv run weather.py` from another folder to confirm the path resolves.
- **Missing type hints produce weak tool schemas.** A parameter without a hint gives the model little to work with. Add `str`, `int`, `float`, or `dict[str, Any]` hints, and check the schema the dev session shows.
- **Mismatched SDK versions.** The quickstart requires SDK 2.0.0 or higher, and the README's import paths can differ from older tutorials you find online. If `from mcp.server import MCPServer` fails, check the installed version with `uv pip show mcp`.
- **Ambiguous Python version.** The quickstart says 3.10 or higher, while the README says 3.11+. Pin the interpreter with `uv` and use 3.11 or later if you want to match the README.

## When to use a skill instead

A one-file server is a good first exercise, but a production server needs decisions about tool granularity, output size, error shape, and whether a tool or a resource fits the data. The [mcp-server-builder](/skills/skill-almanac/mcp-server-builder) skill covers those design choices, including JSON Schema inputs, bounded outputs, and stdio versus HTTP transport. The [python-practices](/skills/skill-almanac/python-practices) skill reviews the Python code itself, so typing, structure, and modern idioms get the same check as the MCP design. Use the skills once the quickstart works and you are deciding what the server should expose. Ask a general prompt only for the first working file.

## FAQ

**How do I create an MCP server in Python?**
Install the SDK with `uv add "mcp[cli]"`, create an `MCPServer` instance, decorate functions with `@mcp.tool()`, and end the file with `mcp.run(transport="stdio")`. Then register the file under `mcpServers` in your client's configuration.

**What is an MCP server?**
An MCP server is a process that exposes capabilities to a client through the Model Context Protocol. The quickstart describes three kinds: resources, which are readable data; tools, which are functions the model can call with user approval; and prompts, which are reusable templates.

**Do I need the cli extra?**
No. The `[cli]` extra adds the `mcp` command, which provides the development session used in the check step. The server runs without it, but you lose that quick test path.

## Related skills

- [mcp-server-builder](https://skillalmanac.com/skills/skill-almanac/mcp-server-builder.md): Platform Score 56/100 (provisional)
- [python-practices](https://skillalmanac.com/skills/skill-almanac/python-practices.md): Platform Score 57/100 (provisional)

## Related guides

- [Debug an MCP Server with MCP Inspector](https://skillalmanac.com/learn/debug-an-mcp-server-with-inspector.md)
- [MCP Server Examples: Learning From a Reference Server](https://skillalmanac.com/learn/mcp-server-examples.md)
- [MCP Client vs MCP Server: Who Starts Calls and Holds Keys](https://skillalmanac.com/learn/mcp-client-vs-mcp-server.md)
- [What Are MCP Apps? Interactive UI in AI Chats](https://skillalmanac.com/learn/what-are-mcp-apps.md)
- [AWS MCP Server: Connect an Agent Read-Only First](https://skillalmanac.com/learn/aws-mcp-server-guide.md)

## Sources

- https://modelcontextprotocol.io/docs/develop/build-server
- https://github.com/modelcontextprotocol/python-sdk

Platform Scores report our assessment under a published method. They are not a safety guarantee.
