Created
March 9, 2025 17:34
-
-
Save presmihaylov/3121f35757437ab14fae213ad99dc3a9 to your computer and use it in GitHub Desktop.
Weather MCP Server example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; | |
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; | |
import { z } from "zod"; | |
const server = new McpServer({ | |
name: "Weather server", | |
version: "1.0.0", | |
}); | |
server.tool( | |
"getWeather", | |
"Gets the weather in a city", | |
{ | |
city: z.string(), | |
}, | |
async ({ city }) => { | |
return { | |
content: [ | |
{ | |
type: "text", | |
text: "It's sunny in " + city + " today!", | |
}, | |
], | |
}; | |
}, | |
); | |
const transport = new StdioServerTransport(); | |
await server.connect(transport).catch(console.error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a single-file MCP server implementation following this tutorial
https://www.aihero.dev/mcp-server-from-a-single-typescript-file