Quickstart
Get started building your own server to use in Claude for Desktop and other clients.
In this tutorial, we'll build a simple MCP weather server and connect it to a host, Claude for Desktop. We'll start with a basic setup, and then progress to more complex use cases.
This is the same tutorial as the one here from the Model Context Protocol documentation. You can compare the two to see how Muppet simplifies the process of building and deploying MCPs.
What we'll be building
Many LLMs do not currently have the ability to fetch the forecast and severe weather alerts. Let's use MCP to solve that!
We'll build a server that exposes two tools: get-alerts
and get-forecast
. Then we'll connect the server to an MCP host (in this case, Claude for Desktop):
Core MCP Concepts
MCP servers can provide three main types of capabilities:
- Resources: File-like data that can be read by clients (like API responses or file contents)
- Tools: Functions that can be called by the LLM (with user approval)
- Prompts: Pre-written templates that help users accomplish specific tasks
This tutorial will primarily focus on tools.
Building our server
Let's get started with building our weather server! You can find the complete code for what we'll be building here.
-
Let's create and setup our project
# Initialize a new muppet project, here we will be using the Stdio Transport for simplicity pnpm create muppet@latest my-mcp -i -t stdio -r nodejs -p pnpm # You can use any validation lib that supports Standard Schema pnpm add zod
-
Importing packages
Add these to the top of your
src/index.ts
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; import { Muppet } from "muppet"; import z from "zod";
-
Helper functions
Next, let's add our helper functions for querying and formatting the data from the National Weather Service API
const NWS_API_BASE = "https://api.weather.gov"; const USER_AGENT = "weather-app/1.0"; // Helper function for making NWS API requests async function makeNWSRequest<T>(url: string): Promise<T | null> { const headers = { "User-Agent": USER_AGENT, Accept: "application/geo+json", }; try { const response = await fetch(url, { headers }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return (await response.json()) as T; } catch (error) { console.error("Error making NWS request:", error); return null; } } interface AlertFeature { properties: { event?: string; areaDesc?: string; severity?: string; status?: string; headline?: string; }; } // Format alert data function formatAlert(feature: AlertFeature): string { const props = feature.properties; return [ `Event: ${props.event || "Unknown"}`, `Area: ${props.areaDesc || "Unknown"}`, `Severity: ${props.severity || "Unknown"}`, `Status: ${props.status || "Unknown"}`, `Headline: ${props.headline || "No headline"}`, "---", ].join("\n"); } interface ForecastPeriod { name?: string; temperature?: number; temperatureUnit?: string; windSpeed?: string; windDirection?: string; shortForecast?: string; } interface AlertsResponse { features: AlertFeature[]; } interface PointsResponse { properties: { forecast?: string; }; } interface ForecastResponse { properties: { periods: ForecastPeriod[]; }; }
-
Implementing tool execution
Now let's implement the tool execution logic. This is where we define how our tools will work.
const mcp = new Muppet({ name: "weather", version: "1.0.0", }); // Define the get-alerts tool mcp.tool( { name: "get-alerts", description: "Get weather alerts for a state", inputSchema: z.object({ state: z .string() .length(2) .describe("Two-letter state code (e.g. CA, NY)"), }), }, async (c) => { const { state } = c.message.params.arguments; const stateCode = state.toUpperCase(); const alertsUrl = `${NWS_API_BASE}/alerts?area=${stateCode}`; const alertsData = await makeNWSRequest<AlertsResponse>(alertsUrl); if (!alertsData) { return { content: [ { type: "text", text: "Failed to retrieve alerts data", }, ], }; } const features = alertsData.features; if (features.length === 0) { return { content: [ { type: "text", text: `No active alerts for ${stateCode}`, }, ], }; } const formattedAlerts = features.map(formatAlert); const alertsText = `Active alerts for ${stateCode}:\n\n${formattedAlerts.join( "\n", )}`; return { content: [ { type: "text", text: alertsText, }, ], }; }, ); mcp.tool( { name: "get-forecast", description: "Get weather forecast for a location", inputSchema: z.object({ latitude: z .number() .min(-90) .max(90) .describe("Latitude of the location"), longitude: z .number() .min(-180) .max(180) .describe("Longitude of the location"), }), }, async (c) => { const { latitude, longitude } = c.message.params.arguments; // Get grid point data const pointsUrl = `${NWS_API_BASE}/points/${latitude.toFixed(4)},${longitude.toFixed( 4, )}`; const pointsData = await makeNWSRequest<PointsResponse>(pointsUrl); if (!pointsData) { return { content: [ { type: "text", text: `Failed to retrieve grid point data for coordinates: ${latitude}, ${longitude}. This location may not be supported by the NWS API (only US locations are supported).`, }, ], }; } const forecastUrl = pointsData.properties?.forecast; if (!forecastUrl) { return { content: [ { type: "text", text: "Failed to get forecast URL from grid point data", }, ], }; } // Get forecast data const forecastData = await makeNWSRequest<ForecastResponse>(forecastUrl); if (!forecastData) { return { content: [ { type: "text", text: "Failed to retrieve forecast data", }, ], }; } const periods = forecastData.properties?.periods || []; if (periods.length === 0) { return { content: [ { type: "text", text: "No forecast periods available", }, ], }; } // Format forecast periods const formattedForecast = periods.map((period: ForecastPeriod) => [ `${period.name || "Unknown"}:`, `Temperature: ${period.temperature || "Unknown"}°${ period.temperatureUnit || "F" }`, `Wind: ${period.windSpeed || "Unknown"} ${period.windDirection || ""}`, `${period.shortForecast || "No forecast available"}`, "---", ].join("\n"), ); const forecastText = `Forecast for ${latitude}, ${longitude}:\n\n${formattedForecast.join( "\n", )}`; return { content: [ { type: "text", text: forecastText, }, ], }; }, );
-
Transport
Finally, connect the transport
// Connect the mcp with the transport mcp.connect(new StdioServerTransport());
Now depending upon the client you can either build the server or run it directly in dev mode. For simplicity we will just build the server. The command for this will depend on the runtime you are using. For example, if you are using nodejs, you can follow these steps
{ "scripts": { "build": "esbuild --bundle --minify --platform=node --outfile=./build/index.js ./src/index.ts", }, "dependencies": { "esbuild": "^0.24.2" } }
Let's now test your server from an existing MCP host, Claude for Desktop.
Connection with Claude for Desktop
First, make sure you have Claude for Desktop installed. You can install the latest version here. If you already have Claude for Desktop, make sure it's updated to the latest version.
We'll need to configure Claude for Desktop for whichever MCP servers you want to use. To do this, open your Claude for Desktop App configuration at ~/Library/Application Support/Claude/claude_desktop_config.json
in a text editor. Make sure to create the file if it doesn't exist.
For example, if you have VS Code installed:
code ~/Library/Application\ Support/Claude/claude_desktop_config.json
code $env:AppData\Claude\claude_desktop_config.json
You'll then add your servers in the mcpServers
key. The MCP UI elements will only show up in Claude for Desktop if at least one server is properly configured.
In this case, we'll add our single weather server like so:
{
"mcpServers": {
"weather": {
"command": "node",
"args": [
"/ABSOLUTE/PATH/TO/PARENT/FOLDER/weather/build/index.js"
]
}
}
}
{
"mcpServers": {
"weather": {
"command": "node",
"args": [
"C:\\PATH\\TO\\PARENT\\FOLDER\\weather\\build\\index.js"
]
}
}
}
This tells Claude for Desktop:
- There's an MCP server named "weather"
- Launch it by running
node /ABSOLUTE/PATH/TO/PARENT/FOLDER/weather/build/index.js
Save the file, and restart Claude for Desktop.
Test with commands
For this you can follow the instructions here to connect your server to the client.