xmcp 0.6.13 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/dist/cli.js +8 -8
  2. package/dist/index.js +2 -2
  3. package/dist/runtime/adapter-express.js +2 -2
  4. package/dist/runtime/adapter-fastify.js +2 -2
  5. package/dist/runtime/adapter-nestjs.js +7 -7
  6. package/dist/runtime/adapter-nextjs.js +11 -11
  7. package/dist/runtime/http.js +3 -3
  8. package/dist/runtime/stdio.js +8 -8
  9. package/package.json +10 -11
  10. package/src/auth/api-key.ts +0 -120
  11. package/src/auth/jwt.ts +0 -52
  12. package/src/cli/commands/create/__tests__/create.test.ts +0 -99
  13. package/src/cli/commands/create/index.ts +0 -74
  14. package/src/cli/commands/create/templates/index.ts +0 -4
  15. package/src/cli/commands/create/templates/prompt.ts +0 -30
  16. package/src/cli/commands/create/templates/resource.ts +0 -20
  17. package/src/cli/commands/create/templates/tool.ts +0 -34
  18. package/src/cli/commands/create/templates/widget.ts +0 -33
  19. package/src/cli/utils/naming.ts +0 -39
  20. package/src/cli.ts +0 -125
  21. package/src/client/headers.ts +0 -61
  22. package/src/client/index.ts +0 -180
  23. package/src/client/types.ts +0 -122
  24. package/src/client/utils.ts +0 -133
  25. package/src/cloudflare.ts +0 -6
  26. package/src/compiler/build-telemetry.ts +0 -88
  27. package/src/compiler/client/component-compiler.ts +0 -250
  28. package/src/compiler/client/transpile.ts +0 -21
  29. package/src/compiler/compiler-context.ts +0 -61
  30. package/src/compiler/config/__tests__/config.test.ts +0 -459
  31. package/src/compiler/config/index.ts +0 -62
  32. package/src/compiler/config/injection.ts +0 -210
  33. package/src/compiler/config/schemas/bundler.ts +0 -12
  34. package/src/compiler/config/schemas/experimental/index.ts +0 -22
  35. package/src/compiler/config/schemas/index.ts +0 -20
  36. package/src/compiler/config/schemas/paths.ts +0 -35
  37. package/src/compiler/config/schemas/template.ts +0 -80
  38. package/src/compiler/config/schemas/transport/http.ts +0 -116
  39. package/src/compiler/config/schemas/transport/stdio.ts +0 -31
  40. package/src/compiler/config/schemas/typescript.ts +0 -26
  41. package/src/compiler/config/utils.ts +0 -168
  42. package/src/compiler/generate-env-code.ts +0 -5
  43. package/src/compiler/generate-import-code.ts +0 -187
  44. package/src/compiler/generate-tools-code.ts +0 -174
  45. package/src/compiler/get-bundler-config/get-entries.ts +0 -44
  46. package/src/compiler/get-bundler-config/get-externals.ts +0 -114
  47. package/src/compiler/get-bundler-config/get-injected-variables.ts +0 -46
  48. package/src/compiler/get-bundler-config/index.ts +0 -288
  49. package/src/compiler/get-bundler-config/plugins/index.ts +0 -140
  50. package/src/compiler/get-bundler-config/plugins/types/express.ts +0 -3
  51. package/src/compiler/get-bundler-config/plugins/types/fastify.ts +0 -4
  52. package/src/compiler/get-bundler-config/plugins/types/index.ts +0 -5
  53. package/src/compiler/get-bundler-config/plugins/types/nest.ts +0 -65
  54. package/src/compiler/get-bundler-config/plugins/types/next.ts +0 -52
  55. package/src/compiler/get-bundler-config/resolve-tsconfig-paths.ts +0 -51
  56. package/src/compiler/index.ts +0 -484
  57. package/src/compiler/on-first-build.ts +0 -54
  58. package/src/compiler/parse-xmcp-config.ts +0 -200
  59. package/src/compiler/start-http-server.ts +0 -42
  60. package/src/compiler/utils/__tests__/config-detection.test.ts +0 -307
  61. package/src/compiler/utils/__tests__/path-utils.test.ts +0 -137
  62. package/src/compiler/utils/config-detection.ts +0 -34
  63. package/src/compiler/utils/path-utils.ts +0 -22
  64. package/src/compiler/watcher-recovery.ts +0 -72
  65. package/src/host-bridge.ts +0 -36
  66. package/src/index.ts +0 -94
  67. package/src/platforms/build-cloudflare-output.ts +0 -116
  68. package/src/platforms/build-vercel-output.ts +0 -131
  69. package/src/plugins/index.ts +0 -1
  70. package/src/plugins/x402/index.ts +0 -24
  71. package/src/runtime/adapters/express/index.ts +0 -75
  72. package/src/runtime/adapters/fastify/__tests__/fastify.test.ts +0 -115
  73. package/src/runtime/adapters/fastify/index.ts +0 -78
  74. package/src/runtime/adapters/nestjs/index.ts +0 -16
  75. package/src/runtime/adapters/nestjs/xmcp.controller.ts +0 -34
  76. package/src/runtime/adapters/nestjs/xmcp.guard.ts +0 -101
  77. package/src/runtime/adapters/nestjs/xmcp.oauth.controller.ts +0 -36
  78. package/src/runtime/adapters/nestjs/xmcp.oauth.module.ts +0 -21
  79. package/src/runtime/adapters/nestjs/xmcp.oauth.service.ts +0 -36
  80. package/src/runtime/adapters/nestjs/xmcp.service.ts +0 -96
  81. package/src/runtime/adapters/nestjs/xmcp.utils.ts +0 -11
  82. package/src/runtime/adapters/nextjs/auth.ts +0 -265
  83. package/src/runtime/adapters/nextjs/handler/error-handler.ts +0 -67
  84. package/src/runtime/adapters/nextjs/handler/node-to-web-adapter.ts +0 -143
  85. package/src/runtime/adapters/nextjs/handler/request-converter.ts +0 -74
  86. package/src/runtime/adapters/nextjs/handler/server-lifecycle.ts +0 -69
  87. package/src/runtime/adapters/nextjs/index.ts +0 -82
  88. package/src/runtime/contexts/client-info-context.ts +0 -16
  89. package/src/runtime/contexts/http-request-context.ts +0 -21
  90. package/src/runtime/contexts/http-transport-context.ts +0 -18
  91. package/src/runtime/headers.ts +0 -42
  92. package/src/runtime/middlewares/utils.ts +0 -72
  93. package/src/runtime/platforms/cloudflare/cors.ts +0 -44
  94. package/src/runtime/platforms/cloudflare/middlewares/api-key.ts +0 -102
  95. package/src/runtime/platforms/cloudflare/middlewares/jwt.ts +0 -127
  96. package/src/runtime/platforms/cloudflare/types.ts +0 -23
  97. package/src/runtime/platforms/cloudflare/worker.ts +0 -270
  98. package/src/runtime/templates/home.ts +0 -746
  99. package/src/runtime/transports/http/base-streamable-http.ts +0 -46
  100. package/src/runtime/transports/http/cors/headers.ts +0 -58
  101. package/src/runtime/transports/http/cors/index.ts +0 -34
  102. package/src/runtime/transports/http/index.ts +0 -78
  103. package/src/runtime/transports/http/stateless-streamable-http.ts +0 -311
  104. package/src/runtime/transports/http/web-stateless-http.ts +0 -288
  105. package/src/runtime/transports/stdio/index.ts +0 -109
  106. package/src/runtime/utils/__tests__/client-info.test.ts +0 -146
  107. package/src/runtime/utils/__tests__/tool-extra.test.ts +0 -239
  108. package/src/runtime/utils/client-info.ts +0 -114
  109. package/src/runtime/utils/elicitation.ts +0 -396
  110. package/src/runtime/utils/ext-apps-registry.ts +0 -151
  111. package/src/runtime/utils/mcp-app-protocol.ts +0 -16
  112. package/src/runtime/utils/mcp-app-types.ts +0 -113
  113. package/src/runtime/utils/mcp-host-bridge.ts +0 -473
  114. package/src/runtime/utils/path-to-tool-name.ts +0 -69
  115. package/src/runtime/utils/prompt-loader.ts +0 -151
  116. package/src/runtime/utils/prompts.ts +0 -69
  117. package/src/runtime/utils/react/generate-html.ts +0 -69
  118. package/src/runtime/utils/react/index.ts +0 -6
  119. package/src/runtime/utils/request-tool-names.ts +0 -48
  120. package/src/runtime/utils/resource-loader.ts +0 -151
  121. package/src/runtime/utils/resources.ts +0 -331
  122. package/src/runtime/utils/server.ts +0 -107
  123. package/src/runtime/utils/tool-loader.ts +0 -149
  124. package/src/runtime/utils/tools.ts +0 -183
  125. package/src/runtime/utils/transformers/prompt.ts +0 -120
  126. package/src/runtime/utils/transformers/resource.ts +0 -196
  127. package/src/runtime/utils/transformers/tool.ts +0 -400
  128. package/src/runtime/utils/ui/__tests__/split-meta.test.ts +0 -803
  129. package/src/runtime/utils/ui/flatten-meta.ts +0 -44
  130. package/src/runtime/utils/ui/split-meta.ts +0 -78
  131. package/src/runtime/utils/utils/resource-uri-composer.ts +0 -204
  132. package/src/runtime/utils/validators/index.ts +0 -138
  133. package/src/telemetry/ci-info.ts +0 -6
  134. package/src/telemetry/debug.ts +0 -8
  135. package/src/telemetry/events/definitions.ts +0 -52
  136. package/src/telemetry/events/detached-flush.ts +0 -83
  137. package/src/telemetry/events/post-payload.ts +0 -141
  138. package/src/telemetry/events/tracker.ts +0 -281
  139. package/src/telemetry/index.ts +0 -7
  140. package/src/telemetry/metadata.ts +0 -49
  141. package/src/telemetry/project-id.ts +0 -35
  142. package/src/telemetry/storage.ts +0 -218
  143. package/src/types/adapter.d.ts +0 -5
  144. package/src/types/client-info.ts +0 -20
  145. package/src/types/declarations.ts +0 -37
  146. package/src/types/injected.d.ts +0 -62
  147. package/src/types/middleware.ts +0 -19
  148. package/src/types/prompt.ts +0 -6
  149. package/src/types/resource.ts +0 -15
  150. package/src/types/tool.ts +0 -192
  151. package/src/types/ui-meta.ts +0 -42
  152. package/src/utils/cli-icons.ts +0 -5
  153. package/src/utils/constants.ts +0 -31
  154. package/src/utils/context.ts +0 -105
  155. package/src/utils/detect-package-manager.ts +0 -46
  156. package/src/utils/file-watcher.ts +0 -66
  157. package/src/utils/fs-utils.ts +0 -16
  158. package/src/utils/path-validation.ts +0 -66
  159. package/src/utils/port-utils.ts +0 -43
  160. package/src/utils/spawn-process.ts +0 -49
  161. package/src/utils/subscribable.ts +0 -62
