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,239 +0,0 @@
1
- import { test } from "node:test";
2
- import assert from "node:assert";
3
- import {
4
- transformToolHandler,
5
- type UserToolResponse,
6
- } from "../transformers/tool";
7
- import { httpRequestContextProvider } from "../../contexts/http-request-context";
8
- import { clientInfoContextProvider } from "../../contexts/client-info-context";
9
-
10
- type MinimalExtra = {
11
- signal: AbortSignal;
12
- requestId: string;
13
- sendNotification: (notification: unknown) => Promise<void>;
14
- sendRequest: (request: unknown, resultSchema: unknown) => Promise<unknown>;
15
- };
16
-
17
- const createMinimalExtra = (requestId: string): MinimalExtra => ({
18
- signal: new AbortController().signal,
19
- requestId,
20
- sendNotification: async () => undefined,
21
- sendRequest: async () => ({}),
22
- });
23
-
24
- const invokeHandler = (
25
- handler: unknown,
26
- requestId: string
27
- ): Promise<UserToolResponse> => {
28
- const typedHandler = handler as (
29
- args: Record<string, never>,
30
- extra: MinimalExtra
31
- ) => Promise<UserToolResponse>;
32
-
33
- return typedHandler({}, createMinimalExtra(requestId));
34
- };
35
-
36
- test("transformToolHandler forwards clientInfo through tool extra arguments", async () => {
37
- const transformedHandler = transformToolHandler((args, extra) => {
38
- return {
39
- structuredContent: {
40
- ...args,
41
- clientInfoName: extra.clientInfo?.name,
42
- clientInfoVersion: extra.clientInfo?.version,
43
- },
44
- };
45
- });
46
-
47
- const result = await new Promise<UserToolResponse>((resolve, reject) => {
48
- httpRequestContextProvider(
49
- {
50
- id: "request-id",
51
- headers: {},
52
- clientInfo: {
53
- name: "cursor",
54
- version: "0.50.1",
55
- title: "Cursor",
56
- },
57
- },
58
- () => {
59
- invokeHandler(transformedHandler, "rpc-1").then(resolve).catch(reject);
60
- }
61
- );
62
- });
63
-
64
- assert.deepStrictEqual(result, {
65
- structuredContent: {
66
- clientInfoName: "cursor",
67
- clientInfoVersion: "0.50.1",
68
- },
69
- content: [
70
- {
71
- type: "text",
72
- text: '{"clientInfoName":"cursor","clientInfoVersion":"0.50.1"}',
73
- },
74
- ],
75
- });
76
- });
77
-
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 () => {
169
- const transformedHandler = transformToolHandler((_args, extra) => {
170
- return {
171
- structuredContent: {
172
- hasClientInfo: extra.clientInfo !== undefined,
173
- },
174
- };
175
- });
176
-
177
- const result = await new Promise<UserToolResponse>((resolve, reject) => {
178
- httpRequestContextProvider(
179
- {
180
- id: "request-id-2",
181
- headers: {},
182
- clientInfo: undefined,
183
- },
184
- () => {
185
- invokeHandler(transformedHandler, "rpc-2").then(resolve).catch(reject);
186
- }
187
- );
188
- });
189
-
190
- assert.deepStrictEqual(result, {
191
- structuredContent: {
192
- hasClientInfo: false,
193
- },
194
- content: [
195
- {
196
- type: "text",
197
- text: '{"hasClientInfo":false}',
198
- },
199
- ],
200
- });
201
- });
202
-
203
- test("transformToolHandler uses stdio clientInfo context as fallback", async () => {
204
- const transformedHandler = transformToolHandler((_args, extra) => {
205
- return {
206
- structuredContent: {
207
- clientInfoName: extra.clientInfo?.name,
208
- clientInfoVersion: extra.clientInfo?.version,
209
- },
210
- };
211
- });
212
-
213
- const result = await new Promise<UserToolResponse>((resolve, reject) => {
214
- clientInfoContextProvider(
215
- {
216
- clientInfo: {
217
- name: "opencode",
218
- version: "1.2.3",
219
- },
220
- },
221
- () => {
222
- invokeHandler(transformedHandler, "rpc-3").then(resolve).catch(reject);
223
- }
224
- );
225
- });
226
-
227
- assert.deepStrictEqual(result, {
228
- structuredContent: {
229
- clientInfoName: "opencode",
230
- clientInfoVersion: "1.2.3",
231
- },
232
- content: [
233
- {
234
- type: "text",
235
- text: '{"clientInfoName":"opencode","clientInfoVersion":"1.2.3"}',
236
- },
237
- ],
238
- });
239
- });
@@ -1,114 +0,0 @@
1
- import type { JsonRpcMessage } from "@/runtime/transports/http/base-streamable-http";
2
- import type { HttpHeaders } from "@/runtime/contexts/http-request-context";
3
- import type { McpClientInfo } from "@/types/client-info";
4
- import type { Implementation } from "@modelcontextprotocol/sdk/types";
5
-
6
- const isObject = (value: unknown): value is Record<string, unknown> => {
7
- return typeof value === "object" && value !== null && !Array.isArray(value);
8
- };
9
-
10
- const parseClientInfoCandidate = (
11
- candidate: unknown
12
- ): McpClientInfo | undefined => {
13
- if (!isObject(candidate)) {
14
- return undefined;
15
- }
16
-
17
- if (
18
- typeof candidate.name !== "string" ||
19
- typeof candidate.version !== "string"
20
- ) {
21
- return undefined;
22
- }
23
-
24
- const result: McpClientInfo = {
25
- name: candidate.name,
26
- version: candidate.version,
27
- };
28
-
29
- if (typeof candidate.title === "string") {
30
- result.title = candidate.title;
31
- }
32
-
33
- if (typeof candidate.websiteUrl === "string") {
34
- result.websiteUrl = candidate.websiteUrl;
35
- }
36
-
37
- if (typeof candidate.description === "string") {
38
- result.description = candidate.description;
39
- }
40
-
41
- return result;
42
- };
43
-
44
- export const mapImplementationToClientInfo = (
45
- implementation: Implementation | undefined
46
- ): McpClientInfo | undefined => {
47
- return parseClientInfoCandidate(implementation);
48
- };
49
-
50
- export const extractClientInfoFromMessage = (
51
- message: JsonRpcMessage | undefined
52
- ): McpClientInfo | undefined => {
53
- if (!message || message.method !== "initialize") {
54
- return undefined;
55
- }
56
-
57
- if (!isObject(message.params)) {
58
- return undefined;
59
- }
60
-
61
- return parseClientInfoCandidate(message.params.clientInfo);
62
- };
63
-
64
- export const extractClientInfoFromMessages = (
65
- payload: unknown
66
- ): McpClientInfo | undefined => {
67
- const messages = Array.isArray(payload)
68
- ? (payload as JsonRpcMessage[])
69
- : ([payload] as JsonRpcMessage[]);
70
-
71
- for (const message of messages) {
72
- const clientInfo = extractClientInfoFromMessage(message);
73
- if (clientInfo) {
74
- return clientInfo;
75
- }
76
- }
77
-
78
- return undefined;
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
- };