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,34 +0,0 @@
1
- import { join } from "node:path";
2
- import { existsSync } from "node:fs";
3
-
4
- export function hasPostCSSConfig(): boolean {
5
- const cwd = process.cwd();
6
- const configFiles = [
7
- "postcss.config.js",
8
- "postcss.config.mjs",
9
- "postcss.config.cjs",
10
- ".postcssrc",
11
- ".postcssrc.json",
12
- ".postcssrc.js",
13
- ];
14
-
15
- return configFiles.some((file) => existsSync(join(cwd, file)));
16
- }
17
-
18
- export function findGlobalsCss(): string | null {
19
- const cwd = process.cwd();
20
- const searchPaths = [
21
- "globals.css",
22
- "src/globals.css",
23
- "src/tools/globals.css",
24
- ];
25
-
26
- for (const relativePath of searchPaths) {
27
- const absolutePath = join(cwd, relativePath);
28
- if (existsSync(absolutePath)) {
29
- return absolutePath;
30
- }
31
- }
32
-
33
- return null;
34
- }
@@ -1,22 +0,0 @@
1
- import { compilerContext } from "../compiler-context";
2
- import {
3
- pathToToolNameMd5,
4
- pathToToolNameDjb2,
5
- } from "@/runtime/utils/path-to-tool-name";
6
-
7
- /**
8
- * Get the appropriate pathToToolName function based on target platform.
9
- * - For Cloudflare: Use djb2 hash
10
- * - For Node.js (express, nextjs, etc.): Use MD5 hash
11
- */
12
- export function pathToToolName(path: string): string {
13
- try {
14
- const { platforms } = compilerContext.getContext();
15
- if (platforms?.cloudflare) {
16
- return pathToToolNameDjb2(path);
17
- }
18
- } catch {
19
- // Context not available, use default (MD5)
20
- }
21
- return pathToToolNameMd5(path);
22
- }
@@ -1,72 +0,0 @@
1
- import path from "path";
2
- import fs from "fs";
3
-
4
- function normalizeSlashes(value: string): string {
5
- return value.replace(/\\/g, "/");
6
- }
7
-
8
- function stripLeadingDotSlash(value: string): string {
9
- return value.replace(/^\.\//, "");
10
- }
11
-
12
- export function toProjectRelativePath(
13
- filePath: string,
14
- cwd: string = process.cwd()
15
- ): string {
16
- const relativePath = path.isAbsolute(filePath)
17
- ? path.relative(cwd, filePath)
18
- : filePath;
19
-
20
- return stripLeadingDotSlash(normalizeSlashes(relativePath));
21
- }
22
-
23
- export function addWatchedPath(
24
- pathSet: Set<string>,
25
- filePath: string,
26
- cwd: string = process.cwd()
27
- ) {
28
- pathSet.add(toProjectRelativePath(filePath, cwd));
29
- }
30
-
31
- export function removeWatchedPath(
32
- pathSet: Set<string>,
33
- filePath: string,
34
- cwd: string = process.cwd()
35
- ) {
36
- const normalizedRawPath = stripLeadingDotSlash(normalizeSlashes(filePath));
37
- const normalizedRelativePath = toProjectRelativePath(filePath, cwd);
38
-
39
- const normalizedCandidates = new Set<string>([
40
- normalizedRawPath,
41
- normalizedRelativePath,
42
- ]);
43
-
44
- for (const currentPath of Array.from(pathSet)) {
45
- const normalizedCurrentPath = stripLeadingDotSlash(
46
- normalizeSlashes(currentPath)
47
- );
48
-
49
- if (normalizedCandidates.has(normalizedCurrentPath)) {
50
- pathSet.delete(currentPath);
51
- }
52
- }
53
- }
54
-
55
- export function pruneMissingWatchedPaths(
56
- pathSet: Set<string>,
57
- cwd: string = process.cwd()
58
- ): boolean {
59
- let removed = false;
60
-
61
- for (const currentPath of Array.from(pathSet)) {
62
- const normalized = stripLeadingDotSlash(normalizeSlashes(currentPath));
63
- const absolutePath = path.resolve(cwd, normalized);
64
-
65
- if (!fs.existsSync(absolutePath)) {
66
- pathSet.delete(currentPath);
67
- removed = true;
68
- }
69
- }
70
-
71
- return removed;
72
- }
@@ -1,36 +0,0 @@
1
- export { createMcpHostBridge } from "./runtime/utils/mcp-host-bridge";
2
- export type {
3
- McpHostBridge,
4
- McpHostBridgeState,
5
- CreateMcpHostBridgeOptions,
6
- } from "./runtime/utils/mcp-host-bridge";
7
- export type {
8
- McpHostCallToolParams,
9
- McpHostContext,
10
- McpHostCapabilities,
11
- McpHostContainerDimensions,
12
- McpHostOpenLinkParams,
13
- McpHostReadResourceResult,
14
- McpHostRequestDisplayModeParams,
15
- McpHostRequestDisplayModeResult,
16
- McpHostSendMessageParams,
17
- McpHostMessageResult,
18
- McpHostModelContextResult,
19
- McpHostToolContentItem,
20
- McpHostToolResult,
21
- McpUiDisplayMode,
22
- McpHostUpdateModelContextParams,
23
- } from "./runtime/utils/mcp-app-types";
24
- export {
25
- MCP_APPS_PROTOCOL_VERSION,
26
- INITIALIZE_METHOD,
27
- INITIALIZED_METHOD,
28
- REQUEST_DISPLAY_MODE_METHOD,
29
- OPEN_LINK_METHOD,
30
- UPDATE_MODEL_CONTEXT_METHOD,
31
- UI_MESSAGE_METHOD,
32
- LOG_MESSAGE_METHOD,
33
- RESOURCES_READ_METHOD,
34
- HOST_CONTEXT_CHANGED_METHOD,
35
- SIZE_CHANGED_METHOD,
36
- } from "./runtime/utils/mcp-app-protocol";
package/src/index.ts DELETED
@@ -1,94 +0,0 @@
1
- import dotenv from "dotenv";
2
- export type {
3
- Middleware,
4
- WebMiddleware,
5
- WebMiddlewareContext,
6
- } from "./types/middleware";
7
- dotenv.config();
8
-
9
- export type {
10
- ToolMetadata,
11
- ToolSchema,
12
- ToolOutputSchema,
13
- ToolExtraArguments,
14
- InferSchema,
15
- ElicitResult,
16
- } from "./types/tool";
17
- export type { McpClientInfo } from "./types/client-info";
18
- export type { PromptMetadata } from "./types/prompt";
19
- export type { ResourceMetadata } from "./types/resource";
20
- export type { UIMetadata } from "./types/ui-meta";
21
-
22
- export type { XmcpConfigInputSchema as XmcpConfig } from "./compiler/config";
23
- import "./types/declarations";
24
- export { apiKeyAuthMiddleware } from "./auth/api-key";
25
- export { jwtAuthMiddleware } from "./auth/jwt";
26
-
27
- export { createContext } from "./utils/context";
28
-
29
- export { completable } from "@modelcontextprotocol/sdk/server/completable";
30
- export { UrlElicitationRequiredError } from "@modelcontextprotocol/sdk/types";
31
-
32
- export {
33
- createHTTPClient,
34
- createSTDIOClient,
35
- listSTDIOClientTools,
36
- callSTDIOClientTool,
37
- disconnectSTDIOClient,
38
- } from "./client";
39
- export type {
40
- HttpClient,
41
- StdioClient,
42
- StdioIOStrategy,
43
- ClientConnectionEntry,
44
- ClientConnections,
45
- ClientDefinition,
46
- HttpClientConfig,
47
- StdioClientConfig,
48
- } from "./client/types";
49
- export type { StdioClientConnection, StdioClientOptions } from "./client";
50
- export type {
51
- CustomHeaders,
52
- CustomHeader,
53
- StaticHeader,
54
- EnvHeader,
55
- } from "./client/headers";
56
- export { isEnvHeader, headersToRecord } from "./client/headers";
57
-
58
- export { extractToolNamesFromRequest } from "./runtime/utils/request-tool-names";
59
- export { createMcpHostBridge } from "./runtime/utils/mcp-host-bridge";
60
- export type {
61
- McpHostBridge,
62
- McpHostBridgeState,
63
- CreateMcpHostBridgeOptions,
64
- } from "./runtime/utils/mcp-host-bridge";
65
- export type {
66
- McpHostCallToolParams,
67
- McpHostContext,
68
- McpHostCapabilities,
69
- McpHostContainerDimensions,
70
- McpHostOpenLinkParams,
71
- McpHostReadResourceResult,
72
- McpHostRequestDisplayModeParams,
73
- McpHostRequestDisplayModeResult,
74
- McpHostSendMessageParams,
75
- McpHostMessageResult,
76
- McpHostModelContextResult,
77
- McpHostToolContentItem,
78
- McpHostToolResult,
79
- McpUiDisplayMode,
80
- McpHostUpdateModelContextParams,
81
- } from "./runtime/utils/mcp-app-types";
82
- export {
83
- MCP_APPS_PROTOCOL_VERSION,
84
- INITIALIZE_METHOD,
85
- INITIALIZED_METHOD,
86
- REQUEST_DISPLAY_MODE_METHOD,
87
- OPEN_LINK_METHOD,
88
- UPDATE_MODEL_CONTEXT_METHOD,
89
- UI_MESSAGE_METHOD,
90
- LOG_MESSAGE_METHOD,
91
- RESOURCES_READ_METHOD,
92
- HOST_CONTEXT_CHANGED_METHOD,
93
- SIZE_CHANGED_METHOD,
94
- } from "./runtime/utils/mcp-app-protocol";
@@ -1,116 +0,0 @@
1
- import path from "path";
2
- import fs from "fs";
3
-
4
- const rootDir = process.cwd();
5
-
6
- interface BuildCloudflareOutputOptions {
7
- log?: boolean;
8
- }
9
-
10
- /**
11
- * Build the Cloudflare Workers output structure.
12
- * Writes Cloudflare Worker files to the project root:
13
- * - worker.js
14
- * - wrangler.jsonc (only if not already present)
15
- */
16
- async function buildCloudflareOutput(
17
- options: BuildCloudflareOutputOptions = {}
18
- ) {
19
- const { log = true } = options;
20
- const outputDir = rootDir;
21
- const buildDir = path.join(rootDir, ".xmcp", "cloudflare");
22
-
23
- // Check if Cloudflare worker build exists
24
- const sourceFile = path.join(buildDir, "worker.js");
25
- if (!fs.existsSync(sourceFile)) {
26
- throw new Error("Cloudflare build output not found. Run: xmcp build --cf");
27
- }
28
-
29
- // Copy the bundled worker
30
- const targetFile = path.join(outputDir, "worker.js");
31
- fs.copyFileSync(sourceFile, targetFile);
32
-
33
- // Generate wrangler config (only if the user doesn't have one already)
34
- const wranglerTomlPath = path.join(outputDir, "wrangler.toml");
35
- const wranglerJsoncPath = path.join(outputDir, "wrangler.jsonc");
36
- if (!fs.existsSync(wranglerTomlPath) && !fs.existsSync(wranglerJsoncPath)) {
37
- const projectName = getProjectName();
38
- const wranglerConfig = generateWranglerConfig(projectName);
39
- fs.writeFileSync(wranglerJsoncPath, wranglerConfig);
40
- }
41
-
42
- if (log) {
43
- console.log("Cloudflare Workers output structure created successfully");
44
- console.log("");
45
- console.log("Next steps:");
46
- console.log(" 1. npx wrangler dev # Test locally");
47
- console.log(" 2. npx wrangler deploy # Deploy to Cloudflare");
48
- }
49
- }
50
-
51
- /**
52
- * Get the project name from package.json or directory name.
53
- */
54
- function getProjectName(): string {
55
- try {
56
- const packageJsonPath = path.join(rootDir, "package.json");
57
- if (fs.existsSync(packageJsonPath)) {
58
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
59
- if (packageJson.name) {
60
- // Sanitize the name for Cloudflare Workers
61
- return packageJson.name
62
- .replace(/^@[^/]+\//, "") // Remove scope
63
- .replace(/[^a-zA-Z0-9-]/g, "-") // Replace invalid chars
64
- .toLowerCase();
65
- }
66
- }
67
- } catch {
68
- // Fallback to directory name
69
- }
70
-
71
- return path
72
- .basename(rootDir)
73
- .replace(/[^a-zA-Z0-9-]/g, "-")
74
- .toLowerCase();
75
- }
76
-
77
- /**
78
- * Generate a wrangler.jsonc configuration file.
79
- */
80
- function generateWranglerConfig(projectName: string): string {
81
- const compatibilityDate = new Date().toISOString().split("T")[0];
82
-
83
- // JSONC format: valid JSON with comments and trailing commas allowed
84
- return `{
85
- "$schema": "node_modules/wrangler/config-schema.json",
86
- // Wrangler config generated by: xmcp build --cf
87
- // Docs: https://developers.cloudflare.com/workers/wrangler/configuration/
88
- "name": ${JSON.stringify(projectName)},
89
- "main": "worker.js",
90
- "compatibility_date": ${JSON.stringify(compatibilityDate)},
91
- "compatibility_flags": ["nodejs_compat"],
92
-
93
- // Observability (Workers Logs)
94
- "observability": {
95
- "enabled": true
96
- }
97
-
98
- // Uncomment to add environment variables:
99
- // "vars": {
100
- // "MY_VAR": "my-value"
101
- // },
102
-
103
- // Uncomment to add KV namespaces:
104
- // "kv_namespaces": [
105
- // { "binding": "MY_KV", "id": "your-kv-namespace-id" }
106
- // ],
107
-
108
- // Uncomment to add D1 databases:
109
- // "d1_databases": [
110
- // { "binding": "MY_DB", "database_name": "my-database", "database_id": "your-database-id" }
111
- // ]
112
- }
113
- `;
114
- }
115
-
116
- export { buildCloudflareOutput };
@@ -1,131 +0,0 @@
1
- import path from "path";
2
- import fs from "fs";
3
-
4
- const rootDir = process.cwd();
5
-
6
- async function buildVercelOutput() {
7
- const outputDir = path.join(rootDir, ".vercel", "output");
8
- const functionsDir = path.join(outputDir, "functions", "api", "index.func");
9
-
10
- console.log("🚀 Building Vercel output structure...");
11
-
12
- fs.mkdirSync(outputDir, { recursive: true });
13
- fs.mkdirSync(functionsDir, { recursive: true });
14
-
15
- const distDir = path.join(rootDir, "dist");
16
- const sourceFile = path.join(distDir, "http.js");
17
- const targetFile = path.join(functionsDir, "index.js");
18
-
19
- if (!fs.existsSync(distDir)) {
20
- throw new Error("❌ Dist directory not found. Run build first.");
21
- }
22
-
23
- if (fs.existsSync(sourceFile)) {
24
- fs.copyFileSync(sourceFile, targetFile);
25
- } else {
26
- throw new Error(
27
- "❌ Application server file not found in dist/. Run build first."
28
- );
29
- }
30
-
31
- // copy all other files from dist directory that http.js might depend on
32
- const distContents = fs.readdirSync(distDir);
33
-
34
- // to do add proper error handling for failed copy
35
- for (const item of distContents) {
36
- const sourcePath = path.join(distDir, item);
37
- const targetPath = path.join(functionsDir, item);
38
-
39
- if (item === "http.js" || item === "stdio.js" || item === "auth-ui")
40
- continue;
41
-
42
- const stat = fs.statSync(sourcePath);
43
- if (stat.isFile()) {
44
- fs.copyFileSync(sourcePath, targetPath);
45
- } else if (stat.isDirectory()) {
46
- fs.cpSync(sourcePath, targetPath, { recursive: true });
47
- }
48
- }
49
-
50
- const packageJsonSource = path.join(rootDir, "package.json");
51
- const packageJsonTarget = path.join(functionsDir, "package.json");
52
- fs.copyFileSync(packageJsonSource, packageJsonTarget);
53
-
54
- console.log("Server and dependency files copied to function directory");
55
-
56
- // Copy static assets to static directory for Vercel
57
- const staticDir = path.join(outputDir, "static");
58
- fs.mkdirSync(staticDir, { recursive: true });
59
-
60
- // Check if auth-ui assets exist in dist or node_modules and copy them
61
- let authUiDir = path.join(distDir, "auth-ui");
62
- if (!fs.existsSync(authUiDir)) {
63
- authUiDir = path.join(
64
- rootDir,
65
- "node_modules",
66
- "@xmcp-dev",
67
- "better-auth",
68
- "dist",
69
- "auth-ui"
70
- );
71
- }
72
-
73
- if (fs.existsSync(authUiDir)) {
74
- const staticAuthDir = path.join(staticDir, "auth");
75
- fs.cpSync(authUiDir, staticAuthDir, { recursive: true });
76
- console.log("Auth UI assets copied to static directory");
77
-
78
- // Remove auth-ui from function directory if it was copied there
79
- const functionAuthDir = path.join(functionsDir, "auth-ui");
80
- if (fs.existsSync(functionAuthDir)) {
81
- fs.rmSync(functionAuthDir, { recursive: true });
82
- console.log("Auth UI assets removed from function directory");
83
- }
84
- }
85
-
86
- const vcConfig = {
87
- handler: "index.js",
88
- runtime: "nodejs22.x",
89
- launcherType: "Nodejs",
90
- shouldAddHelpers: true,
91
- };
92
-
93
- fs.writeFileSync(
94
- path.join(functionsDir, ".vc-config.json"),
95
- JSON.stringify(vcConfig, null, 2)
96
- );
97
-
98
- const config = {
99
- version: 3,
100
- routes: [
101
- // static auth assets first
102
- {
103
- src: "^/auth/assets/(.*)$",
104
- dest: "/auth/assets/$1",
105
- },
106
- // filesystem (static files)
107
- {
108
- handle: "filesystem",
109
- },
110
- // auth routes should serve the static index.html for client-side routing
111
- {
112
- src: "^/auth/(sign-in|callback/.*|index\\.html)?$",
113
- dest: "/auth/index.html",
114
- },
115
- // rest of the endpoints
116
- {
117
- src: "^/(.*)$",
118
- dest: "/api",
119
- },
120
- ],
121
- };
122
-
123
- fs.writeFileSync(
124
- path.join(outputDir, "config.json"),
125
- JSON.stringify(config, null, 2)
126
- );
127
-
128
- console.log("✅ Vercel output structure created successfully");
129
- }
130
-
131
- export { buildVercelOutput };
@@ -1 +0,0 @@
1
- export * as x402 from "./x402";
@@ -1,24 +0,0 @@
1
- export interface X402ToolOptions {
2
- price?: number;
3
- currency?: string;
4
- network?: string;
5
- receipt?: boolean;
6
- maxPaymentAge?: number;
7
- description?: string;
8
- }
9
-
10
- export interface PaidHandler {
11
- __x402: X402ToolOptions;
12
- }
13
-
14
- declare global {
15
- var __XMCP_X402_REGISTRY: Map<string, X402ToolOptions> | undefined;
16
- }
17
-
18
- export function isPaidHandler(handler: unknown): handler is PaidHandler {
19
- return typeof handler === "function" && "__x402" in handler;
20
- }
21
-
22
- export function getX402Registry(): Map<string, X402ToolOptions> | undefined {
23
- return global.__XMCP_X402_REGISTRY;
24
- }
@@ -1,75 +0,0 @@
1
- import { Request, Response } from "express";
2
- import { createServer } from "@/runtime/utils/server";
3
- import { StatelessHttpServerTransport } from "@/runtime/transports/http/stateless-streamable-http";
4
- import { setHeaders } from "@/runtime/transports/http/cors";
5
- import { httpRequestContextProvider } from "@/runtime/contexts/http-request-context";
6
- import { randomUUID } from "node:crypto";
7
- import { extractClientInfoFromMessages } from "@/runtime/utils/client-info";
8
-
9
- // cors config
10
- const corsOrigin = HTTP_CORS_ORIGIN as string;
11
- const corsMethods = HTTP_CORS_METHODS as string;
12
- const corsAllowedHeaders = HTTP_CORS_ALLOWED_HEADERS as string;
13
- const corsExposedHeaders = HTTP_CORS_EXPOSED_HEADERS as string;
14
- const corsCredentials = HTTP_CORS_CREDENTIALS as boolean;
15
- const corsMaxAge = HTTP_CORS_MAX_AGE as number;
16
-
17
- const debug = HTTP_DEBUG as boolean;
18
- const bodySizeLimit = HTTP_BODY_SIZE_LIMIT as string;
19
-
20
- export async function xmcpHandler(req: Request, res: Response) {
21
- return new Promise((resolve) => {
22
- const id = randomUUID();
23
- const clientInfo = extractClientInfoFromMessages(req.body);
24
-
25
- httpRequestContextProvider(
26
- { id, headers: req.headers, clientInfo },
27
- async () => {
28
- try {
29
- setHeaders(
30
- res,
31
- {
32
- origin: corsOrigin,
33
- methods: corsMethods,
34
- allowedHeaders: corsAllowedHeaders,
35
- exposedHeaders: corsExposedHeaders,
36
- credentials: corsCredentials,
37
- maxAge: corsMaxAge,
38
- },
39
- req.headers.origin
40
- );
41
-
42
- const server = await createServer();
43
- const transport = new StatelessHttpServerTransport(
44
- debug,
45
- bodySizeLimit || "10mb"
46
- );
47
-
48
- // cleanup when request/connection closes
49
- res.on("close", () => {
50
- transport.close();
51
- server.close();
52
- });
53
-
54
- await server.connect(transport);
55
-
56
- await transport.handleRequest(req, res, req.body).then(() => {
57
- resolve(res);
58
- });
59
- } catch (error) {
60
- console.error("[HTTP-server] Error handling MCP request:", error);
61
- if (!res.headersSent) {
62
- res.status(500).json({
63
- jsonrpc: "2.0",
64
- error: {
65
- code: -32603,
66
- message: "Internal server error",
67
- },
68
- id: null,
69
- });
70
- }
71
- }
72
- }
73
- );
74
- });
75
- }