Quickstart
Let's create a simple MCP server with a basic tool. This guide will walk you through creating a weather information tool.
Prerequisites
Make sure you have mcp-framework
installed globally with npm:
npm i -g mcp-framework
Create a New Project
First, create a new MCP server project:
mcp create weather-mcp-server
cd weather-mcp-server
Add a Weather Tool
Use the CLI to create a new tool:
mcp add tool weather
This creates src/tools/WeatherTool.ts
Let's modify it to handle weather requests:
import { MCPTool } from "mcp-framework";
import { z } from "zod";
interface WeatherInput {
city: string;
}
class WeatherTool extends MCPTool<WeatherInput> {
name = "weather";
description = "Get weather information for a city";
schema = {
city: {
type: z.string(),
description: "City name to get weather for",
},
};
async execute({ city }: WeatherInput) {
// In a real scenario, this would call a weather API
// For now, we return this sample data
return {
city,
temperature: 22,
condition: "Sunny",
humidity: 45,
};
}
}
export default WeatherTool;
Build your project
# Build the project
npm run build
Choose a Transport
MCP Framework supports two types of transports:
- STDIO Transport (Default): Perfect for CLI tools and local integrations. This is what we'll use with Claude Desktop.
- SSE Transport: Ideal for web applications and distributed systems.
For this quickstart, we'll use the default STDIO transport. To learn more about transports, check out:
Use the Tool
You can test your tool using the Claude Desktop client. Add this to your Claude Desktop config:
MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%/Claude/claude_desktop_config.json
{
"mcpServers": {
"weather-mcp-server": {
"command": "node",
"args": ["/absolute/path/to/weather-mcp-server/dist/index.js"]
}
}
}
Now you can ask Claude to use your weather tool:
Could you check the weather in London using the weather tool?
What's Next?
The example above shows a basic tool implementation. In practice, you might want to:
- Add real API integration
- Include error handling
- Add more weather-related tools
- Create resources for caching
- Define prompts for common queries
- Consider using SSE transport for web integration
Check out our US Treasury Data Example for a more complete implementation.
Next Steps
- Learn more about Tools
- Learn about Resources
- Understand Prompts
- Explore Transports
- Set up Debugging