xmcp 0.6.8 → 0.6.10
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.
- package/README.md +0 -32
- package/dist/cli.js +27 -24
- package/dist/compiler/config/index.d.ts +11 -11
- package/dist/compiler/config/schemas/experimental/index.d.ts +4 -4
- package/dist/compiler/config/schemas/transport/http.d.ts +13 -13
- package/dist/index.js +5 -5
- package/dist/runtime/adapter-express.js +16 -16
- package/dist/runtime/adapter-fastify.js +488 -0
- package/dist/runtime/adapter-nestjs.js +16 -16
- package/dist/runtime/adapter-nextjs.js +14 -14
- package/dist/runtime/http.js +24 -24
- package/dist/runtime/stdio.js +17 -17
- package/dist/runtime/utils/client-info.d.ts +8 -0
- package/dist/types/client-info.d.ts +1 -0
- package/package.json +4 -2
- package/src/compiler/config/__tests__/config.test.ts +56 -0
- package/src/compiler/config/schemas/experimental/index.ts +6 -1
- package/src/compiler/config/schemas/transport/http.ts +5 -0
- package/src/compiler/get-bundler-config/get-entries.ts +3 -0
- package/src/compiler/get-bundler-config/get-externals.ts +10 -0
- package/src/compiler/get-bundler-config/plugins/index.ts +8 -3
- package/src/compiler/get-bundler-config/plugins/types/fastify.ts +4 -0
- package/src/compiler/get-bundler-config/plugins/types/index.ts +1 -0
- package/src/runtime/adapters/fastify/__tests__/fastify.test.ts +115 -0
- package/src/runtime/adapters/fastify/index.ts +78 -0
- package/src/runtime/transports/http/cors/index.ts +4 -2
- package/src/runtime/transports/http/stateless-streamable-http.ts +11 -89
- package/src/runtime/utils/__tests__/client-info.test.ts +47 -0
- package/src/runtime/utils/__tests__/tool-extra.test.ts +91 -1
- package/src/runtime/utils/client-info.ts +36 -0
- package/src/runtime/utils/transformers/tool.ts +5 -1
- package/src/telemetry/events/definitions.ts +2 -0
- package/src/types/client-info.ts +8 -0
|
@@ -75,7 +75,97 @@ test("transformToolHandler forwards clientInfo through tool extra arguments", as
|
|
|
75
75
|
});
|
|
76
76
|
});
|
|
77
77
|
|
|
78
|
-
test("transformToolHandler
|
|
78
|
+
test("transformToolHandler prefers initialize clientInfo over request headers", async () => {
|
|
79
|
+
const transformedHandler = transformToolHandler((_args, extra) => {
|
|
80
|
+
return {
|
|
81
|
+
structuredContent: {
|
|
82
|
+
clientInfoName: extra.clientInfo?.name,
|
|
83
|
+
clientInfoVersion: extra.clientInfo?.version,
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const result = await new Promise<UserToolResponse>((resolve, reject) => {
|
|
89
|
+
httpRequestContextProvider(
|
|
90
|
+
{
|
|
91
|
+
id: "request-id-headers-precedence",
|
|
92
|
+
headers: {
|
|
93
|
+
"x-mcp-client-name": "header-client",
|
|
94
|
+
"x-mcp-client-version": "9.9.9",
|
|
95
|
+
},
|
|
96
|
+
clientInfo: {
|
|
97
|
+
name: "initialize-client",
|
|
98
|
+
version: "1.0.0",
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
() => {
|
|
102
|
+
invokeHandler(transformedHandler, "rpc-headers-precedence")
|
|
103
|
+
.then(resolve)
|
|
104
|
+
.catch(reject);
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
assert.deepStrictEqual(result, {
|
|
110
|
+
structuredContent: {
|
|
111
|
+
clientInfoName: "initialize-client",
|
|
112
|
+
clientInfoVersion: "1.0.0",
|
|
113
|
+
},
|
|
114
|
+
content: [
|
|
115
|
+
{
|
|
116
|
+
type: "text",
|
|
117
|
+
text: '{"clientInfoName":"initialize-client","clientInfoVersion":"1.0.0"}',
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test("transformToolHandler uses request headers as HTTP clientInfo fallback", async () => {
|
|
124
|
+
const transformedHandler = transformToolHandler((_args, extra) => {
|
|
125
|
+
return {
|
|
126
|
+
structuredContent: {
|
|
127
|
+
clientInfoName: extra.clientInfo?.name,
|
|
128
|
+
clientInfoVersion: extra.clientInfo?.version,
|
|
129
|
+
clientInfoTitle: extra.clientInfo?.title,
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const result = await new Promise<UserToolResponse>((resolve, reject) => {
|
|
135
|
+
httpRequestContextProvider(
|
|
136
|
+
{
|
|
137
|
+
id: "request-id-headers",
|
|
138
|
+
headers: {
|
|
139
|
+
"X-MCP-Client-Name": "cursor",
|
|
140
|
+
"X-MCP-Client-Version": "0.50.1",
|
|
141
|
+
"X-MCP-Client-Title": "Cursor",
|
|
142
|
+
},
|
|
143
|
+
clientInfo: undefined,
|
|
144
|
+
},
|
|
145
|
+
() => {
|
|
146
|
+
invokeHandler(transformedHandler, "rpc-headers")
|
|
147
|
+
.then(resolve)
|
|
148
|
+
.catch(reject);
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
assert.deepStrictEqual(result, {
|
|
154
|
+
structuredContent: {
|
|
155
|
+
clientInfoName: "cursor",
|
|
156
|
+
clientInfoVersion: "0.50.1",
|
|
157
|
+
clientInfoTitle: "Cursor",
|
|
158
|
+
},
|
|
159
|
+
content: [
|
|
160
|
+
{
|
|
161
|
+
type: "text",
|
|
162
|
+
text: '{"clientInfoName":"cursor","clientInfoVersion":"0.50.1","clientInfoTitle":"Cursor"}',
|
|
163
|
+
},
|
|
164
|
+
],
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test("transformToolHandler leaves clientInfo undefined when request has no client metadata", async () => {
|
|
79
169
|
const transformedHandler = transformToolHandler((_args, extra) => {
|
|
80
170
|
return {
|
|
81
171
|
structuredContent: {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { JsonRpcMessage } from "@/runtime/transports/http/base-streamable-http";
|
|
2
|
+
import type { HttpHeaders } from "@/runtime/contexts/http-request-context";
|
|
2
3
|
import type { McpClientInfo } from "@/types/client-info";
|
|
3
4
|
import type { Implementation } from "@modelcontextprotocol/sdk/types";
|
|
4
5
|
|
|
@@ -76,3 +77,38 @@ export const extractClientInfoFromMessages = (
|
|
|
76
77
|
|
|
77
78
|
return undefined;
|
|
78
79
|
};
|
|
80
|
+
|
|
81
|
+
const getHeaderValue = (
|
|
82
|
+
headers: HttpHeaders,
|
|
83
|
+
headerName: string
|
|
84
|
+
): string | undefined => {
|
|
85
|
+
const normalizedHeaderName = headerName.toLowerCase();
|
|
86
|
+
|
|
87
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
88
|
+
if (key.toLowerCase() !== normalizedHeaderName) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const headerValue = Array.isArray(value) ? value[0] : value;
|
|
93
|
+
if (typeof headerValue !== "string") {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const trimmedValue = headerValue.trim();
|
|
98
|
+
return trimmedValue.length > 0 ? trimmedValue : undefined;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return undefined;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export const extractClientInfoFromHeaders = (
|
|
105
|
+
headers: HttpHeaders
|
|
106
|
+
): McpClientInfo | undefined => {
|
|
107
|
+
return parseClientInfoCandidate({
|
|
108
|
+
name: getHeaderValue(headers, "x-mcp-client-name"),
|
|
109
|
+
version: getHeaderValue(headers, "x-mcp-client-version"),
|
|
110
|
+
title: getHeaderValue(headers, "x-mcp-client-title"),
|
|
111
|
+
websiteUrl: getHeaderValue(headers, "x-mcp-client-website-url"),
|
|
112
|
+
description: getHeaderValue(headers, "x-mcp-client-description"),
|
|
113
|
+
});
|
|
114
|
+
};
|
|
@@ -8,6 +8,7 @@ import { ZodRawShape } from "zod/v3";
|
|
|
8
8
|
import type { ToolExtraArguments } from "@/types/tool";
|
|
9
9
|
import { getHttpRequestContext } from "@/runtime/contexts/http-request-context";
|
|
10
10
|
import { getClientInfoContext } from "@/runtime/contexts/client-info-context";
|
|
11
|
+
import { extractClientInfoFromHeaders } from "@/runtime/utils/client-info";
|
|
11
12
|
import { elicitFromTool } from "../elicitation";
|
|
12
13
|
import { validateContent } from "../validators";
|
|
13
14
|
|
|
@@ -78,7 +79,10 @@ function createToolExtraArguments(
|
|
|
78
79
|
let clientInfo = undefined;
|
|
79
80
|
|
|
80
81
|
try {
|
|
81
|
-
|
|
82
|
+
const httpRequestContext = getHttpRequestContext();
|
|
83
|
+
clientInfo =
|
|
84
|
+
httpRequestContext.clientInfo ??
|
|
85
|
+
extractClientInfoFromHeaders(httpRequestContext.headers);
|
|
82
86
|
} catch {
|
|
83
87
|
// no HTTP request context available (for example, stdio transport)
|
|
84
88
|
}
|
package/src/types/client-info.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
export const CLIENT_INFO_HEADER_NAMES = [
|
|
2
|
+
"x-mcp-client-name",
|
|
3
|
+
"x-mcp-client-version",
|
|
4
|
+
"x-mcp-client-title",
|
|
5
|
+
"x-mcp-client-website-url",
|
|
6
|
+
"x-mcp-client-description",
|
|
7
|
+
] as const;
|
|
8
|
+
|
|
1
9
|
export interface McpClientInfo {
|
|
2
10
|
/** MCP client implementation name from initialize.params.clientInfo.name */
|
|
3
11
|
name: string;
|