Skip to main content
Glama

Example MCP SSE Server

by keepview
mcp-server.ts1.17 kB
import { McpServer, ResourceTemplate, } from "@modelcontextprotocol/sdk/server/mcp.js"; import { z } from "zod"; const mcpServer = new McpServer( { name: "ExampleMCPServer", version: "1.0.0", }, { capabilities: {}, } ); mcpServer.tool("add", { a: z.number(), b: z.number() }, async ({ a, b }) => { console.log("add:>>", { a, b }); return { content: [{ type: "text", text: String(a + b) }], }; }); mcpServer.tool("weather", { city: z.string() }, async ({ city }) => { const alerts = city === "上海" ? ["高温预警"] : []; return { content: [{ type: "text", text: JSON.stringify({ alerts }) }], }; }); mcpServer.resource( "document", new ResourceTemplate("document://{name}", { list: async () => { return { resources: [ { name: "document-getting-started", uri: "document://getting-started", }, ], }; }, }), async (uri, variables) => { return { contents: [ { uri: uri.href, text: "Getting Started", mimeType: "text/plain", }, ], }; } ); export { mcpServer };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/keepview/hono-mcp-sse-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server