How to Build Your First MCP Server with Claude Desktop
- Jun 9
- 3 min read

MCP (Model Context Protocol) is the new standard that lets Claude directly connect to your local code — giving it the ability to run functions, call APIs, control your computer, and more. In this tutorial, you'll build your first MCP server from scratch using Python and connect it to Claude Desktop.
🎥 Prefer video? Watch the full walkthrough on YouTube → [Your First MCP Server — Codersarts]
What is MCP?
MCP is a protocol that acts as a bridge between Claude Desktop and your local Python code. Once connected, Claude can call functions you define — directly from the chat window — without you having to run anything manually each time.
Think of it like giving Claude a set of custom tools that live on your machine.
What You'll Build
By the end of this tutorial you'll have:
A working MCP server with two tools
Claude Desktop connected to your local server
A clear understanding of how input and output flow between Claude and your code
Prerequisites
Python 3.10+
Claude Desktop installed (download here)
Basic Python knowledge
Step 1 — Install the MCP Package
pip install mcp
Step 2 — Write Your Server
Create a file called server.py:
"""My First MCP Server"""
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("Hello World")
@mcp.tool()
def say_hello() -> str:
"""Say hello to the world."""
return "Hello, World!"
@mcp.tool()
def get_weather(city: str) -> str:
"""Get the weather for a city."""
return f"Weather in {city}: Sunny, 28°C"
if __name__ == "__main__":
mcp.run()
What each part does
FastMCP("Hello World") — creates your server. The string is just a label.
@mcp.tool() — registers the function as a tool Claude can call. Without this decorator, Claude has no idea the function exists.
Docstring — Claude reads this to decide when and how to use the tool. Always write a clear one-line description.
mcp.run() — starts the server. The if name == "__main__" guard ensures it only runs when called directly, not when imported.
Step 3 — Configure Claude Desktop
This is where most beginners get confused. You don't run server.py manually — Claude Desktop handles that for you via a config file.
Open Claude Desktop → Settings → Developer → Edit Config
This opens a file called claude_desktop_config.json. Add your server:
{
"mcpServers": {
"my-tools": {
"command": "python",
"args": ["/absolute/path/to/server.py"]
}
}
}
Understanding the config
Key | What it means |
"mcpServers" | Container for all your servers |
"my-tools" | A label for this server — you choose the name |
"command" | How to run the server (python) |
"args" | Full path to your server.py file |
⚠️ Use the absolute path to your file. Relative paths will not work.
Save the file and restart Claude Desktop. Your tools will appear in the tools panel automatically.
Step 4 — Test It in Claude
Open Claude Desktop and type:
"Say hello"
Claude will call say_hello and return: Hello, World!
Now try:
"What's the weather in Delhi?"
Claude maps Delhi to the city parameter and calls get_weather automatically.
How Claude Calls Your Tools
Here's the full flow:
You type a message in Claude
Claude reads all registered tool docstrings
It decides which tool matches your intent
It passes your input as function parameters
Your function runs locally on your machine
The return value is sent back to Claude
Claude summarises and displays the result
You never have to call the function yourself — Claude handles the entire invocation.
The 3 "Tools" — Cleared Up
The word tool appears in three different places. Here's what each one means:
Where | What it refers to |
"my-tools" in config JSON | The server label — just a name you give the connection |
Claude's tools panel (UI) | The list of registered functions Claude discovered |
@mcp.tool() in Python | The decorator that registers a function as callable by Claude |
What to Build Next
Once you have the basics working, you can extend your MCP server to:
Fetch live data from any website or REST API
Read and write files on your computer
Query a database
Automate browser actions
Build tools specific to your workflow or product
Go Deeper
This tutorial covers the essentials. If you want to go further:
🎓 Full MCP Course — Codersarts Labs
Take the complete project-based course covering tools with parameters, live API connections, file system control, and building a real production-ready MCP server end to end.
📖 Free Text Tutorial — codersarts.dev
Step-by-step written tutorial with all code snippets, config examples, and common error fixes.
Need Help With Your Project?
Building something with MCP — a portfolio project, SaaS product, AI integration, or internal tool? Our team at Codersarts can help you design, build, and ship it.
1-on-1 mentorship for learning MCP and AI development
Project assistance for portfolio and freelance work
Full development support for SaaS and production apps
Published by Codersarts — Helping developers build with AI.



Comments