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,218 +0,0 @@
1
- import { randomBytes, createHash, BinaryLike } from "crypto";
2
- import {
3
- readFileSync,
4
- writeFileSync,
5
- existsSync,
6
- mkdirSync,
7
- unlinkSync,
8
- } from "fs";
9
- import path from "path";
10
- import os from "os";
11
- import isDockerFunction from "is-docker";
12
- import { isCI } from "./ci-info";
13
-
14
- // This is the key that stores whether or not telemetry is enabled or disabled.
15
- const TELEMETRY_KEY_ENABLED = "telemetry.enabled";
16
-
17
- // This is the key that specifies when the user was informed about anonymous
18
- // telemetry collection.
19
- const TELEMETRY_KEY_NOTIFY_DATE = "telemetry.notifiedAt";
20
-
21
- // This is a quasi-persistent identifier used to dedupe recurring events. It's
22
- // generated from random data and completely anonymous.
23
- const TELEMETRY_KEY_ID = "telemetry.anonymousId";
24
-
25
- // This is the cryptographic salt that is included within every hashed value.
26
- // This salt value is never sent to us, ensuring privacy and the one-way nature
27
- // of the hash (prevents dictionary lookups of pre-computed hashes).
28
- // See the `oneWayHash` function.
29
- const TELEMETRY_KEY_SALT = "telemetry.salt";
30
-
31
- function getConfigPath(): string {
32
- const isEphemeral = isCI || isDockerFunction();
33
-
34
- if (isEphemeral) {
35
- // Store in temp directory for CI/Docker (won't persist)
36
- return path.join(os.tmpdir(), ".xmcp-cache", "telemetry.json");
37
- }
38
-
39
- // Use system config directory
40
- const configDir = path.join(
41
- os.homedir(),
42
- process.platform === "win32" ? "AppData/Local/xmcp" : ".config/xmcp"
43
- );
44
-
45
- return path.join(configDir, "telemetry.json");
46
- }
47
-
48
- interface TelemetryConfig {
49
- [TELEMETRY_KEY_ENABLED]?: boolean;
50
- [TELEMETRY_KEY_NOTIFY_DATE]?: string;
51
- [TELEMETRY_KEY_ID]?: string;
52
- [TELEMETRY_KEY_SALT]?: string;
53
- }
54
-
55
- export class TelemetryStorage {
56
- private configPath: string;
57
- private config: TelemetryConfig | null = null;
58
- private XMCP_TELEMETRY_DISABLED: string | undefined;
59
-
60
- constructor() {
61
- this.configPath = getConfigPath();
62
- this.XMCP_TELEMETRY_DISABLED = process.env.XMCP_TELEMETRY_DISABLED;
63
- this.ensureConfig();
64
- }
65
-
66
- private isEnvTelemetryDisabled(): boolean {
67
- const value = this.XMCP_TELEMETRY_DISABLED;
68
- return typeof value === "string" && value.toLowerCase() === "true";
69
- }
70
-
71
- private ensureConfig(): void {
72
- try {
73
- // Ensure directory exists
74
- const dir = path.dirname(this.configPath);
75
- if (!existsSync(dir)) {
76
- mkdirSync(dir, { recursive: true });
77
- }
78
-
79
- // Read existing config
80
- if (existsSync(this.configPath)) {
81
- const data = readFileSync(this.configPath, "utf-8");
82
- this.config = JSON.parse(data);
83
- } else {
84
- this.config = {};
85
- }
86
- } catch (error) {
87
- // If we can't read/write, use empty config
88
- this.config = {};
89
- }
90
- }
91
-
92
- private get<T>(key: string, defaultValue?: T): T | undefined {
93
- if (!this.config) {
94
- return defaultValue;
95
- }
96
- const val = this.config[key as keyof TelemetryConfig];
97
- return val !== undefined ? (val as T) : defaultValue;
98
- }
99
-
100
- private set<T>(key: string, value: T): void {
101
- if (!this.config) {
102
- return;
103
- }
104
- this.config[key as keyof TelemetryConfig] = value as any;
105
- try {
106
- writeFileSync(
107
- this.configPath,
108
- JSON.stringify(this.config, null, 2),
109
- "utf-8"
110
- );
111
- } catch (error) {
112
- // Ignore write errors
113
- }
114
- }
115
-
116
- private notify(): void {
117
- if (this.isDisabled || !this.config) {
118
- return;
119
- }
120
-
121
- // The end-user has already been notified about our telemetry integration. We
122
- // don't need to constantly annoy them about it.
123
- // We will re-inform users about the telemetry if significant changes are
124
- // ever made.
125
- if (this.get(TELEMETRY_KEY_NOTIFY_DATE, "")) {
126
- return;
127
- }
128
- this.set(TELEMETRY_KEY_NOTIFY_DATE, Date.now().toString());
129
-
130
- if (!isCI) {
131
- console.log("");
132
- console.log(
133
- "xmcp collects anonymous usage data to improve the framework."
134
- );
135
- console.log(" No personal information is collected.");
136
- console.log(
137
- " You can learn more and opt-out by visiting: https://xmcp.dev/telemetry"
138
- );
139
- console.log(" Or disable with: npx xmcp telemetry disable");
140
- console.log("");
141
- }
142
- }
143
-
144
- get anonymousId(): string {
145
- this.notify();
146
-
147
- const val = this.get<string>(TELEMETRY_KEY_ID);
148
- if (val) {
149
- return val;
150
- }
151
-
152
- const generated = randomBytes(32).toString("hex");
153
- this.set(TELEMETRY_KEY_ID, generated);
154
- return generated;
155
- }
156
-
157
- get salt(): string {
158
- const val = this.get<string>(TELEMETRY_KEY_SALT);
159
- if (val) {
160
- return val;
161
- }
162
-
163
- const generated = randomBytes(16).toString("hex");
164
- this.set(TELEMETRY_KEY_SALT, generated);
165
- return generated;
166
- }
167
-
168
- get isDisabled(): boolean {
169
- if (!this.config || this.isEnvTelemetryDisabled()) {
170
- return true;
171
- }
172
- return this.get<boolean>(TELEMETRY_KEY_ENABLED, true) === false;
173
- }
174
-
175
- get isEnabled(): boolean {
176
- return (
177
- !this.isEnvTelemetryDisabled() &&
178
- !!this.config &&
179
- this.get<boolean>(TELEMETRY_KEY_ENABLED, true) !== false
180
- );
181
- }
182
-
183
- setEnabled(enabled: boolean): string | undefined {
184
- this.set(TELEMETRY_KEY_ENABLED, !!enabled);
185
- return this.configPath;
186
- }
187
-
188
- /**
189
- * Create a one-way hash with salt.
190
- * This ensures the hash is truly one-way and prevents dictionary attacks.
191
- */
192
- oneWayHash(payload: BinaryLike): string {
193
- const hash = createHash("sha256");
194
-
195
- // Always prepend the payload value with salt. This ensures the hash is truly
196
- // one-way.
197
- hash.update(this.salt);
198
-
199
- // Update is an append operation, not a replacement. The salt from the prior
200
- // update is still present!
201
- hash.update(payload);
202
- return hash.digest("hex");
203
- }
204
-
205
- clear(): void {
206
- try {
207
- if (existsSync(this.configPath)) {
208
- unlinkSync(this.configPath);
209
- }
210
- } catch (error) {
211
- // Ignore errors
212
- }
213
- }
214
-
215
- get configFilePath(): string {
216
- return this.configPath;
217
- }
218
- }
@@ -1,5 +0,0 @@
1
- import { Request, Response } from "express";
2
-
3
- declare module "xmcp/adapter" {
4
- export const mcpHandler: (req: Request, res: Response) => Promise<void>;
5
- }
@@ -1,20 +0,0 @@
1
- export const CLIENT_INFO_HEADER_NAMES = [
2
- "x-mcp-client-name",
3
- "x-mcp-client-version",
4
- "x-mcp-client-title",
5
- "x-mcp-client-website-url",
6
- "x-mcp-client-description",
7
- ] as const;
8
-
9
- export interface McpClientInfo {
10
- /** MCP client implementation name from initialize.params.clientInfo.name */
11
- name: string;
12
- /** MCP client implementation version from initialize.params.clientInfo.version */
13
- version: string;
14
- /** Optional human-friendly title from initialize.params.clientInfo.title */
15
- title?: string;
16
- /** Optional website URL from initialize.params.clientInfo.websiteUrl */
17
- websiteUrl?: string;
18
- /** Optional description from initialize.params.clientInfo.description */
19
- description?: string;
20
- }
@@ -1,37 +0,0 @@
1
- declare module "xmcp/headers" {
2
- export const headers: typeof import("../runtime/headers").headers;
3
- }
4
-
5
- declare module "xmcp/plugins/x402" {
6
- export const isPaidHandler: typeof import("../plugins/x402/index").isPaidHandler;
7
- export const getX402Registry: typeof import("../plugins/x402/index").getX402Registry;
8
- export type X402ToolOptions = import("../plugins/x402/index").X402ToolOptions;
9
- export type PaidHandler = import("../plugins/x402/index").PaidHandler;
10
- }
11
-
12
- declare module "xmcp/cloudflare" {
13
- export const apiKeyAuthMiddleware: typeof import("../runtime/platforms/cloudflare/middlewares/api-key").cloudflareApiKeyAuthMiddleware;
14
- export const jwtAuthMiddleware: typeof import("../runtime/platforms/cloudflare/middlewares/jwt").cloudflareJwtAuthMiddleware;
15
- export type JWTAuthMiddlewareConfig = import("../runtime/platforms/cloudflare/middlewares/jwt").CloudflareJWTAuthMiddlewareConfig;
16
- export type WebMiddleware = import("./middleware").WebMiddleware;
17
- }
18
-
19
- declare module "*.module.css" {
20
- const classes: { readonly [key: string]: string };
21
- export default classes;
22
- }
23
-
24
- declare module "*.module.less" {
25
- const classes: { readonly [key: string]: string };
26
- export default classes;
27
- }
28
-
29
- declare module "*.css" {
30
- const content: string;
31
- export default content;
32
- }
33
-
34
- declare module "*.less" {
35
- const content: string;
36
- export default content;
37
- }
@@ -1,62 +0,0 @@
1
- // ─── ProvidePlugin (module exports wired from .xmcp/import-map.js) ────────────
2
-
3
- declare const INJECTED_TOOLS: Record<
4
- string,
5
- () => Promise<import("../runtime/utils/server").ToolFile>
6
- >;
7
-
8
- declare const INJECTED_PROMPTS: Record<
9
- string,
10
- () => Promise<import("../runtime/utils/server").PromptFile>
11
- >;
12
-
13
- declare const INJECTED_RESOURCES: Record<
14
- string,
15
- () => Promise<import("../runtime/utils/server").ResourceFile>
16
- >;
17
-
18
- declare const INJECTED_MIDDLEWARE:
19
- | (() => Promise<{
20
- default?:
21
- | import("./middleware").Middleware
22
- | import("./middleware").Middleware[]
23
- | import("./middleware").WebMiddleware
24
- | import("./middleware").WebMiddleware[];
25
- }>)
26
- | undefined;
27
-
28
- // ─── DefinePlugin — config objects ────────────────────────────────────────────
29
-
30
- declare const HTTP_CONFIG: Omit<
31
- NonNullable<import("../compiler/config").ResolvedHttpConfig>,
32
- "cors"
33
- >;
34
-
35
- declare const HTTP_CORS_CONFIG: import("../compiler/config").CorsConfig;
36
-
37
- declare const TEMPLATE_CONFIG: import("../compiler/config").TemplateConfig;
38
-
39
- declare const STDIO_CONFIG: { debug: boolean; silent: boolean };
40
-
41
- declare const SERVER_INFO: import("@modelcontextprotocol/sdk/types").Implementation;
42
-
43
- // ─── DefinePlugin — individual CORS vars (legacy Express adapter) ──────────────
44
-
45
- declare const HTTP_CORS_ORIGIN: string;
46
- declare const HTTP_CORS_METHODS: string;
47
- declare const HTTP_CORS_ALLOWED_HEADERS: string;
48
- declare const HTTP_CORS_EXPOSED_HEADERS: string;
49
- declare const HTTP_CORS_CREDENTIALS: boolean;
50
- declare const HTTP_CORS_MAX_AGE: number;
51
- declare const HTTP_DEBUG: boolean;
52
- declare const HTTP_BODY_SIZE_LIMIT: string;
53
-
54
- // ─── DefinePlugin — runtime flags ─────────────────────────────────────────────
55
-
56
- declare const IS_CLOUDFLARE: boolean;
57
-
58
- declare const INJECTED_CLIENT_BUNDLES:
59
- | Record<string, { js: string; css?: string }>
60
- | undefined;
61
-
62
- declare const RUNTIME_FILES: Record<string, string>;
@@ -1,19 +0,0 @@
1
- import type { RequestHandler, Router } from "express";
2
- import type { AuthInfo } from "@modelcontextprotocol/sdk/server/auth/types";
3
-
4
- export type RequestHandlerAndRouter = {
5
- middleware: RequestHandler;
6
- router: Router;
7
- };
8
-
9
- export type Middleware = RequestHandler | RequestHandlerAndRouter;
10
-
11
- export type WebMiddlewareContext = {
12
- auth?: AuthInfo;
13
- setAuth: (auth: AuthInfo) => void;
14
- };
15
-
16
- export type WebMiddleware = (
17
- request: Request,
18
- context: WebMiddlewareContext
19
- ) => Promise<Response | void> | Response | void;
@@ -1,6 +0,0 @@
1
- export type PromptMetadata = {
2
- name: string;
3
- title: string;
4
- description: string;
5
- role?: string;
6
- };
@@ -1,15 +0,0 @@
1
- import { UIMetadata } from "./ui-meta";
2
-
3
- export interface ResourceMetadata {
4
- name: string;
5
- title?: string;
6
- description?: string;
7
- mimeType?: string;
8
- size?: number;
9
- /** Metadata for the resource. */
10
- _meta?: {
11
- ui?: UIMetadata;
12
- [key: string]: unknown;
13
- };
14
- [key: string]: any;
15
- }
package/src/types/tool.ts DELETED
@@ -1,192 +0,0 @@
1
- import { z } from "zod/v3";
2
- import type { ZodType as ZodTypeV4, infer as inferV4 } from "zod";
3
- import type { ElicitResult as McpElicitResult } from "@modelcontextprotocol/sdk/types";
4
- import { UIMetadata } from "./ui-meta";
5
- import type { McpClientInfo } from "./client-info";
6
-
7
- export interface ToolAnnotations {
8
- /** Human-readable title for the tool */
9
- title?: string;
10
- /** If true, the tool does not modify its environment */
11
- readOnlyHint?: boolean;
12
- /** If true, the tool may perform destructive updates */
13
- destructiveHint?: boolean;
14
- /** If true, repeated calls with same args have no additional effect */
15
- idempotentHint?: boolean;
16
- /** If true, tool interacts with external entities */
17
- openWorldHint?: boolean;
18
- [key: string]: any;
19
- }
20
-
21
- export interface ToolMetadata {
22
- /** Unique identifier for the tool */
23
- name: string;
24
- /** Human-readable description */
25
- description: string;
26
- /** Optional hints about tool behavior */
27
- annotations?: ToolAnnotations;
28
- /** Metadata for the tool. */
29
- _meta?: {
30
- ui?: UIMetadata;
31
- [key: string]: unknown;
32
- };
33
- }
34
-
35
- type CompatibleZodType = z.ZodTypeAny | ZodTypeV4<unknown>;
36
- type InferCompatibleZodType<T extends CompatibleZodType> =
37
- T extends z.ZodTypeAny
38
- ? z.infer<T>
39
- : T extends ZodTypeV4<unknown>
40
- ? inferV4<T>
41
- : never;
42
-
43
- export type ToolSchema = Record<string, CompatibleZodType>;
44
- export type ToolOutputSchema = Record<string, CompatibleZodType>;
45
- export type ElicitResult = McpElicitResult;
46
-
47
- export interface ToolRequestOptions {
48
- /** Progress notification callback */
49
- onprogress?: (progress: any) => void;
50
- /** Abort signal for cancelling the request */
51
- signal?: AbortSignal;
52
- /** Request timeout in milliseconds */
53
- timeout?: number;
54
- /** Whether receiving progress notifications resets the timeout */
55
- resetTimeoutOnProgress?: boolean;
56
- /** Maximum total time to wait for a response */
57
- maxTotalTimeout?: number;
58
- /** Additional transport-specific options */
59
- [key: string]: unknown;
60
- }
61
-
62
- type ElicitStringFormat = "date" | "uri" | "email" | "date-time";
63
-
64
- interface ElicitFieldBase {
65
- title?: string;
66
- description?: string;
67
- }
68
-
69
- export interface ElicitStringField extends ElicitFieldBase {
70
- type: "string";
71
- minLength?: number;
72
- maxLength?: number;
73
- format?: ElicitStringFormat;
74
- default?: string;
75
- }
76
-
77
- export interface ElicitEnumField extends ElicitFieldBase {
78
- type: "string";
79
- enum: string[];
80
- enumNames?: string[];
81
- default?: string;
82
- }
83
-
84
- export interface ElicitBooleanField extends ElicitFieldBase {
85
- type: "boolean";
86
- default?: boolean;
87
- }
88
-
89
- export interface ElicitNumberField extends ElicitFieldBase {
90
- type: "number" | "integer";
91
- minimum?: number;
92
- maximum?: number;
93
- default?: number;
94
- }
95
-
96
- export type ElicitFormField =
97
- | ElicitStringField
98
- | ElicitEnumField
99
- | ElicitBooleanField
100
- | ElicitNumberField;
101
-
102
- export interface ElicitFormSchema {
103
- type: "object";
104
- properties: Record<string, ElicitFormField>;
105
- required?: string[];
106
- }
107
-
108
- export interface ElicitFormRequest {
109
- mode?: "form";
110
- message: string;
111
- requestedSchema: ElicitFormSchema;
112
- }
113
-
114
- export interface ElicitUrlRequest {
115
- mode: "url";
116
- message: string;
117
- url: string;
118
- elicitationId: string;
119
- }
120
-
121
- export type ElicitRequest = ElicitFormRequest | ElicitUrlRequest;
122
-
123
- // The ToolExtraArguments type is based on Parameters<ToolCallback<undefined>>[0]
124
- // from @modelcontextprotocol/sdk, with xmcp-specific extensions.
125
- /**
126
- * Extra arguments passed to MCP tool functions.
127
- */
128
- export interface ToolExtraArguments {
129
- /** An abort signal used to communicate if the request was cancelled from the sender's side */
130
- signal: AbortSignal;
131
-
132
- /** Information about a validated access token, provided to request handlers */
133
- authInfo?: {
134
- /** The access token */
135
- token: string;
136
- /** The client ID associated with this token */
137
- clientId: string;
138
- /** Scopes associated with this token */
139
- scopes: string[];
140
- /** When the token expires (in seconds since epoch) */
141
- expiresAt?: number;
142
- /** The RFC 8707 resource server identifier for which this token is valid */
143
- resource?: URL;
144
- /** Additional data associated with the token */
145
- extra?: Record<string, unknown>;
146
- };
147
-
148
- /** The session ID from the transport, if available */
149
- sessionId?: string;
150
-
151
- /** Metadata from the original request */
152
- _meta?: {
153
- /** Progress token for tracking long-running operations */
154
- progressToken?: string | number;
155
- };
156
-
157
- /** The JSON-RPC ID of the request being handled */
158
- requestId: string | number;
159
-
160
- /** The original HTTP request information */
161
- requestInfo?: {
162
- /** The headers of the request */
163
- headers: Record<string, string | string[] | undefined>;
164
- };
165
-
166
- /** MCP client metadata from initialize.params.clientInfo, when available */
167
- clientInfo?: McpClientInfo;
168
-
169
- /** Sends a notification that relates to the current request being handled */
170
- sendNotification: (notification: any) => Promise<void>;
171
-
172
- /** Sends a request that relates to the current request being handled */
173
- sendRequest: <U extends CompatibleZodType>(
174
- request: any,
175
- resultSchema: U,
176
- options?: ToolRequestOptions
177
- ) => Promise<InferCompatibleZodType<U>>;
178
-
179
- /** Requests user input from the connected client */
180
- elicit: (
181
- request: ElicitRequest,
182
- options?: ToolRequestOptions
183
- ) => Promise<ElicitResult>;
184
- }
185
-
186
- export type InferSchema<T extends Record<string, unknown>> = {
187
- [K in keyof T]: T[K] extends z.ZodTypeAny
188
- ? z.infer<T[K]>
189
- : T[K] extends ZodTypeV4<unknown>
190
- ? inferV4<T[K]>
191
- : never;
192
- };
@@ -1,42 +0,0 @@
1
- export interface UIMetadata {
2
- /**
3
- * URI template for the widget resource.
4
- * Auto-generated as `ui://app/{toolName}.html` when omitted.
5
- */
6
- resourceUri?: string;
7
-
8
- /**
9
- * Visibility hint for how prominently hosts should surface the widget entry point.
10
- */
11
- visibility?: Array<"model" | "app">;
12
-
13
- /**
14
- * Content Security Policy configuration for widget resources.
15
- */
16
- csp?: {
17
- connectDomains?: string[];
18
- resourceDomains?: string[];
19
- frameDomains?: string[];
20
- baseUriDomains?: string[];
21
- };
22
-
23
- /**
24
- * Browser permission hints requested by the widget iframe.
25
- */
26
- permissions?: {
27
- camera?: Record<string, never>;
28
- microphone?: Record<string, never>;
29
- geolocation?: Record<string, never>;
30
- clipboardWrite?: Record<string, never>;
31
- };
32
-
33
- /**
34
- * Optional dedicated origin for this widget.
35
- */
36
- domain?: string;
37
-
38
- /**
39
- * Visual hint indicating the widget prefers a border.
40
- */
41
- prefersBorder?: boolean;
42
- }
@@ -1,5 +0,0 @@
1
- import chalk from "chalk";
2
-
3
- export const greenCheck = chalk.bold.green("✔");
4
- export const xmcpLogo = chalk.bold.black.bgWhite(" XMCP ");
5
- export const yellowArrow = chalk.bold.yellow("❯");
@@ -1,31 +0,0 @@
1
- import path from "path";
2
- import { createRequire } from "module";
3
-
4
- export const runtimeFolder = ".xmcp";
5
- export const runtimeFolderPath = path.join(process.cwd(), runtimeFolder);
6
- export const rootFolder = path.join(process.cwd());
7
-
8
- export const processFolder = process.cwd();
9
- export const distOutputPath = path.join(processFolder, "dist");
10
- export const adapterOutputPath = path.join(runtimeFolderPath, "adapter");
11
- export const cloudflareOutputPath = path.join(runtimeFolderPath, "cloudflare");
12
-
13
- /**
14
- * Resolve the absolute path to the `xmcp` package `src/` folder.
15
- *
16
- * Used when we need to bundle TypeScript source from xmcp itself
17
- * (e.g. Cloudflare adapter builds).
18
- */
19
- export function resolveXmcpSrcPath(): string {
20
- try {
21
- const req = createRequire(path.join(process.cwd(), "package.json"));
22
- const pkgJsonPath = req.resolve("xmcp/package.json");
23
- return path.join(path.dirname(pkgJsonPath), "src");
24
- } catch (error) {
25
- throw new Error(
26
- `Could not resolve xmcp source path. ` +
27
- `Make sure the \"xmcp\" package is resolvable from your project.\n` +
28
- `Original error: ${error instanceof Error ? error.message : String(error)}`
29
- );
30
- }
31
- }