Building Your First MCP Server
Use the Python MCP SDK to create a server that exposes resources, tools, and prompts, then connect it to Claude Desktop to see it working end to end.
Project Setup for an MCP Server
Building an MCP server in Python requires the mcp SDK and a Python environment. You'll create a server that Claude Desktop or any MCP client can connect to via stdio. Start by installing the package and creating your server file.
# Create a project directory
# mkdir my_mcp_server && cd my_mcp_server
# Create a virtual environment
# python -m venv venv && source venv/bin/activate
# Install the MCP SDK
# pip install mcp httpx
# Project structure:
# my_mcp_server/
# server.py <- Your MCP server
# requirements.txt
# README.mdCreating the Server Object
Import from the mcp package and create a Server instance with your server's name. The name is shown to clients in their MCP server list — pick something descriptive. The server object is the entry point for registering all your tools, resources, and prompts.
# server.py
from mcp.server import Server
from mcp.server.stdio import stdio_server
from mcp import types
import asyncio
import httpx
# Create the server — name is shown in Claude Desktop
app = Server('weather-server')
# --- Tool registrations go here ---
# Entry point
if __name__ == '__main__':
asyncio.run(stdio_server(app))All lessons in this course
- What Is MCP and Why It Matters
- Building Your First MCP Server
- Exposing Database Resources via MCP
- MCP Security and Authentication