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,270 +0,0 @@
1
- import { createServer } from "@/runtime/utils/server";
2
- import { WebStatelessHttpTransport } from "@/runtime/transports/http/web-stateless-http";
3
- import { httpRequestContextProvider } from "@/runtime/contexts/http-request-context";
4
- import { extractClientInfoFromMessages } from "@/runtime/utils/client-info";
5
- import homeTemplate from "../../templates/home";
6
-
7
- import { addCorsHeaders, handleCorsPreflightRequest } from "./cors";
8
- import type { Env, ExecutionContext } from "./types";
9
- import type { WebMiddleware, WebMiddlewareContext } from "@/types/middleware";
10
- import type { AuthInfo } from "@modelcontextprotocol/sdk/server/auth/types";
11
-
12
- const httpConfig = HTTP_CONFIG as {
13
- port: number;
14
- host: string;
15
- bodySizeLimit: number;
16
- endpoint: string;
17
- debug: boolean;
18
- };
19
-
20
- const templateConfig = TEMPLATE_CONFIG as {
21
- name?: string;
22
- description?: string;
23
- homePage?: string;
24
- };
25
-
26
- const middleware = INJECTED_MIDDLEWARE as
27
- | (() => Promise<{ default?: WebMiddleware | WebMiddleware[] }>)
28
- | undefined;
29
-
30
- let resolvedMiddlewarePromise: Promise<WebMiddleware[]> | null = null;
31
-
32
- async function resolveWebMiddleware(): Promise<WebMiddleware[]> {
33
- if (!middleware) {
34
- return [];
35
- }
36
-
37
- if (!resolvedMiddlewarePromise) {
38
- resolvedMiddlewarePromise = (async () => {
39
- try {
40
- const module = await middleware();
41
- return normalizeWebMiddleware(module?.default);
42
- } catch (error) {
43
- console.error("[Cloudflare-MCP] Failed to load middleware:", error);
44
- return [];
45
- }
46
- })();
47
- }
48
-
49
- return resolvedMiddlewarePromise;
50
- }
51
-
52
- function normalizeWebMiddleware(defaultExport: unknown): WebMiddleware[] {
53
- if (Array.isArray(defaultExport)) {
54
- return defaultExport.filter(isWebMiddleware);
55
- }
56
-
57
- if (isWebMiddleware(defaultExport)) {
58
- return [defaultExport];
59
- }
60
-
61
- if (
62
- defaultExport &&
63
- typeof defaultExport === "object" &&
64
- "middleware" in defaultExport &&
65
- typeof (defaultExport as { middleware?: unknown }).middleware === "function"
66
- ) {
67
- return [(defaultExport as { middleware: WebMiddleware }).middleware];
68
- }
69
-
70
- return [];
71
- }
72
-
73
- function isWebMiddleware(value: unknown): value is WebMiddleware {
74
- return typeof value === "function";
75
- }
76
-
77
- async function runWebMiddleware(
78
- request: Request
79
- ): Promise<{ response?: Response; authInfo?: AuthInfo }> {
80
- const webMiddleware = await resolveWebMiddleware();
81
-
82
- if (webMiddleware.length === 0) {
83
- return {};
84
- }
85
-
86
- const context: WebMiddlewareContext = {
87
- auth: undefined,
88
- setAuth: (auth) => {
89
- context.auth = auth;
90
- },
91
- };
92
-
93
- for (const handler of webMiddleware) {
94
- const result = await handler(request, context);
95
- if (result instanceof Response) {
96
- return { response: result, authInfo: context.auth };
97
- }
98
- }
99
-
100
- return { authInfo: context.auth };
101
- }
102
-
103
- /**
104
- * Log a message if debug mode is enabled
105
- */
106
- function log(message: string, ...args: unknown[]): void {
107
- if (httpConfig.debug) {
108
- console.log(`[Cloudflare-MCP] ${message}`, ...args);
109
- }
110
- }
111
-
112
- /**
113
- * Handle MCP requests
114
- */
115
- async function handleMcpRequest(
116
- request: Request,
117
- requestOrigin: string | null,
118
- ctx: ExecutionContext,
119
- authInfo?: AuthInfo
120
- ): Promise<Response> {
121
- const requestId = crypto.randomUUID();
122
- const requestPayload = await request
123
- .clone()
124
- .json()
125
- .catch(() => undefined);
126
- const clientInfo = extractClientInfoFromMessages(requestPayload);
127
-
128
- // Use the http request context provider to maintain request isolation
129
- return new Promise<Response>((resolve) => {
130
- // Convert Web Request headers to a format compatible with httpRequestContext
131
- const headers: Record<string, string | string[] | undefined> = {};
132
- request.headers.forEach((value, key) => {
133
- headers[key] = value;
134
- });
135
-
136
- httpRequestContextProvider(
137
- { id: requestId, headers, clientInfo },
138
- async () => {
139
- let server: Awaited<ReturnType<typeof createServer>> | null = null;
140
- let transport: WebStatelessHttpTransport | null = null;
141
-
142
- try {
143
- server = await createServer();
144
- transport = new WebStatelessHttpTransport(httpConfig.debug);
145
-
146
- await server.connect(transport);
147
- const response = await transport.handleRequest(request, authInfo);
148
-
149
- resolve(addCorsHeaders(response, requestOrigin));
150
- } catch (error) {
151
- console.error("[Cloudflare-MCP] Error handling MCP request:", error);
152
- const errorResponse = new Response(
153
- JSON.stringify({
154
- jsonrpc: "2.0",
155
- error: {
156
- code: -32603,
157
- message: "Internal server error",
158
- },
159
- id: null,
160
- }),
161
- {
162
- status: 500,
163
- headers: { "Content-Type": "application/json" },
164
- }
165
- );
166
- resolve(addCorsHeaders(errorResponse, requestOrigin));
167
- } finally {
168
- if (server && transport) {
169
- ctx.waitUntil(
170
- Promise.allSettled([transport.close(), server.close()])
171
- );
172
- }
173
- }
174
- }
175
- );
176
- });
177
- }
178
-
179
- /**
180
- * Cloudflare Workers fetch handler
181
- */
182
- export default {
183
- async fetch(
184
- request: Request,
185
- env: Env,
186
- _ctx: ExecutionContext
187
- ): Promise<Response> {
188
- const url = new URL(request.url);
189
- const pathname = url.pathname;
190
- const requestOrigin = request.headers.get("origin");
191
-
192
- log(`${request.method} ${pathname}`);
193
-
194
- // Handle CORS preflight
195
- if (request.method === "OPTIONS") {
196
- return handleCorsPreflightRequest(requestOrigin);
197
- }
198
-
199
- // Normalize the MCP endpoint path
200
- const mcpEndpoint = httpConfig.endpoint?.startsWith("/")
201
- ? httpConfig.endpoint
202
- : `/${httpConfig.endpoint || "mcp"}`;
203
-
204
- // Health check endpoint (no auth required)
205
- if (pathname === "/health") {
206
- const response = new Response(
207
- JSON.stringify({
208
- status: "ok",
209
- transport: "cloudflare-workers",
210
- mode: "stateless",
211
- auth: "none",
212
- }),
213
- {
214
- status: 200,
215
- headers: { "Content-Type": "application/json" },
216
- }
217
- );
218
- return addCorsHeaders(response, requestOrigin);
219
- }
220
-
221
- // Home page (no auth required)
222
- if (pathname === "/" && request.method === "GET") {
223
- const html = homeTemplate(
224
- mcpEndpoint,
225
- templateConfig.name,
226
- templateConfig.description
227
- );
228
- const response = new Response(html, {
229
- status: 200,
230
- headers: { "Content-Type": "text/html" },
231
- });
232
- return addCorsHeaders(response, requestOrigin);
233
- }
234
-
235
- // MCP endpoint
236
- if (pathname === mcpEndpoint) {
237
- try {
238
- const { response, authInfo } = await runWebMiddleware(request);
239
- if (response) {
240
- return addCorsHeaders(response, requestOrigin);
241
- }
242
- return handleMcpRequest(request, requestOrigin, _ctx, authInfo);
243
- } catch (error) {
244
- console.error("[Cloudflare-MCP] Middleware error:", error);
245
- const response = new Response(
246
- JSON.stringify({
247
- jsonrpc: "2.0",
248
- error: {
249
- code: -32603,
250
- message: "Internal server error",
251
- },
252
- id: null,
253
- }),
254
- {
255
- status: 500,
256
- headers: { "Content-Type": "application/json" },
257
- }
258
- );
259
- return addCorsHeaders(response, requestOrigin);
260
- }
261
- }
262
-
263
- // 404 for unknown paths
264
- const response = new Response(JSON.stringify({ error: "Not found" }), {
265
- status: 404,
266
- headers: { "Content-Type": "application/json" },
267
- });
268
- return addCorsHeaders(response, requestOrigin);
269
- },
270
- };