Step 1: Install the MCP Python SDK
pip3 install mcp
The mcp package provides the Python SDK for building servers.
Step 2: Write a minimal server
Create a file called server.py:
from mcp.server import Server
from mcp.types import Tool
server = Server("demo-server")
@server.call_tool()
def call_tool(name: str, arguments: dict):
if name == "greet":
return f"Hello, {arguments.get('name', 'World')}!"
return "Unknown tool"
if __name__ == "__main__":
server.run()
This creates a server with one tool called "greet" that accepts a name and returns a greeting.
Step 3: Register the tool
Update the server to declare the tool so Claude knows it exists:
from mcp.server import Server
from mcp.types import Tool, TextContent
server = Server("demo-server")
# Register the tool
server.tools = [
Tool(
name="greet",
description="Greet someone by name",
inputSchema={
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "The person's name"
}
},
"required": ["name"]
}
)
]
@server.call_tool()
def call_tool(name: str, arguments: dict):
if name == "greet":
return [TextContent(
type="text",
text=f"Hello, {arguments.get('name')}!"
)]
return [TextContent(type="text", text="Unknown tool")]
if __name__ == "__main__":
server.run()
Step 4: Run the server
python3 server.py
The server starts and listens via stdio. Leave it running in a terminal.
Step 5: Connect to Claude Desktop
Add this to your claude_desktop_config.json:
{
"mcpServers": {
"demo": {
"command": "python",
"args": ["/path/to/server.py"]
}
}
}
Replace /path/to/server.py with the full path to your script.
Step 6: Test it
- Restart Claude Desktop.
- Click the 🔨 hammer icon to confirm your server is running.
- In a conversation, try: "Use the greet tool to greet Alice".
- Claude should call your tool and return the greeting.
Quick summary
- Install the mcp Python SDK:
pip3 install mcp - Create a Server and define tools with @server.call_tool()
- Register tools so Claude knows their names and parameters
- Connect in Claude Desktop config and test via the 🔨 icon
- Next: deep dive into tool input schemas and error handling