From c38230b780c4a35e562ac858b62091300d30787e Mon Sep 17 00:00:00 2001 From: Konstantin Konstantinov Date: Tue, 30 Jun 2026 10:32:07 +0300 Subject: [PATCH] initial @modelcontextprotocol/server & @modelcontextprotocol/node 2.0.0-alpha.3 --- packages/mcp/package.json | 5 +- packages/mcp/src/index.ts | 30 ++++------ packages/mcp/src/lib/auth/auth-prompt.ts | 2 +- pnpm-lock.yaml | 74 ++++++++++++++++++------ pnpm-workspace.yaml | 2 + 5 files changed, 73 insertions(+), 40 deletions(-) diff --git a/packages/mcp/package.json b/packages/mcp/package.json index 1dfa279bb..8aeef39c8 100644 --- a/packages/mcp/package.json +++ b/packages/mcp/package.json @@ -45,14 +45,15 @@ }, "homepage": "https://github.com/upstash/context7#readme", "dependencies": { - "@modelcontextprotocol/sdk": "^1.29.0", "@types/express": "^5.0.4", "@upstash/redis": "^1.38.0", "commander": "^13.1.0", "express": "^5.1.0", "jose": "^6.1.3", "undici": "^6.26.0", - "zod": "^4.4.3" + "zod": "^4.4.3", + "@modelcontextprotocol/server": "2.0.0-alpha.3", + "@modelcontextprotocol/node": "2.0.0-alpha.3" }, "devDependencies": { "@types/node": "^25.0.3", diff --git a/packages/mcp/src/index.ts b/packages/mcp/src/index.ts index 6f56fa921..0127cfd23 100644 --- a/packages/mcp/src/index.ts +++ b/packages/mcp/src/index.ts @@ -1,21 +1,15 @@ #!/usr/bin/env node -import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; -import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; -import { - ListPromptsRequestSchema, - ListResourcesRequestSchema, - ListResourceTemplatesRequestSchema, -} from "@modelcontextprotocol/sdk/types.js"; -import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js"; +import { NodeStreamableHTTPServerTransport } from "@modelcontextprotocol/node"; +import { StdioServerTransport } from "@modelcontextprotocol/server/stdio"; +import { McpServer, isInitializeRequest } from "@modelcontextprotocol/server"; +import type { Transport } from "@modelcontextprotocol/server"; import { z } from "zod"; import { searchLibraries, fetchLibraryContext } from "./lib/api.js"; import type { ClientContext } from "./lib/types.js"; import { formatSearchResults, extractClientInfoFromUserAgent } from "./lib/utils.js"; import { isJWT, validateJWT } from "./lib/jwt.js"; import express from "express"; -import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js"; -import { isInitializeRequest } from "@modelcontextprotocol/sdk/types.js"; import { Command } from "commander"; import { AsyncLocalStorage } from "async_hooks"; import { randomUUID } from "node:crypto"; @@ -197,7 +191,7 @@ Response Format: For ambiguous queries, request clarification before proceeding with a best-guess match. IMPORTANT: Do not call this tool more than 3 times per question. If you cannot find what you need after 3 calls, use the best result you have.`, - inputSchema: { + inputSchema: z.object({ query: z .string() .describe( @@ -208,7 +202,7 @@ IMPORTANT: Do not call this tool more than 3 times per question. If you cannot f .describe( "Library name to search for and retrieve a Context7-compatible library ID. Use the official library name with proper punctuation — e.g., 'Next.js' instead of 'nextjs', 'Customer.io' instead of 'customerio', 'Three.js' instead of 'threejs'." ), - }, + }), annotations: { readOnlyHint: true, destructiveHint: false, @@ -256,7 +250,7 @@ IMPORTANT: Do not call this tool more than 3 times per question. If you cannot f You must call 'Resolve Context7 Library ID' tool first to obtain the exact Context7-compatible library ID required to use this tool, UNLESS the user explicitly provides a library ID in the format '/org/project' or '/org/project/version' in their query. Do not call this tool more than 3 times per question.`, - inputSchema: { + inputSchema: z.object({ libraryId: z .string() .describe( @@ -267,7 +261,7 @@ Do not call this tool more than 3 times per question.`, .describe( "The question or task you need help with. Be specific and include relevant details. Good: 'How to set up authentication with JWT in Express.js' or 'React useEffect cleanup function examples'. Bad: 'auth' or 'hooks'. The query is sent to the Context7 API for processing. Do not include any sensitive or confidential information such as API keys, passwords, credentials, personal data, or proprietary code in your query." ), - }, + }), annotations: { readOnlyHint: true, destructiveHint: false, @@ -291,11 +285,11 @@ Do not call this tool more than 3 times per question.`, ); server.server.registerCapabilities({ prompts: {}, resources: {} }); - server.server.setRequestHandler(ListPromptsRequestSchema, async () => ({ prompts: [] })); - server.server.setRequestHandler(ListResourcesRequestSchema, async () => ({ + server.server.setRequestHandler("prompts/list", async () => ({ prompts: [] })); + server.server.setRequestHandler("resources/list", async () => ({ resources: [], })); - server.server.setRequestHandler(ListResourceTemplatesRequestSchema, async () => ({ + server.server.setRequestHandler("resources/templates/list", async () => ({ resourceTemplates: [], })); @@ -522,7 +516,7 @@ async function main() { // buffering until the tool returns. This is required for long-running tools // because some MCP HTTP clients cap the underlying fetch at 60s waiting for // headers, even though the per-tool timeout is much higher. - const transport = new StreamableHTTPServerTransport({ + const transport = new NodeStreamableHTTPServerTransport({ sessionIdGenerator: undefined, enableJsonResponse: false, }); diff --git a/packages/mcp/src/lib/auth/auth-prompt.ts b/packages/mcp/src/lib/auth/auth-prompt.ts index 319c22524..f171d649c 100644 --- a/packages/mcp/src/lib/auth/auth-prompt.ts +++ b/packages/mcp/src/lib/auth/auth-prompt.ts @@ -1,4 +1,4 @@ -import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; +import type { McpServer } from "@modelcontextprotocol/server"; import type { ClientContext } from "../types.js"; function clientFlagForCli(ide: string | undefined): string { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bc119bb8d..3f2dc3ac1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -109,9 +109,12 @@ importers: packages/mcp: dependencies: - '@modelcontextprotocol/sdk': - specifier: ^1.29.0 - version: 1.29.0(zod@4.4.3) + '@modelcontextprotocol/node': + specifier: 2.0.0-alpha.3 + version: 2.0.0-alpha.3(@modelcontextprotocol/server@2.0.0-alpha.3)(hono@4.12.23) + '@modelcontextprotocol/server': + specifier: 2.0.0-alpha.3 + version: 2.0.0-alpha.3 '@types/express': specifier: ^5.0.4 version: 5.0.5 @@ -1048,6 +1051,16 @@ packages: '@mistralai/mistralai@2.2.1': resolution: {integrity: sha512-uKU8CZmL2RzYKmplsU01hii4p3pe4HqJefpWNRWXm1Tcm0Sm4xXfwSLIy4k7ZCPlbETCGcp69E7hZs+WOJ5itQ==} + '@modelcontextprotocol/node@2.0.0-alpha.3': + resolution: {integrity: sha512-3S/1lsMoN4dLifs9cZXq5eZ0/yygjQY5iyx8dv9NKEM9r3347vSB3S025tIukr+Kc5y4uaq1ZsYg/idEycFe/Q==} + engines: {node: '>=20'} + peerDependencies: + '@modelcontextprotocol/server': ^2.0.0-alpha.3 + hono: ^4.11.4 + peerDependenciesMeta: + hono: + optional: true + '@modelcontextprotocol/sdk@1.29.0': resolution: {integrity: sha512-zo37mZA9hJWpULgkRpowewez1y6ML5GsXJPY8FI0tBBCd77HEvza4jDqRKOXgHNn867PVGCyTdzqpz0izu5ZjQ==} engines: {node: '>=18'} @@ -1058,6 +1071,10 @@ packages: '@cfworker/json-schema': optional: true + '@modelcontextprotocol/server@2.0.0-alpha.3': + resolution: {integrity: sha512-PYdVDA6x3joCy/rw1mGdMSvqisPKlmt5QN/ILcT8R7efgvmhij14L87lJrWAm4pszaThzwpV49BmBBTZWtlY3A==} + engines: {node: '>=20'} + '@nodable/entities@2.1.0': resolution: {integrity: sha512-nyT7T3nbMyBI/lvr6L5TyWbFJAI9FTgVRakNoBqCD+PmID8DzFrrNdLLtHMwMszOtqZa8PAOV24ZqDnQrhQINA==} @@ -2144,10 +2161,6 @@ packages: resolution: {integrity: sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==} engines: {node: '>=0.10.0'} - iconv-lite@0.7.0: - resolution: {integrity: sha512-cf6L2Ds3h57VVmkZe+Pn+5APsT7FpqJtEhhieDCvrE2MK5Qk9MyffgQyuxQTm6BChfeZNtcOLHp9IcWRVcIcBQ==} - engines: {node: '>=0.10.0'} - iconv-lite@0.7.2: resolution: {integrity: sha512-im9DjEDQ55s9fL4EYzOAv0yMqmMBSZp6G0VvFyTMPKWxiSBHUj9NW/qqLmXUwXrrM7AvqSlTCfvqRb0cM8yYqw==} engines: {node: '>=0.10.0'} @@ -4067,6 +4080,13 @@ snapshots: - bufferutil - utf-8-validate + '@modelcontextprotocol/node@2.0.0-alpha.3(@modelcontextprotocol/server@2.0.0-alpha.3)(hono@4.12.23)': + dependencies: + '@hono/node-server': 1.19.14(hono@4.12.23) + '@modelcontextprotocol/server': 2.0.0-alpha.3 + optionalDependencies: + hono: 4.12.23 + '@modelcontextprotocol/sdk@1.29.0(zod@4.4.3)': dependencies: '@hono/node-server': 1.19.14(hono@4.12.23) @@ -4088,6 +4108,11 @@ snapshots: zod-to-json-schema: 3.25.2(zod@4.4.3) transitivePeerDependencies: - supports-color + optional: true + + '@modelcontextprotocol/server@2.0.0-alpha.3': + dependencies: + zod: 4.4.3 '@nodable/entities@2.1.0': {} @@ -4536,6 +4561,7 @@ snapshots: ajv-formats@3.0.1(ajv@8.17.1): optionalDependencies: ajv: 8.17.1 + optional: true ajv@6.15.0: dependencies: @@ -4550,6 +4576,7 @@ snapshots: fast-uri: 3.1.0 json-schema-traverse: 1.0.0 require-from-string: 2.0.2 + optional: true ansi-align@3.0.1: dependencies: @@ -4620,6 +4647,7 @@ snapshots: type-is: 2.0.1 transitivePeerDependencies: - supports-color + optional: true bowser@2.14.1: {} @@ -4739,6 +4767,7 @@ snapshots: dependencies: object-assign: 4.1.1 vary: 1.1.2 + optional: true cross-spawn@7.0.6: dependencies: @@ -4964,6 +4993,7 @@ snapshots: eventsource@3.0.7: dependencies: eventsource-parser: 3.0.6 + optional: true expect-type@1.2.2: {} @@ -4971,6 +5001,7 @@ snapshots: dependencies: express: 5.2.1 ip-address: 10.2.0 + optional: true express@5.1.0: dependencies: @@ -5026,7 +5057,7 @@ snapshots: once: 1.4.0 parseurl: 1.3.3 proxy-addr: 2.0.7 - qs: 6.14.0 + qs: 6.15.2 range-parser: 1.2.1 router: 2.2.0 send: 1.2.0 @@ -5036,6 +5067,7 @@ snapshots: vary: 1.1.2 transitivePeerDependencies: - supports-color + optional: true extend@3.0.2: {} @@ -5057,7 +5089,8 @@ snapshots: fast-levenshtein@2.0.6: {} - fast-uri@3.1.0: {} + fast-uri@3.1.0: + optional: true fast-xml-builder@1.2.0: dependencies: @@ -5284,10 +5317,6 @@ snapshots: dependencies: safer-buffer: 2.1.2 - iconv-lite@0.7.0: - dependencies: - safer-buffer: 2.1.2 - iconv-lite@0.7.2: dependencies: safer-buffer: 2.1.2 @@ -5305,7 +5334,8 @@ snapshots: inherits@2.0.4: {} - ip-address@10.2.0: {} + ip-address@10.2.0: + optional: true ipaddr.js@1.9.1: {} @@ -5371,9 +5401,11 @@ snapshots: json-schema-traverse@0.4.1: {} - json-schema-traverse@1.0.0: {} + json-schema-traverse@1.0.0: + optional: true - json-schema-typed@8.0.2: {} + json-schema-typed@8.0.2: + optional: true json-schema@0.4.0: {} @@ -5624,7 +5656,8 @@ snapshots: pirates@4.0.7: {} - pkce-challenge@5.0.0: {} + pkce-challenge@5.0.0: + optional: true pkg-types@1.3.1: dependencies: @@ -5692,6 +5725,7 @@ snapshots: qs@6.15.2: dependencies: side-channel: 1.1.0 + optional: true quansync@0.2.11: {} @@ -5703,7 +5737,7 @@ snapshots: dependencies: bytes: 3.1.2 http-errors: 2.0.1 - iconv-lite: 0.7.0 + iconv-lite: 0.7.2 unpipe: 1.0.0 read-yaml-file@1.1.0: @@ -5715,7 +5749,8 @@ snapshots: readdirp@4.1.2: {} - require-from-string@2.0.2: {} + require-from-string@2.0.2: + optional: true resolve-from@4.0.0: {} @@ -6255,5 +6290,6 @@ snapshots: zod-to-json-schema@3.25.2(zod@4.4.3): dependencies: zod: 4.4.3 + optional: true zod@4.4.3: {} diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 664ca3c47..b5c6a51a2 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -5,3 +5,5 @@ allowBuilds: esbuild: true minimumReleaseAge: 10080 +minimumReleaseAgeExclude: + - '@modelcontextprotocol/*'