@@ -1,288 +0,0 @@
1
- import { Transport } from "@modelcontextprotocol/sdk/shared/transport";
2
- import { MessageExtraInfo } from "@modelcontextprotocol/sdk/types";
3
- import { AuthInfo } from "@modelcontextprotocol/sdk/server/auth/types";
4
-
5
- export interface JsonRpcMessage {
6
- jsonrpc: string;
7
- method?: string;
8
- params?: any;
9
- id?: string | number | null;
10
- result?: any;
11
- error?: any;
12
- }
13
-
14
- /**
15
- * Web API-based stateless HTTP transport for Cloudflare Workers.
16
- * Uses only Web APIs (no Node.js dependencies).
17
- */
18
- export class WebStatelessHttpTransport implements Transport {
19
- private debug: boolean;
20
- private _started: boolean = false;
21
-
22
- // Promise-based response collection (replaces EventEmitter pattern)
23
- private _responseResolvers: Map<
24
- string,
25
- {
26
- requestIds: Set<string | number>;
27
- responses: JsonRpcMessage[];
28
- resolve: (response: Response) => void;
29
- }
30
- > = new Map();
31
- private _requestToCollectorMapping: Map<string | number, string> = new Map();
32
-
33
- // MCP SDK transport interface
34
- onmessage?: (message: JsonRpcMessage, extra?: MessageExtraInfo) => void;
35
- onerror?: (error: Error) => void;
36
- onclose?: () => void;
37
-
38
- constructor(debug: boolean = false) {
39
- this.debug = debug;
40
- }
41
-
42
- private log(message: string, ...args: any[]): void {
43
- if (this.debug) {
44
- console.log(`[WebStatelessHTTP] ${message}`, ...args);
45
- }
46
- }
47
-
48
- async start(): Promise<void> {
49
- if (this._started) {
50
- throw new Error("Transport already started");
51
- }
52
- this._started = true;
53
- }
54
-
55
- async close(): Promise<void> {
56
- // Resolve any pending requests with service unavailable
57
- this._responseResolvers.forEach((collector) => {
58
- collector.resolve(
59
- new Response(
60
- JSON.stringify({
61
- jsonrpc: "2.0",
62
- error: {
63
- code: -32000,
64
- message: "Service unavailable: Server shutting down",
65
- },
66
- id: null,
67
- }),
68
- {
69
- status: 503,
70
- headers: { "Content-Type": "application/json" },
71
- }
72
- )
73
- );
74
- });
75
- this._responseResolvers.clear();
76
- this._requestToCollectorMapping.clear();
77
- }
78
-
79
- async send(message: JsonRpcMessage): Promise<void> {
80
- const requestId = message.id;
81
-
82
- if (requestId === undefined || requestId === null) {
83
- // In stateless mode, we can't handle notifications without request IDs
84
- if (this.debug) {
85
- this.log("Dropping notification without request ID");
86
- }
87
- return;
88
- }
89
-
90
- const collectorId = this._requestToCollectorMapping.get(requestId);
91
- if (collectorId) {
92
- const collector = this._responseResolvers.get(collectorId);
93
- if (
94
- collector &&
95
- (message.result !== undefined || message.error !== undefined)
96
- ) {
97
- collector.responses.push(message);
98
- collector.requestIds.delete(requestId);
99
-
100
- // All responses collected, resolve the promise
101
- if (collector.requestIds.size === 0) {
102
- const responseBody =
103
- collector.responses.length === 1
104
- ? collector.responses[0]
105
- : collector.responses;
106
-
107
- collector.resolve(
108
- new Response(JSON.stringify(responseBody), {
109
- status: 200,
110
- headers: { "Content-Type": "application/json" },
111
- })
112
- );
113
-
114
- // Cleanup
115
- this._responseResolvers.delete(collectorId);
116
- for (const response of collector.responses) {
117
- if (response.id !== undefined && response.id !== null) {
118
- this._requestToCollectorMapping.delete(response.id);
119
- }
120
- }
121
- }
122
- }
123
- }
124
- }
125
-
126
- /**
127
- * Handle an incoming Web Request and return a Web Response.
128
- * This is the main entry point for Cloudflare Workers.
129
- */
130
- async handleRequest(
131
- request: Request,
132
- authInfo?: AuthInfo
133
- ): Promise<Response> {
134
- // Only support POST in stateless mode
135
- if (request.method !== "POST") {
136
- return new Response(
137
- JSON.stringify({
138
- jsonrpc: "2.0",
139
- error: {
140
- code: -32000,
141
- message: "Method not allowed.",
142
- },
143
- id: null,
144
- }),
145
- {
146
- status: 405,
147
- headers: { "Content-Type": "application/json" },
148
- }
149
- );
150
- }
151
-
152
- return this.handlePOST(request, authInfo);
153
- }
154
-
155
- private async handlePOST(
156
- request: Request,
157
- authInfo?: AuthInfo
158
- ): Promise<Response> {
159
- try {
160
- const acceptHeader = request.headers.get("accept");
161
- const acceptsJson = acceptHeader?.includes("application/json");
162
-
163
- if (!acceptsJson) {
164
- return new Response(
165
- JSON.stringify({
166
- jsonrpc: "2.0",
167
- error: {
168
- code: -32000,
169
- message: "Not Acceptable: Client must accept application/json",
170
- },
171
- id: null,
172
- }),
173
- {
174
- status: 406,
175
- headers: { "Content-Type": "application/json" },
176
- }
177
- );
178
- }
179
-
180
- const contentType = request.headers.get("content-type");
181
- if (!contentType || !contentType.includes("application/json")) {
182
- return new Response(
183
- JSON.stringify({
184
- jsonrpc: "2.0",
185
- error: {
186
- code: -32000,
187
- message:
188
- "Unsupported Media Type: Content-Type must be application/json",
189
- },
190
- id: null,
191
- }),
192
- {
193
- status: 415,
194
- headers: { "Content-Type": "application/json" },
195
- }
196
- );
197
- }
198
-
199
- const rawMessage = await request.json();
200
- const incomingMessages: JsonRpcMessage[] = Array.isArray(rawMessage)
201
- ? rawMessage
202
- : [rawMessage];
203
-
204
- const invalidResponses: JsonRpcMessage[] = [];
205
- const messages = incomingMessages.filter((msg) => {
206
- if (msg?.jsonrpc === "2.0") {
207
- return true;
208
- }
209
- invalidResponses.push({
210
- jsonrpc: "2.0",
211
- error: {
212
- code: -32600,
213
- message: "Invalid Request",
214
- },
215
- id: msg && "id" in msg ? (msg as any).id ?? null : null,
216
- } as JsonRpcMessage);
217
- return false;
218
- });
219
-
220
- const hasRequests = messages.some(
221
- (msg) => msg.method && msg.id !== undefined
222
- );
223
-
224
- if (!hasRequests) {
225
- if (invalidResponses.length > 0) {
226
- const payload =
227
- invalidResponses.length === 1
228
- ? invalidResponses[0]
229
- : invalidResponses;
230
- return new Response(JSON.stringify(payload), {
231
- status: 400,
232
- headers: { "Content-Type": "application/json" },
233
- });
234
- }
235
- return new Response(null, { status: 202 });
236
- }
237
-
238
- // Handle requests that expect responses
239
- const requestIds = messages
240
- .filter((msg) => msg.method && msg.id !== undefined)
241
- .map((msg) => msg.id!);
242
-
243
- if (requestIds.length === 0) {
244
- return new Response(null, { status: 202 });
245
- }
246
-
247
- // Create a promise that will resolve when all responses are collected
248
- const responsePromise = new Promise<Response>((resolve) => {
249
- const collectorId = crypto.randomUUID();
250
- this._responseResolvers.set(collectorId, {
251
- requestIds: new Set(requestIds),
252
- responses: invalidResponses,
253
- resolve,
254
- });
255
-
256
- for (const requestId of requestIds) {
257
- this._requestToCollectorMapping.set(requestId, collectorId);
258
- }
259
- });
260
-
261
- // Process messages through MCP SDK transport interface
262
- for (const message of messages) {
263
- if (this.onmessage) {
264
- this.onmessage(message, { authInfo });
265
- }
266
- }
267
-
268
- // Wait for all responses
269
- return responsePromise;
270
- } catch (error) {
271
- return new Response(
272
- JSON.stringify({
273
- jsonrpc: "2.0",
274
- error: {
275
- code: -32700,
276
- message: "Parse error",
277
- data: String(error),
278
- },
279
- id: null,
280
- }),
281
- {
282
- status: 400,
283
- headers: { "Content-Type": "application/json" },
284
- }
285
- );
286
- }
287
- }
288
- }
@@ -1,109 +0,0 @@
1
- import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
- import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
- import { createServer } from "../../utils/server";
4
- import dotenv from "dotenv";
5
- import {
6
- clientInfoContextProvider,
7
- setClientInfoContext,
8
- } from "@/runtime/contexts/client-info-context";
9
- import { mapImplementationToClientInfo } from "@/runtime/utils/client-info";
10
- dotenv.config();
11
-
12
- class StdioTransport {
13
- private mcpServer: McpServer;
14
- private transport: StdioServerTransport;
15
- private debug: boolean;
16
-
17
- constructor(mcpServer: McpServer, debug: boolean = false) {
18
- this.mcpServer = mcpServer;
19
- this.transport = new StdioServerTransport();
20
- this.debug = debug;
21
- }
22
-
23
- public start(): void {
24
- try {
25
- this.mcpServer.server.oninitialized = () => {
26
- const implementation = this.mcpServer.server.getClientVersion();
27
- const clientInfo = mapImplementationToClientInfo(implementation);
28
- setClientInfoContext({ clientInfo });
29
-
30
- if (this.debug && clientInfo) {
31
- console.log(
32
- `[STDIO] MCP client initialized: ${clientInfo.name}@${clientInfo.version}`
33
- );
34
- }
35
- };
36
-
37
- this.mcpServer.connect(this.transport);
38
- if (this.debug) {
39
- console.log("[STDIO] MCP Server running with STDIO transport");
40
- }
41
- this.setupShutdownHandlers();
42
- } catch (error) {
43
- if (this.debug) {
44
- console.error("[STDIO] Error starting STDIO transport:", error);
45
- }
46
- process.exit(1);
47
- }
48
- }
49
-
50
- private setupShutdownHandlers(): void {
51
- const shutdownHandler = () => {
52
- if (this.debug) {
53
- console.log("[STDIO] Shutting down STDIO transport");
54
- }
55
- process.exit(0);
56
- };
57
-
58
- process.on("SIGINT", shutdownHandler);
59
- process.on("SIGTERM", shutdownHandler);
60
- }
61
-
62
- public shutdown(): void {
63
- if (this.debug) {
64
- console.log("[STDIO] Shutting down STDIO transport");
65
- }
66
- process.exit(0);
67
- }
68
- }
69
-
70
- const debug = STDIO_CONFIG.debug || false;
71
- const silent = STDIO_CONFIG.silent || false;
72
-
73
- if (silent) {
74
- // Redirect all console methods to stderr so they don't interfere with
75
- // the MCP stdio protocol on stdout.
76
- const stderrConsole = new console.Console(process.stderr, process.stderr);
77
- const methods = [
78
- "log",
79
- "debug",
80
- "info",
81
- "warn",
82
- "error",
83
- "dir",
84
- "table",
85
- "trace",
86
- "assert",
87
- "time",
88
- "timeEnd",
89
- "timeLog",
90
- "count",
91
- "countReset",
92
- "group",
93
- "groupEnd",
94
- "groupCollapsed",
95
- "clear",
96
- ] as const;
97
- for (const method of methods) {
98
- (console as any)[method] = (stderrConsole as any)[method].bind(
99
- stderrConsole
100
- );
101
- }
102
- }
103
-
104
- createServer().then((mcpServer) => {
105
- const stdioTransport = new StdioTransport(mcpServer, debug);
106
- clientInfoContextProvider({ clientInfo: undefined }, () => {
107
- stdioTransport.start();
108
- });
109
- });
@@ -1,146 +0,0 @@
1
- import { test } from "node:test";
2
- import assert from "node:assert";
3
- import {
4
- extractClientInfoFromHeaders,
5
- extractClientInfoFromMessage,
6
- extractClientInfoFromMessages,
7
- mapImplementationToClientInfo,
8
- } from "../client-info";
9
-
10
- test("extractClientInfoFromMessage returns undefined for non-initialize methods", () => {
11
- const result = extractClientInfoFromMessage({
12
- jsonrpc: "2.0",
13
- method: "tools/call",
14
- params: {},
15
- });
16
-
17
- assert.strictEqual(result, undefined);
18
- });
19
-
20
- test("extractClientInfoFromMessage extracts required and optional fields", () => {
21
- const result = extractClientInfoFromMessage({
22
- jsonrpc: "2.0",
23
- method: "initialize",
24
- params: {
25
- clientInfo: {
26
- name: "cursor",
27
- version: "0.50.1",
28
- title: "Cursor",
29
- websiteUrl: "https://cursor.com",
30
- description: "AI code editor",
31
- },
32
- },
33
- });
34
-
35
- assert.deepStrictEqual(result, {
36
- name: "cursor",
37
- version: "0.50.1",
38
- title: "Cursor",
39
- websiteUrl: "https://cursor.com",
40
- description: "AI code editor",
41
- });
42
- });
43
-
44
- test("extractClientInfoFromMessage returns undefined for invalid clientInfo payload", () => {
45
- const result = extractClientInfoFromMessage({
46
- jsonrpc: "2.0",
47
- method: "initialize",
48
- params: {
49
- clientInfo: {
50
- name: "cursor",
51
- },
52
- },
53
- });
54
-
55
- assert.strictEqual(result, undefined);
56
- });
57
-
58
- test("extractClientInfoFromMessages supports batch requests", () => {
59
- const result = extractClientInfoFromMessages([
60
- {
61
- jsonrpc: "2.0",
62
- method: "ping",
63
- id: 1,
64
- },
65
- {
66
- jsonrpc: "2.0",
67
- method: "initialize",
68
- id: 2,
69
- params: {
70
- clientInfo: {
71
- name: "opencode",
72
- version: "1.2.3",
73
- },
74
- },
75
- },
76
- ]);
77
-
78
- assert.deepStrictEqual(result, {
79
- name: "opencode",
80
- version: "1.2.3",
81
- });
82
- });
83
-
84
- test("mapImplementationToClientInfo maps SDK implementation shape", () => {
85
- const result = mapImplementationToClientInfo({
86
- name: "claude-code",
87
- version: "2.1.0",
88
- title: "Claude Code",
89
- websiteUrl: "https://claude.ai",
90
- description: "CLI coding agent",
91
- });
92
-
93
- assert.deepStrictEqual(result, {
94
- name: "claude-code",
95
- version: "2.1.0",
96
- title: "Claude Code",
97
- websiteUrl: "https://claude.ai",
98
- description: "CLI coding agent",
99
- });
100
- });
101
-
102
- test("extractClientInfoFromHeaders extracts required and optional fields", () => {
103
- const result = extractClientInfoFromHeaders({
104
- "x-mcp-client-name": "cursor",
105
- "x-mcp-client-version": "0.50.1",
106
- "x-mcp-client-title": "Cursor",
107
- "x-mcp-client-website-url": "https://cursor.com",
108
- "x-mcp-client-description": "AI code editor",
109
- });
110
-
111
- assert.deepStrictEqual(result, {
112
- name: "cursor",
113
- version: "0.50.1",
114
- title: "Cursor",
115
- websiteUrl: "https://cursor.com",
116
- description: "AI code editor",
117
- });
118
- });
119
-
120
- test("extractClientInfoFromHeaders handles case-insensitive header names", () => {
121
- const result = extractClientInfoFromHeaders({
122
- "X-MCP-Client-Name": "claude-code",
123
- "X-MCP-Client-Version": "2.1.0",
124
- });
125
-
126
- assert.deepStrictEqual(result, {
127
- name: "claude-code",
128
- version: "2.1.0",
129
- });
130
- });
131
-
132
- test("extractClientInfoFromHeaders returns undefined without name and version", () => {
133
- assert.strictEqual(
134
- extractClientInfoFromHeaders({
135
- "x-mcp-client-name": "cursor",
136
- }),
137
- undefined
138
- );
139
-
140
- assert.strictEqual(
141
- extractClientInfoFromHeaders({
142
- "x-mcp-client-version": "0.50.1",
143
- }),
144
- undefined
145
- );
146
- });