Understanding MCP
Setting Up Your MCP Development Environment
5 min read
Let's set up everything you need to build and test MCP servers.
Prerequisites
Before starting, ensure you have:
- Python 3.10+ or Node.js 18+
- Claude Desktop (for testing)
- A code editor (VS Code recommended)
Installing the MCP SDK
Python SDK
# Create a virtual environment
python -m venv mcp-env
source mcp-env/bin/activate # On Windows: mcp-env\Scripts\activate
# Install the MCP SDK
pip install mcp
TypeScript SDK
# Create a new project
mkdir my-mcp-server && cd my-mcp-server
npm init -y
# Install the MCP SDK
npm install @modelcontextprotocol/sdk
Your First MCP Server (Python)
Create a file called server.py:
from mcp.server import Server
from mcp.server.stdio import stdio_server
from mcp.types import Tool, TextContent
# Create server instance
server = Server(name="hello-mcp")
# Define a simple tool
@server.list_tools()
async def list_tools():
return [
Tool(
name="greet",
description="Greet someone by name",
inputSchema={
"type": "object",
"properties": {
"name": {"type": "string", "description": "Name to greet"}
},
"required": ["name"]
}
)
]
@server.call_tool()
async def call_tool(name: str, arguments: dict):
if name == "greet":
return [TextContent(type="text", text=f"Hello, {arguments['name']}!")]
raise ValueError(f"Unknown tool: {name}")
# Run the server
async def main():
async with stdio_server() as (read, write):
await server.run(read, write)
if __name__ == "__main__":
import asyncio
asyncio.run(main())
Configuring Claude Desktop
Add your server to Claude Desktop's config file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"hello-mcp": {
"command": "python",
"args": ["/path/to/server.py"]
}
}
}
Testing Your Server
- Restart Claude Desktop
- Open a new conversation
- Ask Claude: "Use the greet tool to say hello to Alice"
- Claude will invoke your MCP server!
Common Setup Issues
| Issue | Solution |
|---|---|
| Server not appearing | Check config path, restart Claude |
| Python not found | Use full path: /usr/bin/python3 |
| Permission denied | Check file permissions |
Next, let's dive into building real MCP servers with tools and resources. :::