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,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
- };