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.
- package/dist/cli.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -3
- package/src/auth/api-key.ts +0 -120
- package/src/auth/jwt.ts +0 -52
- package/src/cli/commands/create/__tests__/create.test.ts +0 -99
- package/src/cli/commands/create/index.ts +0 -74
- package/src/cli/commands/create/templates/index.ts +0 -4
- package/src/cli/commands/create/templates/prompt.ts +0 -30
- package/src/cli/commands/create/templates/resource.ts +0 -20
- package/src/cli/commands/create/templates/tool.ts +0 -34
- package/src/cli/commands/create/templates/widget.ts +0 -33
- package/src/cli/utils/naming.ts +0 -39
- package/src/cli.ts +0 -125
- package/src/client/headers.ts +0 -61
- package/src/client/index.ts +0 -180
- package/src/client/types.ts +0 -122
- package/src/client/utils.ts +0 -133
- package/src/cloudflare.ts +0 -6
- package/src/compiler/build-telemetry.ts +0 -88
- package/src/compiler/client/component-compiler.ts +0 -250
- package/src/compiler/client/transpile.ts +0 -21
- package/src/compiler/compiler-context.ts +0 -61
- package/src/compiler/config/__tests__/config.test.ts +0 -459
- package/src/compiler/config/index.ts +0 -62
- package/src/compiler/config/injection.ts +0 -210
- package/src/compiler/config/schemas/bundler.ts +0 -12
- package/src/compiler/config/schemas/experimental/index.ts +0 -22
- package/src/compiler/config/schemas/index.ts +0 -20
- package/src/compiler/config/schemas/paths.ts +0 -35
- package/src/compiler/config/schemas/template.ts +0 -80
- package/src/compiler/config/schemas/transport/http.ts +0 -116
- package/src/compiler/config/schemas/transport/stdio.ts +0 -31
- package/src/compiler/config/schemas/typescript.ts +0 -26
- package/src/compiler/config/utils.ts +0 -168
- package/src/compiler/generate-env-code.ts +0 -5
- package/src/compiler/generate-import-code.ts +0 -187
- package/src/compiler/generate-tools-code.ts +0 -174
- package/src/compiler/get-bundler-config/get-entries.ts +0 -44
- package/src/compiler/get-bundler-config/get-externals.ts +0 -114
- package/src/compiler/get-bundler-config/get-injected-variables.ts +0 -46
- package/src/compiler/get-bundler-config/index.ts +0 -288
- package/src/compiler/get-bundler-config/plugins/index.ts +0 -140
- package/src/compiler/get-bundler-config/plugins/types/express.ts +0 -3
- package/src/compiler/get-bundler-config/plugins/types/fastify.ts +0 -4
- package/src/compiler/get-bundler-config/plugins/types/index.ts +0 -5
- package/src/compiler/get-bundler-config/plugins/types/nest.ts +0 -65
- package/src/compiler/get-bundler-config/plugins/types/next.ts +0 -52
- package/src/compiler/get-bundler-config/resolve-tsconfig-paths.ts +0 -51
- package/src/compiler/index.ts +0 -484
- package/src/compiler/on-first-build.ts +0 -54
- package/src/compiler/parse-xmcp-config.ts +0 -200
- package/src/compiler/start-http-server.ts +0 -42
- package/src/compiler/utils/__tests__/config-detection.test.ts +0 -307
- package/src/compiler/utils/__tests__/path-utils.test.ts +0 -137
- package/src/compiler/utils/config-detection.ts +0 -34
- package/src/compiler/utils/path-utils.ts +0 -22
- package/src/compiler/watcher-recovery.ts +0 -72
- package/src/host-bridge.ts +0 -36
- package/src/index.ts +0 -94
- package/src/platforms/build-cloudflare-output.ts +0 -116
- package/src/platforms/build-vercel-output.ts +0 -131
- package/src/plugins/index.ts +0 -1
- package/src/plugins/x402/index.ts +0 -24
- package/src/runtime/adapters/express/index.ts +0 -75
- package/src/runtime/adapters/fastify/__tests__/fastify.test.ts +0 -115
- package/src/runtime/adapters/fastify/index.ts +0 -78
- package/src/runtime/adapters/nestjs/index.ts +0 -16
- package/src/runtime/adapters/nestjs/xmcp.controller.ts +0 -34
- package/src/runtime/adapters/nestjs/xmcp.guard.ts +0 -101
- package/src/runtime/adapters/nestjs/xmcp.oauth.controller.ts +0 -36
- package/src/runtime/adapters/nestjs/xmcp.oauth.module.ts +0 -21
- package/src/runtime/adapters/nestjs/xmcp.oauth.service.ts +0 -36
- package/src/runtime/adapters/nestjs/xmcp.service.ts +0 -96
- package/src/runtime/adapters/nestjs/xmcp.utils.ts +0 -11
- package/src/runtime/adapters/nextjs/auth.ts +0 -265
- package/src/runtime/adapters/nextjs/handler/error-handler.ts +0 -67
- package/src/runtime/adapters/nextjs/handler/node-to-web-adapter.ts +0 -143
- package/src/runtime/adapters/nextjs/handler/request-converter.ts +0 -74
- package/src/runtime/adapters/nextjs/handler/server-lifecycle.ts +0 -69
- package/src/runtime/adapters/nextjs/index.ts +0 -121
- package/src/runtime/contexts/client-info-context.ts +0 -16
- package/src/runtime/contexts/http-request-context.ts +0 -21
- package/src/runtime/contexts/http-transport-context.ts +0 -18
- package/src/runtime/headers.ts +0 -42
- package/src/runtime/middlewares/utils.ts +0 -72
- package/src/runtime/platforms/cloudflare/cors.ts +0 -44
- package/src/runtime/platforms/cloudflare/middlewares/api-key.ts +0 -102
- package/src/runtime/platforms/cloudflare/middlewares/jwt.ts +0 -127
- package/src/runtime/platforms/cloudflare/types.ts +0 -23
- package/src/runtime/platforms/cloudflare/worker.ts +0 -270
- package/src/runtime/templates/home.ts +0 -746
- package/src/runtime/transports/http/base-streamable-http.ts +0 -46
- package/src/runtime/transports/http/cors/headers.ts +0 -58
- package/src/runtime/transports/http/cors/index.ts +0 -34
- package/src/runtime/transports/http/index.ts +0 -78
- package/src/runtime/transports/http/stateless-streamable-http.ts +0 -353
- package/src/runtime/transports/http/web-stateless-http.ts +0 -288
- package/src/runtime/transports/stdio/index.ts +0 -109
- package/src/runtime/utils/__tests__/client-info.test.ts +0 -146
- package/src/runtime/utils/__tests__/tool-extra.test.ts +0 -239
- package/src/runtime/utils/client-info.ts +0 -114
- package/src/runtime/utils/elicitation.ts +0 -396
- package/src/runtime/utils/ext-apps-registry.ts +0 -151
- package/src/runtime/utils/mcp-app-protocol.ts +0 -16
- package/src/runtime/utils/mcp-app-types.ts +0 -113
- package/src/runtime/utils/mcp-host-bridge.ts +0 -473
- package/src/runtime/utils/path-to-tool-name.ts +0 -69
- package/src/runtime/utils/prompt-loader.ts +0 -151
- package/src/runtime/utils/prompts.ts +0 -69
- package/src/runtime/utils/react/generate-html.ts +0 -69
- package/src/runtime/utils/react/index.ts +0 -6
- package/src/runtime/utils/request-tool-names.ts +0 -48
- package/src/runtime/utils/resource-loader.ts +0 -151
- package/src/runtime/utils/resources.ts +0 -331
- package/src/runtime/utils/server.ts +0 -107
- package/src/runtime/utils/tool-loader.ts +0 -149
- package/src/runtime/utils/tools.ts +0 -183
- package/src/runtime/utils/transformers/prompt.ts +0 -120
- package/src/runtime/utils/transformers/resource.ts +0 -196
- package/src/runtime/utils/transformers/tool.ts +0 -400
- package/src/runtime/utils/ui/__tests__/split-meta.test.ts +0 -803
- package/src/runtime/utils/ui/flatten-meta.ts +0 -44
- package/src/runtime/utils/ui/split-meta.ts +0 -78
- package/src/runtime/utils/utils/resource-uri-composer.ts +0 -204
- package/src/runtime/utils/validators/index.ts +0 -138
- package/src/telemetry/ci-info.ts +0 -6
- package/src/telemetry/debug.ts +0 -8
- package/src/telemetry/events/definitions.ts +0 -52
- package/src/telemetry/events/detached-flush.ts +0 -83
- package/src/telemetry/events/post-payload.ts +0 -141
- package/src/telemetry/events/tracker.ts +0 -281
- package/src/telemetry/index.ts +0 -7
- package/src/telemetry/metadata.ts +0 -49
- package/src/telemetry/project-id.ts +0 -35
- package/src/telemetry/storage.ts +0 -218
- package/src/types/adapter.d.ts +0 -5
- package/src/types/client-info.ts +0 -20
- package/src/types/declarations.ts +0 -37
- package/src/types/injected.d.ts +0 -62
- package/src/types/middleware.ts +0 -19
- package/src/types/prompt.ts +0 -6
- package/src/types/resource.ts +0 -15
- package/src/types/tool.ts +0 -192
- package/src/types/ui-meta.ts +0 -42
- package/src/utils/cli-icons.ts +0 -5
- package/src/utils/constants.ts +0 -31
- package/src/utils/context.ts +0 -105
- package/src/utils/detect-package-manager.ts +0 -46
- package/src/utils/file-watcher.ts +0 -66
- package/src/utils/fs-utils.ts +0 -16
- package/src/utils/path-validation.ts +0 -66
- package/src/utils/port-utils.ts +0 -43
- package/src/utils/spawn-process.ts +0 -49
- 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
|
-
};
|