refactor: finish MCP SDK v2 migration

This commit is contained in:
Andrew Khadder 2026-07-14 17:07:30 -07:00
commit f94cb38b0b
No known key found for this signature in database
4 changed files with 684 additions and 540 deletions

View file

@ -4,10 +4,10 @@
* Or: node dist/index.js [--stdio]
*/
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { createMcpExpressApp } from "@modelcontextprotocol/sdk/server/express.js";
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
import { createMcpExpressApp } from "@modelcontextprotocol/express";
import { NodeStreamableHTTPServerTransport } from "@modelcontextprotocol/node";
import type { McpServer } from "@modelcontextprotocol/server";
import { StdioServerTransport } from "@modelcontextprotocol/server/stdio";
import cors from "cors";
import type { Request, Response } from "express";
import { createServer } from "./server.js";
@ -27,7 +27,7 @@ export async function startStreamableHTTPServer(
app.all("/mcp", async (req: Request, res: Response) => {
const server = createServer();
const transport = new StreamableHTTPServerTransport({
const transport = new NodeStreamableHTTPServerTransport({
sessionIdGenerator: undefined,
});

View file

@ -26,10 +26,11 @@
"serve": "bun --watch main.ts"
},
"dependencies": {
"@modelcontextprotocol/client": "2.0.0-beta.4",
"@modelcontextprotocol/ext-apps": "^1.7.0",
"@modelcontextprotocol/express": "2.0.0-beta.4",
"@modelcontextprotocol/node": "2.0.0-beta.4",
"@modelcontextprotocol/sdk": "^1.29.0",
"@modelcontextprotocol/server": "2.0.0-beta.4",
"cors": "^2.8.5",
"express": "^5.1.0",
"zod": "^4.1.13"

View file

@ -5,11 +5,11 @@
* - geocode: Search for places using OpenStreetMap Nominatim
* - show-map: Display an interactive 3D globe at a given location
*/
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import type {
CallToolResult,
ReadResourceResult,
} from "@modelcontextprotocol/sdk/types.js";
import {
McpServer,
type CallToolResult,
type ReadResourceResult,
} from "@modelcontextprotocol/server";
import fs from "node:fs/promises";
import path from "node:path";
import { z } from "zod";
@ -148,7 +148,7 @@ export function createServer(): McpServer {
title: "Show Map",
description:
"Display an interactive world map zoomed to a specific bounding box. Use the GeoCode tool to find the bounding box of a location. The widget is interactive and exposes tools for navigation (fly to locations) and querying the current view.",
inputSchema: {
inputSchema: z.object({
west: z
.number()
.optional()
@ -173,7 +173,7 @@ export function createServer(): McpServer {
.string()
.optional()
.describe("Optional label to display on the map"),
},
}),
_meta: { ui: { resourceUri } },
},
async ({ west, south, east, north, label }): Promise<CallToolResult> => ({
@ -196,13 +196,13 @@ export function createServer(): McpServer {
title: "Geocode",
description:
"Search for places using OpenStreetMap. Returns coordinates and bounding boxes for up to 5 matches.",
inputSchema: {
inputSchema: z.object({
query: z
.string()
.describe(
"Place name or address to search for (e.g., 'Paris', 'Golden Gate Bridge', '1600 Pennsylvania Ave')",
),
},
}),
},
async ({ query }): Promise<CallToolResult> => {
try {

View file

@ -6,7 +6,7 @@
* a navigate-to tool for the host to control navigation.
*/
import { App } from "@modelcontextprotocol/ext-apps";
import type { ContentBlock } from "@modelcontextprotocol/sdk/spec.types.js";
import type { ContentBlock } from "@modelcontextprotocol/client";
import { z } from "zod";
// TypeScript declaration for Cesium loaded from CDN