Build Your Own MCP Server: From First Python Server to Claude (2026)

Build an MCP server that connects your own tools and data to Claude. We set up the environment with uv, write a minimal server with FastMCP, and connect it to Claude step by step.

If the tool or data you need is not among the existing connectors, you can build your own MCP server and attach it to Claude. It sounds hard, but in Python the core is surprisingly short — set up the environment, register one function as a "tool," and connect it to Claude. This guide walks through building a minimal MCP server and connecting it to Claude, step by step.

Build an MCP server — 4 stepsBuild an MCP server — 4 steps1. Set upuv · MCP SDK2. Write tool@mcp.tool()3. Connectconfig · mcp add4. Testcall the tool

What an MCP server does

An MCP server is a small program that tells an AI like Claude "here are tools you can use" and actually runs them. Wrap things like an internal DB query, a specific API call, or file handling as tools, and Claude can call them mid-conversation. New to the idea? Start with a simple explanation of MCP and how MCP is structured. For what connectors and servers exist, see the connector & MCP catalog.

What you need

This example uses Python. For package and run management we use uv, same as the official quickstart (Python 3.10+ recommended). To build in JavaScript instead, see "Building it in TypeScript" below.

1) Set up the environment

Install uv, create a project, and add the MCP SDK.

curl -LsSf https://astral.sh/uv/install.sh | sh

uv init demo
cd demo
uv venv
source .venv/bin/activate
uv add "mcp[cli]"
touch server.py

The commands above are for macOS/Linux. For full environment setup including Windows, see the official "Build an MCP server" docs.

2) Write a tool

Add a function in server.py and register it with @mcp.tool() — that function becomes a tool Claude can call. The function’s docstring becomes the tool description, so write it clearly.

from mcp.server.fastmcp import FastMCP

mcp = FastMCP("demo")

@mcp.tool()
def add(a: int, b: int) -> int:
    """Add two integers."""
    return a + b

if __name__ == "__main__":
    mcp.run(transport="stdio")

Here we registered just an "add" tool. In practice you add functions like DB queries or API calls the same way. Type hints on arguments (e.g. a: int) help Claude fill in values more accurately.

3) Connect it to Claude

To use it in Claude Desktop, register the server in the config file claude_desktop_config.json. Replace the --directory path with the absolute path to your project folder.

{
  "mcpServers": {
    "demo": {
      "command": "uv",
      "args": ["--directory", "/ABSOLUTE/PATH/TO/demo", "run", "server.py"]
    }
  }
}

After saving, restart Claude Desktop and the demo server appears in the tools list. In Claude Code, register it with claude mcp add — for scopes and transports see Claude Code MCP setup, and for all four ways to connect see How to connect & use MCP.

4) Use and test

Ask Claude something like "use demo’s add tool to add 2 and 3," and Claude will ask to approve the tool, then call your server. If a tool does not show up or the connection fails, follow the symptom-by-symptom checklist in the troubleshooting guide.

Using it remotely (custom connector)

The example above is a local (stdio) server running on your machine, which suits Claude Desktop and Claude Code. To attach it in claude.ai on the web as a custom connector, deploy the server as a remote HTTP server and add its URL under Settings → Connectors. For an overview see How to connect (incl. custom connectors) and the official connector guide.

Building it in TypeScript

JavaScript/TypeScript has an official SDK too. Install it as below, and for the server code follow the TypeScript example in the official docs directly (method signatures can change between versions, so the source is the safe reference).

npm install @modelcontextprotocol/sdk zod@3
npm install -D @types/node typescript

Staying safe

Whether you built the server or someone else did, connecting it to Claude lets that tool reach your data and systems. When you expose it publicly or deploy it remotely, keep permissions narrow and add authentication. For trust and permission criteria see MCP connector security; for existing servers see picks by use case and where to find them.

Written/current as of June 2026. The code and config follow the official "Build an MCP server" docs; details may change between SDK versions, so check the official docs as you build. This is an unofficial guide.

Keep reading

Discuss this topic in the community

Be the first to post in 'Claude Coding'. This is where readers of this topic gather.