xmcp 0.6.6 → 0.6.7
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/README.md +32 -0
- package/dist/cli.js +30 -32
- package/dist/compiler/config/index.d.ts +54 -54
- package/dist/compiler/config/schemas/transport/http.d.ts +82 -82
- package/dist/index.d.ts +4 -2
- package/dist/index.js +3 -3
- package/dist/runtime/adapter-express.js +39 -22
- package/dist/runtime/adapter-nestjs.js +39 -22
- package/dist/runtime/adapter-nextjs.js +38 -21
- package/dist/runtime/contexts/http-request-context.d.ts +3 -1
- package/dist/runtime/headers.js +1 -1
- package/dist/runtime/http.js +47 -30
- package/dist/runtime/stdio.js +17 -11
- package/dist/runtime/utils/elicitation.d.ts +4 -0
- package/dist/runtime/utils/ext-apps-registry.d.ts +132 -0
- package/dist/runtime/utils/path-to-tool-name.d.ts +20 -0
- package/dist/runtime/utils/prompt-loader.d.ts +11 -0
- package/dist/runtime/utils/prompts.d.ts +8 -0
- package/dist/runtime/utils/react/generate-html.d.ts +1 -0
- package/dist/runtime/utils/react/index.d.ts +4 -0
- package/dist/runtime/utils/resource-loader.d.ts +11 -0
- package/dist/runtime/utils/resources.d.ts +4 -0
- package/dist/runtime/utils/server.d.ts +35 -0
- package/dist/runtime/utils/tool-loader.d.ts +11 -0
- package/dist/runtime/utils/tools.d.ts +11 -0
- package/dist/runtime/utils/transformers/prompt.d.ts +32 -0
- package/dist/runtime/utils/transformers/resource.d.ts +26 -0
- package/dist/runtime/utils/transformers/tool.d.ts +30 -0
- package/dist/runtime/utils/ui/flatten-meta.d.ts +6 -0
- package/dist/runtime/utils/ui/split-meta.d.ts +17 -0
- package/dist/runtime/utils/utils/resource-uri-composer.d.ts +60 -0
- package/dist/runtime/utils/validators/index.d.ts +13 -0
- package/dist/types/client-info.d.ts +12 -0
- package/dist/types/tool.d.ts +69 -14
- package/dist/utils/context.d.ts +1 -1
- package/package.json +9 -1
- package/src/client/index.ts +4 -1
- package/src/compiler/generate-tools-code.ts +4 -6
- package/src/compiler/get-bundler-config/plugins/index.ts +0 -1
- package/src/compiler/index.ts +24 -7
- package/src/index.ts +8 -1
- package/src/runtime/adapters/express/index.ts +45 -47
- package/src/runtime/adapters/nestjs/xmcp.service.ts +4 -3
- package/src/runtime/adapters/nextjs/handler/node-to-web-adapter.ts +40 -6
- package/src/runtime/adapters/nextjs/handler/request-converter.ts +20 -0
- package/src/runtime/adapters/nextjs/handler/server-lifecycle.ts +8 -5
- package/src/runtime/adapters/nextjs/index.ts +41 -25
- package/src/runtime/contexts/http-request-context.ts +2 -0
- package/src/runtime/headers.ts +37 -2
- package/src/runtime/platforms/cloudflare/cors.ts +0 -1
- package/src/runtime/platforms/cloudflare/worker.ts +46 -44
- package/src/runtime/transports/http/index.ts +0 -4
- package/src/runtime/transports/http/stateless-streamable-http.ts +131 -233
- package/src/runtime/transports/stdio/index.ts +0 -2
- package/src/runtime/utils/__tests__/client-info.test.ts +80 -0
- package/src/runtime/utils/__tests__/tool-extra.test.ts +110 -0
- package/src/runtime/utils/client-info.ts +71 -0
- package/src/runtime/utils/elicitation.ts +396 -0
- package/src/runtime/utils/prompt-loader.ts +151 -0
- package/src/runtime/utils/resource-loader.ts +151 -0
- package/src/runtime/utils/resources.ts +0 -8
- package/src/runtime/utils/server.ts +28 -38
- package/src/runtime/utils/tool-loader.ts +149 -0
- package/src/runtime/utils/tools.ts +9 -6
- package/src/runtime/utils/transformers/tool.ts +26 -5
- package/src/types/client-info.ts +12 -0
- package/src/types/injected.d.ts +62 -0
- package/src/types/tool.ts +99 -17
- package/src/utils/context.ts +2 -2
|
@@ -0,0 +1,62 @@
|
|
|
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>;
|
package/src/types/tool.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { z } from "zod/v3";
|
|
2
2
|
import type { ZodType as ZodTypeV4, infer as inferV4 } from "zod";
|
|
3
|
+
import type { ElicitResult as McpElicitResult } from "@modelcontextprotocol/sdk/types";
|
|
3
4
|
import { UIMetadata } from "./ui-meta";
|
|
5
|
+
import type { McpClientInfo } from "./client-info";
|
|
4
6
|
|
|
5
7
|
export interface ToolAnnotations {
|
|
6
8
|
/** Human-readable title for the tool */
|
|
@@ -31,11 +33,95 @@ export interface ToolMetadata {
|
|
|
31
33
|
}
|
|
32
34
|
|
|
33
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;
|
|
34
42
|
|
|
35
43
|
export type ToolSchema = Record<string, CompatibleZodType>;
|
|
36
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
|
+
}
|
|
37
88
|
|
|
38
|
-
|
|
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.
|
|
39
125
|
/**
|
|
40
126
|
* Extra arguments passed to MCP tool functions.
|
|
41
127
|
*/
|
|
@@ -77,28 +163,24 @@ export interface ToolExtraArguments {
|
|
|
77
163
|
headers: Record<string, string | string[] | undefined>;
|
|
78
164
|
};
|
|
79
165
|
|
|
166
|
+
/** MCP client metadata from initialize.params.clientInfo, when available */
|
|
167
|
+
clientInfo?: McpClientInfo;
|
|
168
|
+
|
|
80
169
|
/** Sends a notification that relates to the current request being handled */
|
|
81
170
|
sendNotification: (notification: any) => Promise<void>;
|
|
82
171
|
|
|
83
172
|
/** Sends a request that relates to the current request being handled */
|
|
84
|
-
sendRequest: <U extends
|
|
173
|
+
sendRequest: <U extends CompatibleZodType>(
|
|
85
174
|
request: any,
|
|
86
175
|
resultSchema: U,
|
|
87
|
-
options?:
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
resetTimeoutOnProgress?: boolean;
|
|
96
|
-
/** Maximum total time to wait for a response */
|
|
97
|
-
maxTotalTimeout?: number;
|
|
98
|
-
/** Additional transport-specific options */
|
|
99
|
-
[key: string]: unknown;
|
|
100
|
-
}
|
|
101
|
-
) => Promise<z.infer<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>;
|
|
102
184
|
}
|
|
103
185
|
|
|
104
186
|
export type InferSchema<T extends Record<string, unknown>> = {
|
package/src/utils/context.ts
CHANGED
|
@@ -8,7 +8,7 @@ type SetContext<T extends DefaultContext> = (data: Partial<T>) => void;
|
|
|
8
8
|
|
|
9
9
|
export interface Context<T extends DefaultContext> {
|
|
10
10
|
/** Run a callback with a specific context. */
|
|
11
|
-
provider: (initialValue: T, callback: () =>
|
|
11
|
+
provider: <R>(initialValue: T, callback: () => R) => R;
|
|
12
12
|
/** Get the context. */
|
|
13
13
|
getContext: GetContext<T>;
|
|
14
14
|
/** Partially update the context. */
|
|
@@ -88,7 +88,7 @@ export function createContext<T extends Object>({
|
|
|
88
88
|
Object.assign(store, data);
|
|
89
89
|
};
|
|
90
90
|
|
|
91
|
-
const provider = (initialValue: T, callback: () =>
|
|
91
|
+
const provider = <R>(initialValue: T, callback: () => R): R => {
|
|
92
92
|
fallbackStoreWrapper.current = initialValue;
|
|
93
93
|
return context.run(initialValue, callback);
|
|
94
94
|
};
|