Skip to content

Instantly share code, notes, and snippets.

@presmihaylov
Created March 9, 2025 17:34
Show Gist options
  • Save presmihaylov/3121f35757437ab14fae213ad99dc3a9 to your computer and use it in GitHub Desktop.
Save presmihaylov/3121f35757437ab14fae213ad99dc3a9 to your computer and use it in GitHub Desktop.
Weather MCP Server example
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);
@presmihaylov
Copy link
Author

This is a single-file MCP server implementation following this tutorial
https://www.aihero.dev/mcp-server-from-a-single-typescript-file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment