xmcp 0.7.0 → 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 (155) hide show
  1. package/dist/cli.js +1 -1
  2. package/dist/index.js +1 -1
  3. package/package.json +2 -3
  4. package/src/auth/api-key.ts +0 -120
  5. package/src/auth/jwt.ts +0 -52
  6. package/src/cli/commands/create/__tests__/create.test.ts +0 -99
  7. package/src/cli/commands/create/index.ts +0 -74
  8. package/src/cli/commands/create/templates/index.ts +0 -4
  9. package/src/cli/commands/create/templates/prompt.ts +0 -30
  10. package/src/cli/commands/create/templates/resource.ts +0 -20
  11. package/src/cli/commands/create/templates/tool.ts +0 -34
  12. package/src/cli/commands/create/templates/widget.ts +0 -33
  13. package/src/cli/utils/naming.ts +0 -39
  14. package/src/cli.ts +0 -125
  15. package/src/client/headers.ts +0 -61
  16. package/src/client/index.ts +0 -180
  17. package/src/client/types.ts +0 -122
  18. package/src/client/utils.ts +0 -133
  19. package/src/cloudflare.ts +0 -6
  20. package/src/compiler/build-telemetry.ts +0 -88
  21. package/src/compiler/client/component-compiler.ts +0 -250
  22. package/src/compiler/client/transpile.ts +0 -21
  23. package/src/compiler/compiler-context.ts +0 -61
  24. package/src/compiler/config/__tests__/config.test.ts +0 -459
  25. package/src/compiler/config/index.ts +0 -62
  26. package/src/compiler/config/injection.ts +0 -210
  27. package/src/compiler/config/schemas/bundler.ts +0 -12
  28. package/src/compiler/config/schemas/experimental/index.ts +0 -22
  29. package/src/compiler/config/schemas/index.ts +0 -20
  30. package/src/compiler/config/schemas/paths.ts +0 -35
  31. package/src/compiler/config/schemas/template.ts +0 -80
  32. package/src/compiler/config/schemas/transport/http.ts +0 -116
  33. package/src/compiler/config/schemas/transport/stdio.ts +0 -31
  34. package/src/compiler/config/schemas/typescript.ts +0 -26
  35. package/src/compiler/config/utils.ts +0 -168
  36. package/src/compiler/generate-env-code.ts +0 -5
  37. package/src/compiler/generate-import-code.ts +0 -187
  38. package/src/compiler/generate-tools-code.ts +0 -174
  39. package/src/compiler/get-bundler-config/get-entries.ts +0 -44
  40. package/src/compiler/get-bundler-config/get-externals.ts +0 -114
  41. package/src/compiler/get-bundler-config/get-injected-variables.ts +0 -46
  42. package/src/compiler/get-bundler-config/index.ts +0 -288
  43. package/src/compiler/get-bundler-config/plugins/index.ts +0 -140
  44. package/src/compiler/get-bundler-config/plugins/types/express.ts +0 -3
  45. package/src/compiler/get-bundler-config/plugins/types/fastify.ts +0 -4
  46. package/src/compiler/get-bundler-config/plugins/types/index.ts +0 -5
  47. package/src/compiler/get-bundler-config/plugins/types/nest.ts +0 -65
  48. package/src/compiler/get-bundler-config/plugins/types/next.ts +0 -52
  49. package/src/compiler/get-bundler-config/resolve-tsconfig-paths.ts +0 -51
  50. package/src/compiler/index.ts +0 -484
  51. package/src/compiler/on-first-build.ts +0 -54
  52. package/src/compiler/parse-xmcp-config.ts +0 -200
  53. package/src/compiler/start-http-server.ts +0 -42
  54. package/src/compiler/utils/__tests__/config-detection.test.ts +0 -307
  55. package/src/compiler/utils/__tests__/path-utils.test.ts +0 -137
  56. package/src/compiler/utils/config-detection.ts +0 -34
  57. package/src/compiler/utils/path-utils.ts +0 -22
  58. package/src/compiler/watcher-recovery.ts +0 -72
  59. package/src/host-bridge.ts +0 -36
  60. package/src/index.ts +0 -94
  61. package/src/platforms/build-cloudflare-output.ts +0 -116
  62. package/src/platforms/build-vercel-output.ts +0 -131
  63. package/src/plugins/index.ts +0 -1
  64. package/src/plugins/x402/index.ts +0 -24
  65. package/src/runtime/adapters/express/index.ts +0 -75
  66. package/src/runtime/adapters/fastify/__tests__/fastify.test.ts +0 -115
  67. package/src/runtime/adapters/fastify/index.ts +0 -78
  68. package/src/runtime/adapters/nestjs/index.ts +0 -16
  69. package/src/runtime/adapters/nestjs/xmcp.controller.ts +0 -34
  70. package/src/runtime/adapters/nestjs/xmcp.guard.ts +0 -101
  71. package/src/runtime/adapters/nestjs/xmcp.oauth.controller.ts +0 -36
  72. package/src/runtime/adapters/nestjs/xmcp.oauth.module.ts +0 -21
  73. package/src/runtime/adapters/nestjs/xmcp.oauth.service.ts +0 -36
  74. package/src/runtime/adapters/nestjs/xmcp.service.ts +0 -96
  75. package/src/runtime/adapters/nestjs/xmcp.utils.ts +0 -11
  76. package/src/runtime/adapters/nextjs/auth.ts +0 -265
  77. package/src/runtime/adapters/nextjs/handler/error-handler.ts +0 -67
  78. package/src/runtime/adapters/nextjs/handler/node-to-web-adapter.ts +0 -143
  79. package/src/runtime/adapters/nextjs/handler/request-converter.ts +0 -74
  80. package/src/runtime/adapters/nextjs/handler/server-lifecycle.ts +0 -69
  81. package/src/runtime/adapters/nextjs/index.ts +0 -121
  82. package/src/runtime/contexts/client-info-context.ts +0 -16
  83. package/src/runtime/contexts/http-request-context.ts +0 -21
  84. package/src/runtime/contexts/http-transport-context.ts +0 -18
  85. package/src/runtime/headers.ts +0 -42
  86. package/src/runtime/middlewares/utils.ts +0 -72
  87. package/src/runtime/platforms/cloudflare/cors.ts +0 -44
  88. package/src/runtime/platforms/cloudflare/middlewares/api-key.ts +0 -102
  89. package/src/runtime/platforms/cloudflare/middlewares/jwt.ts +0 -127
  90. package/src/runtime/platforms/cloudflare/types.ts +0 -23
  91. package/src/runtime/platforms/cloudflare/worker.ts +0 -270
  92. package/src/runtime/templates/home.ts +0 -746
  93. package/src/runtime/transports/http/base-streamable-http.ts +0 -46
  94. package/src/runtime/transports/http/cors/headers.ts +0 -58
  95. package/src/runtime/transports/http/cors/index.ts +0 -34
  96. package/src/runtime/transports/http/index.ts +0 -78
  97. package/src/runtime/transports/http/stateless-streamable-http.ts +0 -353
  98. package/src/runtime/transports/http/web-stateless-http.ts +0 -288
  99. package/src/runtime/transports/stdio/index.ts +0 -109
  100. package/src/runtime/utils/__tests__/client-info.test.ts +0 -146
  101. package/src/runtime/utils/__tests__/tool-extra.test.ts +0 -239
  102. package/src/runtime/utils/client-info.ts +0 -114
  103. package/src/runtime/utils/elicitation.ts +0 -396
  104. package/src/runtime/utils/ext-apps-registry.ts +0 -151
  105. package/src/runtime/utils/mcp-app-protocol.ts +0 -16
  106. package/src/runtime/utils/mcp-app-types.ts +0 -113
  107. package/src/runtime/utils/mcp-host-bridge.ts +0 -473
  108. package/src/runtime/utils/path-to-tool-name.ts +0 -69
  109. package/src/runtime/utils/prompt-loader.ts +0 -151
  110. package/src/runtime/utils/prompts.ts +0 -69
  111. package/src/runtime/utils/react/generate-html.ts +0 -69
  112. package/src/runtime/utils/react/index.ts +0 -6
  113. package/src/runtime/utils/request-tool-names.ts +0 -48
  114. package/src/runtime/utils/resource-loader.ts +0 -151
  115. package/src/runtime/utils/resources.ts +0 -331
  116. package/src/runtime/utils/server.ts +0 -107
  117. package/src/runtime/utils/tool-loader.ts +0 -149
  118. package/src/runtime/utils/tools.ts +0 -183
  119. package/src/runtime/utils/transformers/prompt.ts +0 -120
  120. package/src/runtime/utils/transformers/resource.ts +0 -196
  121. package/src/runtime/utils/transformers/tool.ts +0 -400
  122. package/src/runtime/utils/ui/__tests__/split-meta.test.ts +0 -803
  123. package/src/runtime/utils/ui/flatten-meta.ts +0 -44
  124. package/src/runtime/utils/ui/split-meta.ts +0 -78
  125. package/src/runtime/utils/utils/resource-uri-composer.ts +0 -204
  126. package/src/runtime/utils/validators/index.ts +0 -138
  127. package/src/telemetry/ci-info.ts +0 -6
  128. package/src/telemetry/debug.ts +0 -8
  129. package/src/telemetry/events/definitions.ts +0 -52
  130. package/src/telemetry/events/detached-flush.ts +0 -83
  131. package/src/telemetry/events/post-payload.ts +0 -141
  132. package/src/telemetry/events/tracker.ts +0 -281
  133. package/src/telemetry/index.ts +0 -7
  134. package/src/telemetry/metadata.ts +0 -49
  135. package/src/telemetry/project-id.ts +0 -35
  136. package/src/telemetry/storage.ts +0 -218
  137. package/src/types/adapter.d.ts +0 -5
  138. package/src/types/client-info.ts +0 -20
  139. package/src/types/declarations.ts +0 -37
  140. package/src/types/injected.d.ts +0 -62
  141. package/src/types/middleware.ts +0 -19
  142. package/src/types/prompt.ts +0 -6
  143. package/src/types/resource.ts +0 -15
  144. package/src/types/tool.ts +0 -192
  145. package/src/types/ui-meta.ts +0 -42
  146. package/src/utils/cli-icons.ts +0 -5
  147. package/src/utils/constants.ts +0 -31
  148. package/src/utils/context.ts +0 -105
  149. package/src/utils/detect-package-manager.ts +0 -46
  150. package/src/utils/file-watcher.ts +0 -66
  151. package/src/utils/fs-utils.ts +0 -16
  152. package/src/utils/path-validation.ts +0 -66
  153. package/src/utils/port-utils.ts +0 -43
  154. package/src/utils/spawn-process.ts +0 -49
  155. 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
- };