Did you know you can create your own tools for Claude Desktop without consuming your token quota? I'll show you how to build a Model Context Protocol (MCP) server in 5 minutes.
What is MCP? 🤔
Model Context Protocol is an open standard that allows AIs to access external tools. Think of it as creating "plugins" for your favorite AI.
Key benefits:
- âś… Free: Doesn't consume AI tokens
- âś… Reusable: Works with multiple clients (Claude, Windsurf, etc.)
- âś… Extensible: Connect APIs, databases, or any Python code
Quick Setup 🛠️
# 1. Create project
mkdir my-mcp-server && cd my-mcp-server
python -m venv venv
# 2. Activate environment
# Windows: .\venv\Scripts\Activate.ps1
# macOS/Linux: source venv/bin/activate
# 3. Install dependencies
pip install mcp fastmcp
The Code: 2 Tools in 30 Lines 🎯
#!/usr/bin/env python3
from mcp.server.fastmcp import FastMCP
mcp = FastMCP()
@mcp.tool()
def calculator(a: int, b: int) -> str:
"""Adds two numbers."""
result = a + b
return f"OK {a} + {b} = {result}"
@mcp.tool()
def generate_greeting(name: str, language: str = "english") -> str:
"""Generates greetings in different languages."""
greetings = {
"english": f"Hello {name}, have a great day!",
"spanish": f"Hola {name}, que tengas un excelente dia!",
"french": f"Bonjour {name}, passez une excellente journee!"
}
return greetings.get(language.lower(), greetings["english"])
if __name__ == "__main__":
print("MCP Server started...")
mcp.run()
Connect with Claude Desktop 🤖
- Run the server:
python server.py
-
Configure Claude Desktop:
Edit
%APPDATA%\Claude\claude_desktop_config.json
:
{
"mcpServers": {
"MY-SERVER": {
"command": "C:\\path\\to\\your\\venv\\Scripts\\python.exe",
"args": ["C:\\path\\to\\your\\server.py"],
"cwd": "C:\\path\\to\\your\\project"
}
}
}
-
Test it!
-
"Add 15 and 27" → Uses
calculator
-
"Greet Ana in Spanish" → Uses
generate_greeting
-
"Add 15 and 27" → Uses
Key Concepts 📚
Tools vs Prompts
-
Tools (
@mcp.tool()
): Execute code, return data -
Prompts (
@mcp.prompt()
): Generate text templates
When to use each?
- Tool: Calculate, query APIs, process data
- Prompt: Generate emails, documents, templates
Real-World Use Cases 🎯
# Connect with external API
@mcp.tool()
async def get_weather(city: str) -> dict:
"""Gets current weather."""
# Your logic here
pass
# Query database
@mcp.tool()
def find_customer(id: int) -> dict:
"""Finds a customer in the database."""
# Your logic here
pass
Common Troubleshooting đź”§
UTF-8 Error: Avoid emojis in prints or configure encoding.
Won't connect: Verify absolute paths in configuration.
Tools don't appear: Restart Claude Desktop after changes.
What's Next? 🚀
With MCP you can:
- Connect your AI to any API
- Automate work-specific tasks
- Create reusable tools for your team
The future of AI is extensible. What tool will you create first?
Liked it? đź’– and tell me what MCP tools you're planning to build.
Full code: https://github.com/Marant7/mcp-python.git
Top comments (0)