@modelcontextprotocol/sdk 1.21.2 → 1.23.0-beta.0
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 +92 -11
- package/dist/cjs/client/auth.d.ts +11 -1
- package/dist/cjs/client/auth.d.ts.map +1 -1
- package/dist/cjs/client/auth.js +71 -19
- package/dist/cjs/client/auth.js.map +1 -1
- package/dist/cjs/client/index.d.ts +252 -1478
- package/dist/cjs/client/index.d.ts.map +1 -1
- package/dist/cjs/client/index.js +130 -0
- package/dist/cjs/client/index.js.map +1 -1
- package/dist/cjs/client/sse.d.ts +1 -0
- package/dist/cjs/client/sse.d.ts.map +1 -1
- package/dist/cjs/client/sse.js +5 -3
- package/dist/cjs/client/sse.js.map +1 -1
- package/dist/cjs/client/streamableHttp.d.ts +2 -1
- package/dist/cjs/client/streamableHttp.d.ts.map +1 -1
- package/dist/cjs/client/streamableHttp.js +35 -15
- package/dist/cjs/client/streamableHttp.js.map +1 -1
- package/dist/cjs/examples/client/elicitationUrlExample.d.ts +2 -0
- package/dist/cjs/examples/client/elicitationUrlExample.d.ts.map +1 -0
- package/dist/cjs/examples/client/elicitationUrlExample.js +693 -0
- package/dist/cjs/examples/client/elicitationUrlExample.js.map +1 -0
- package/dist/cjs/examples/client/simpleOAuthClient.js +13 -52
- package/dist/cjs/examples/client/simpleOAuthClient.js.map +1 -1
- package/dist/cjs/examples/client/simpleOAuthClientProvider.d.ts +26 -0
- package/dist/cjs/examples/client/simpleOAuthClientProvider.d.ts.map +1 -0
- package/dist/cjs/examples/client/simpleOAuthClientProvider.js +51 -0
- package/dist/cjs/examples/client/simpleOAuthClientProvider.js.map +1 -0
- package/dist/cjs/examples/client/simpleStreamableHttp.js +11 -6
- package/dist/cjs/examples/client/simpleStreamableHttp.js.map +1 -1
- package/dist/cjs/examples/server/demoInMemoryOAuthProvider.d.ts +4 -4
- package/dist/cjs/examples/server/demoInMemoryOAuthProvider.d.ts.map +1 -1
- package/dist/cjs/examples/server/demoInMemoryOAuthProvider.js +16 -0
- package/dist/cjs/examples/server/demoInMemoryOAuthProvider.js.map +1 -1
- package/dist/cjs/examples/server/elicitationFormExample.d.ts +2 -0
- package/dist/cjs/examples/server/elicitationFormExample.d.ts.map +1 -0
- package/dist/cjs/examples/server/{elicitationExample.js → elicitationFormExample.js} +16 -12
- package/dist/cjs/examples/server/elicitationFormExample.js.map +1 -0
- package/dist/cjs/examples/server/elicitationUrlExample.d.ts +2 -0
- package/dist/cjs/examples/server/elicitationUrlExample.d.ts.map +1 -0
- package/dist/cjs/examples/server/elicitationUrlExample.js +655 -0
- package/dist/cjs/examples/server/elicitationUrlExample.js.map +1 -0
- package/dist/cjs/examples/server/jsonResponseStreamableHttp.js +26 -3
- package/dist/cjs/examples/server/jsonResponseStreamableHttp.js.map +1 -1
- package/dist/cjs/examples/server/mcpServerOutputSchema.js +34 -11
- package/dist/cjs/examples/server/mcpServerOutputSchema.js.map +1 -1
- package/dist/cjs/examples/server/simpleSseServer.js +26 -3
- package/dist/cjs/examples/server/simpleSseServer.js.map +1 -1
- package/dist/cjs/examples/server/simpleStatelessStreamableHttp.js +27 -4
- package/dist/cjs/examples/server/simpleStatelessStreamableHttp.js.map +1 -1
- package/dist/cjs/examples/server/simpleStreamableHttp.js +34 -10
- package/dist/cjs/examples/server/simpleStreamableHttp.js.map +1 -1
- package/dist/cjs/examples/server/sseAndStreamableHttpCompatibleServer.js +26 -3
- package/dist/cjs/examples/server/sseAndStreamableHttpCompatibleServer.js.map +1 -1
- package/dist/cjs/examples/server/toolWithSampleServer.js +30 -8
- package/dist/cjs/examples/server/toolWithSampleServer.js.map +1 -1
- package/dist/cjs/server/auth/handlers/authorize.js +34 -11
- package/dist/cjs/server/auth/handlers/authorize.js.map +1 -1
- package/dist/cjs/server/auth/handlers/token.js +35 -12
- package/dist/cjs/server/auth/handlers/token.js.map +1 -1
- package/dist/cjs/server/auth/middleware/bearerAuth.d.ts.map +1 -1
- package/dist/cjs/server/auth/middleware/bearerAuth.js +13 -8
- package/dist/cjs/server/auth/middleware/bearerAuth.js.map +1 -1
- package/dist/cjs/server/auth/middleware/clientAuth.js +27 -4
- package/dist/cjs/server/auth/middleware/clientAuth.js.map +1 -1
- package/dist/cjs/server/auth/router.js +1 -1
- package/dist/cjs/server/auth/router.js.map +1 -1
- package/dist/cjs/server/completable.d.ts +30 -16
- package/dist/cjs/server/completable.d.ts.map +1 -1
- package/dist/cjs/server/completable.js +38 -55
- package/dist/cjs/server/completable.js.map +1 -1
- package/dist/cjs/server/index.d.ts +213 -71
- package/dist/cjs/server/index.d.ts.map +1 -1
- package/dist/cjs/server/index.js +61 -16
- package/dist/cjs/server/index.js.map +1 -1
- package/dist/cjs/server/mcp.d.ts +14 -16
- package/dist/cjs/server/mcp.d.ts.map +1 -1
- package/dist/cjs/server/mcp.js +105 -41
- package/dist/cjs/server/mcp.js.map +1 -1
- package/dist/cjs/server/zod-compat.d.ts +82 -0
- package/dist/cjs/server/zod-compat.d.ts.map +1 -0
- package/dist/cjs/server/zod-compat.js +252 -0
- package/dist/cjs/server/zod-compat.js.map +1 -0
- package/dist/cjs/server/zod-json-schema-compat.d.ts +12 -0
- package/dist/cjs/server/zod-json-schema-compat.d.ts.map +1 -0
- package/dist/cjs/server/zod-json-schema-compat.js +80 -0
- package/dist/cjs/server/zod-json-schema-compat.js.map +1 -0
- package/dist/cjs/shared/auth.d.ts +116 -502
- package/dist/cjs/shared/auth.d.ts.map +1 -1
- package/dist/cjs/shared/auth.js +133 -112
- package/dist/cjs/shared/auth.js.map +1 -1
- package/dist/cjs/shared/metadataUtils.d.ts +5 -1
- package/dist/cjs/shared/metadataUtils.d.ts.map +1 -1
- package/dist/cjs/shared/metadataUtils.js +2 -5
- package/dist/cjs/shared/metadataUtils.js.map +1 -1
- package/dist/cjs/shared/protocol.d.ts +7 -10
- package/dist/cjs/shared/protocol.d.ts.map +1 -1
- package/dist/cjs/shared/protocol.js +39 -16
- package/dist/cjs/shared/protocol.js.map +1 -1
- package/dist/cjs/shared/toolNameValidation.d.ts +31 -0
- package/dist/cjs/shared/toolNameValidation.d.ts.map +1 -0
- package/dist/cjs/shared/toolNameValidation.js +97 -0
- package/dist/cjs/shared/toolNameValidation.js.map +1 -0
- package/dist/cjs/shared/transport.d.ts +15 -1
- package/dist/cjs/shared/transport.d.ts.map +1 -1
- package/dist/cjs/shared/transport.js +40 -0
- package/dist/cjs/shared/transport.js.map +1 -1
- package/dist/cjs/shared/zodTestMatrix.d.ts +16 -0
- package/dist/cjs/shared/zodTestMatrix.d.ts.map +1 -0
- package/dist/cjs/shared/zodTestMatrix.js +43 -0
- package/dist/cjs/shared/zodTestMatrix.js.map +1 -0
- package/dist/cjs/spec.types.d.ts +823 -261
- package/dist/cjs/spec.types.d.ts.map +1 -1
- package/dist/cjs/spec.types.js +5 -8
- package/dist/cjs/spec.types.js.map +1 -1
- package/dist/cjs/types.d.ts +3828 -59205
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/cjs/types.js +817 -487
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/client/auth.d.ts +11 -1
- package/dist/esm/client/auth.d.ts.map +1 -1
- package/dist/esm/client/auth.js +71 -20
- package/dist/esm/client/auth.js.map +1 -1
- package/dist/esm/client/index.d.ts +252 -1478
- package/dist/esm/client/index.d.ts.map +1 -1
- package/dist/esm/client/index.js +130 -1
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/client/sse.d.ts +1 -0
- package/dist/esm/client/sse.d.ts.map +1 -1
- package/dist/esm/client/sse.js +5 -3
- package/dist/esm/client/sse.js.map +1 -1
- package/dist/esm/client/streamableHttp.d.ts +2 -1
- package/dist/esm/client/streamableHttp.d.ts.map +1 -1
- package/dist/esm/client/streamableHttp.js +35 -15
- package/dist/esm/client/streamableHttp.js.map +1 -1
- package/dist/esm/examples/client/elicitationUrlExample.d.ts +2 -0
- package/dist/esm/examples/client/elicitationUrlExample.d.ts.map +1 -0
- package/dist/esm/examples/client/elicitationUrlExample.js +691 -0
- package/dist/esm/examples/client/elicitationUrlExample.js.map +1 -0
- package/dist/esm/examples/client/simpleOAuthClient.js +12 -51
- package/dist/esm/examples/client/simpleOAuthClient.js.map +1 -1
- package/dist/esm/examples/client/simpleOAuthClientProvider.d.ts +26 -0
- package/dist/esm/examples/client/simpleOAuthClientProvider.d.ts.map +1 -0
- package/dist/esm/examples/client/simpleOAuthClientProvider.js +47 -0
- package/dist/esm/examples/client/simpleOAuthClientProvider.js.map +1 -0
- package/dist/esm/examples/client/simpleStreamableHttp.js +12 -7
- package/dist/esm/examples/client/simpleStreamableHttp.js.map +1 -1
- package/dist/esm/examples/server/demoInMemoryOAuthProvider.d.ts +4 -4
- package/dist/esm/examples/server/demoInMemoryOAuthProvider.d.ts.map +1 -1
- package/dist/esm/examples/server/demoInMemoryOAuthProvider.js +16 -0
- package/dist/esm/examples/server/demoInMemoryOAuthProvider.js.map +1 -1
- package/dist/esm/examples/server/elicitationFormExample.d.ts +2 -0
- package/dist/esm/examples/server/elicitationFormExample.d.ts.map +1 -0
- package/dist/esm/examples/server/{elicitationExample.js → elicitationFormExample.js} +16 -12
- package/dist/esm/examples/server/elicitationFormExample.js.map +1 -0
- package/dist/esm/examples/server/elicitationUrlExample.d.ts +2 -0
- package/dist/esm/examples/server/elicitationUrlExample.d.ts.map +1 -0
- package/dist/esm/examples/server/elicitationUrlExample.js +650 -0
- package/dist/esm/examples/server/elicitationUrlExample.js.map +1 -0
- package/dist/esm/examples/server/jsonResponseStreamableHttp.js +1 -1
- package/dist/esm/examples/server/jsonResponseStreamableHttp.js.map +1 -1
- package/dist/esm/examples/server/mcpServerOutputSchema.js +1 -1
- package/dist/esm/examples/server/mcpServerOutputSchema.js.map +1 -1
- package/dist/esm/examples/server/simpleSseServer.js +1 -1
- package/dist/esm/examples/server/simpleSseServer.js.map +1 -1
- package/dist/esm/examples/server/simpleStatelessStreamableHttp.js +1 -1
- package/dist/esm/examples/server/simpleStatelessStreamableHttp.js.map +1 -1
- package/dist/esm/examples/server/simpleStreamableHttp.js +4 -3
- package/dist/esm/examples/server/simpleStreamableHttp.js.map +1 -1
- package/dist/esm/examples/server/sseAndStreamableHttpCompatibleServer.js +1 -1
- package/dist/esm/examples/server/sseAndStreamableHttpCompatibleServer.js.map +1 -1
- package/dist/esm/examples/server/toolWithSampleServer.js +6 -7
- package/dist/esm/examples/server/toolWithSampleServer.js.map +1 -1
- package/dist/esm/server/auth/handlers/authorize.js +1 -1
- package/dist/esm/server/auth/handlers/authorize.js.map +1 -1
- package/dist/esm/server/auth/handlers/token.js +1 -1
- package/dist/esm/server/auth/handlers/token.js.map +1 -1
- package/dist/esm/server/auth/middleware/bearerAuth.d.ts.map +1 -1
- package/dist/esm/server/auth/middleware/bearerAuth.js +13 -8
- package/dist/esm/server/auth/middleware/bearerAuth.js.map +1 -1
- package/dist/esm/server/auth/middleware/clientAuth.js +1 -1
- package/dist/esm/server/auth/middleware/clientAuth.js.map +1 -1
- package/dist/esm/server/auth/router.js +1 -1
- package/dist/esm/server/auth/router.js.map +1 -1
- package/dist/esm/server/completable.d.ts +30 -16
- package/dist/esm/server/completable.d.ts.map +1 -1
- package/dist/esm/server/completable.js +34 -53
- package/dist/esm/server/completable.js.map +1 -1
- package/dist/esm/server/index.d.ts +213 -71
- package/dist/esm/server/index.d.ts.map +1 -1
- package/dist/esm/server/index.js +61 -16
- package/dist/esm/server/index.js.map +1 -1
- package/dist/esm/server/mcp.d.ts +14 -16
- package/dist/esm/server/mcp.d.ts.map +1 -1
- package/dist/esm/server/mcp.js +107 -43
- package/dist/esm/server/mcp.js.map +1 -1
- package/dist/esm/server/zod-compat.d.ts +82 -0
- package/dist/esm/server/zod-compat.d.ts.map +1 -0
- package/dist/esm/server/zod-compat.js +217 -0
- package/dist/esm/server/zod-compat.js.map +1 -0
- package/dist/esm/server/zod-json-schema-compat.d.ts +12 -0
- package/dist/esm/server/zod-json-schema-compat.d.ts.map +1 -0
- package/dist/esm/server/zod-json-schema-compat.js +52 -0
- package/dist/esm/server/zod-json-schema-compat.js.map +1 -0
- package/dist/esm/shared/auth.d.ts +116 -502
- package/dist/esm/shared/auth.d.ts.map +1 -1
- package/dist/esm/shared/auth.js +17 -19
- package/dist/esm/shared/auth.js.map +1 -1
- package/dist/esm/shared/metadataUtils.d.ts +5 -1
- package/dist/esm/shared/metadataUtils.d.ts.map +1 -1
- package/dist/esm/shared/metadataUtils.js +2 -5
- package/dist/esm/shared/metadataUtils.js.map +1 -1
- package/dist/esm/shared/protocol.d.ts +7 -10
- package/dist/esm/shared/protocol.d.ts.map +1 -1
- package/dist/esm/shared/protocol.js +39 -16
- package/dist/esm/shared/protocol.js.map +1 -1
- package/dist/esm/shared/toolNameValidation.d.ts +31 -0
- package/dist/esm/shared/toolNameValidation.d.ts.map +1 -0
- package/dist/esm/shared/toolNameValidation.js +92 -0
- package/dist/esm/shared/toolNameValidation.js.map +1 -0
- package/dist/esm/shared/transport.d.ts +15 -1
- package/dist/esm/shared/transport.d.ts.map +1 -1
- package/dist/esm/shared/transport.js +38 -1
- package/dist/esm/shared/transport.js.map +1 -1
- package/dist/esm/shared/zodTestMatrix.d.ts +16 -0
- package/dist/esm/shared/zodTestMatrix.d.ts.map +1 -0
- package/dist/esm/shared/zodTestMatrix.js +17 -0
- package/dist/esm/shared/zodTestMatrix.js.map +1 -0
- package/dist/esm/spec.types.d.ts +823 -261
- package/dist/esm/spec.types.d.ts.map +1 -1
- package/dist/esm/spec.types.js +4 -7
- package/dist/esm/spec.types.js.map +1 -1
- package/dist/esm/types.d.ts +3828 -59205
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js +664 -360
- package/dist/esm/types.js.map +1 -1
- package/package.json +13 -12
- package/dist/cjs/examples/server/elicitationExample.d.ts +0 -2
- package/dist/cjs/examples/server/elicitationExample.d.ts.map +0 -1
- package/dist/cjs/examples/server/elicitationExample.js.map +0 -1
- package/dist/esm/examples/server/elicitationExample.d.ts +0 -2
- package/dist/esm/examples/server/elicitationExample.d.ts.map +0 -1
- package/dist/esm/examples/server/elicitationExample.js.map +0 -1
package/dist/esm/types.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as z from 'zod/v4';
|
|
2
2
|
export const LATEST_PROTOCOL_VERSION = '2025-06-18';
|
|
3
3
|
export const DEFAULT_NEGOTIATED_PROTOCOL_VERSION = '2025-03-26';
|
|
4
4
|
export const SUPPORTED_PROTOCOL_VERSIONS = [LATEST_PROTOCOL_VERSION, '2025-03-26', '2024-11-05', '2024-10-07'];
|
|
5
5
|
/* JSON-RPC types */
|
|
6
6
|
export const JSONRPC_VERSION = '2.0';
|
|
7
|
+
/**
|
|
8
|
+
* Assert 'object' type schema.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
const AssertObjectSchema = z.custom((v) => v !== null && (typeof v === 'object' || typeof v === 'function'));
|
|
7
13
|
/**
|
|
8
14
|
* A progress token, used to associate progress notifications with the original request.
|
|
9
15
|
*/
|
|
@@ -12,45 +18,43 @@ export const ProgressTokenSchema = z.union([z.string(), z.number().int()]);
|
|
|
12
18
|
* An opaque token used to represent a cursor for pagination.
|
|
13
19
|
*/
|
|
14
20
|
export const CursorSchema = z.string();
|
|
15
|
-
const RequestMetaSchema = z
|
|
16
|
-
.object({
|
|
21
|
+
const RequestMetaSchema = z.looseObject({
|
|
17
22
|
/**
|
|
18
23
|
* If specified, the caller is requesting out-of-band progress notifications for this request (as represented by notifications/progress). The value of this parameter is an opaque token that will be attached to any subsequent notifications. The receiver is not obligated to provide these notifications.
|
|
19
24
|
*/
|
|
20
|
-
progressToken:
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
progressToken: ProgressTokenSchema.optional()
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* Common params for any request.
|
|
29
|
+
*/
|
|
30
|
+
const BaseRequestParamsSchema = z.looseObject({
|
|
31
|
+
/**
|
|
32
|
+
* See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage.
|
|
33
|
+
*/
|
|
34
|
+
_meta: RequestMetaSchema.optional()
|
|
35
|
+
});
|
|
28
36
|
export const RequestSchema = z.object({
|
|
29
37
|
method: z.string(),
|
|
30
|
-
params:
|
|
38
|
+
params: BaseRequestParamsSchema.optional()
|
|
31
39
|
});
|
|
32
|
-
const
|
|
33
|
-
.object({
|
|
40
|
+
const NotificationsParamsSchema = z.looseObject({
|
|
34
41
|
/**
|
|
35
42
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
36
43
|
* for notes on _meta usage.
|
|
37
44
|
*/
|
|
38
|
-
_meta: z.
|
|
39
|
-
})
|
|
40
|
-
.passthrough();
|
|
45
|
+
_meta: z.record(z.string(), z.unknown()).optional()
|
|
46
|
+
});
|
|
41
47
|
export const NotificationSchema = z.object({
|
|
42
48
|
method: z.string(),
|
|
43
|
-
params:
|
|
49
|
+
params: NotificationsParamsSchema.optional()
|
|
44
50
|
});
|
|
45
|
-
export const ResultSchema = z
|
|
46
|
-
.object({
|
|
51
|
+
export const ResultSchema = z.looseObject({
|
|
47
52
|
/**
|
|
48
53
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
49
54
|
* for notes on _meta usage.
|
|
50
55
|
*/
|
|
51
|
-
_meta: z.
|
|
52
|
-
})
|
|
53
|
-
.passthrough();
|
|
56
|
+
_meta: z.record(z.string(), z.unknown()).optional()
|
|
57
|
+
});
|
|
54
58
|
/**
|
|
55
59
|
* A uniquely identifying ID for a request in JSON-RPC.
|
|
56
60
|
*/
|
|
@@ -61,9 +65,9 @@ export const RequestIdSchema = z.union([z.string(), z.number().int()]);
|
|
|
61
65
|
export const JSONRPCRequestSchema = z
|
|
62
66
|
.object({
|
|
63
67
|
jsonrpc: z.literal(JSONRPC_VERSION),
|
|
64
|
-
id: RequestIdSchema
|
|
68
|
+
id: RequestIdSchema,
|
|
69
|
+
...RequestSchema.shape
|
|
65
70
|
})
|
|
66
|
-
.merge(RequestSchema)
|
|
67
71
|
.strict();
|
|
68
72
|
export const isJSONRPCRequest = (value) => JSONRPCRequestSchema.safeParse(value).success;
|
|
69
73
|
/**
|
|
@@ -71,9 +75,9 @@ export const isJSONRPCRequest = (value) => JSONRPCRequestSchema.safeParse(value)
|
|
|
71
75
|
*/
|
|
72
76
|
export const JSONRPCNotificationSchema = z
|
|
73
77
|
.object({
|
|
74
|
-
jsonrpc: z.literal(JSONRPC_VERSION)
|
|
78
|
+
jsonrpc: z.literal(JSONRPC_VERSION),
|
|
79
|
+
...NotificationSchema.shape
|
|
75
80
|
})
|
|
76
|
-
.merge(NotificationSchema)
|
|
77
81
|
.strict();
|
|
78
82
|
export const isJSONRPCNotification = (value) => JSONRPCNotificationSchema.safeParse(value).success;
|
|
79
83
|
/**
|
|
@@ -101,6 +105,8 @@ export var ErrorCode;
|
|
|
101
105
|
ErrorCode[ErrorCode["MethodNotFound"] = -32601] = "MethodNotFound";
|
|
102
106
|
ErrorCode[ErrorCode["InvalidParams"] = -32602] = "InvalidParams";
|
|
103
107
|
ErrorCode[ErrorCode["InternalError"] = -32603] = "InternalError";
|
|
108
|
+
// MCP-specific error codes
|
|
109
|
+
ErrorCode[ErrorCode["UrlElicitationRequired"] = -32042] = "UrlElicitationRequired";
|
|
104
110
|
})(ErrorCode || (ErrorCode = {}));
|
|
105
111
|
/**
|
|
106
112
|
* A response to a request that indicates an error occurred.
|
|
@@ -132,6 +138,18 @@ export const JSONRPCMessageSchema = z.union([JSONRPCRequestSchema, JSONRPCNotifi
|
|
|
132
138
|
* A response that indicates success but carries no data.
|
|
133
139
|
*/
|
|
134
140
|
export const EmptyResultSchema = ResultSchema.strict();
|
|
141
|
+
export const CancelledNotificationParamsSchema = NotificationsParamsSchema.extend({
|
|
142
|
+
/**
|
|
143
|
+
* The ID of the request to cancel.
|
|
144
|
+
*
|
|
145
|
+
* This MUST correspond to the ID of a request previously issued in the same direction.
|
|
146
|
+
*/
|
|
147
|
+
requestId: RequestIdSchema,
|
|
148
|
+
/**
|
|
149
|
+
* An optional string describing the reason for the cancellation. This MAY be logged or presented to the user.
|
|
150
|
+
*/
|
|
151
|
+
reason: z.string().optional()
|
|
152
|
+
});
|
|
135
153
|
/* Cancellation */
|
|
136
154
|
/**
|
|
137
155
|
* This notification can be sent by either side to indicate that it is cancelling a previously-issued request.
|
|
@@ -144,25 +162,13 @@ export const EmptyResultSchema = ResultSchema.strict();
|
|
|
144
162
|
*/
|
|
145
163
|
export const CancelledNotificationSchema = NotificationSchema.extend({
|
|
146
164
|
method: z.literal('notifications/cancelled'),
|
|
147
|
-
params:
|
|
148
|
-
/**
|
|
149
|
-
* The ID of the request to cancel.
|
|
150
|
-
*
|
|
151
|
-
* This MUST correspond to the ID of a request previously issued in the same direction.
|
|
152
|
-
*/
|
|
153
|
-
requestId: RequestIdSchema,
|
|
154
|
-
/**
|
|
155
|
-
* An optional string describing the reason for the cancellation. This MAY be logged or presented to the user.
|
|
156
|
-
*/
|
|
157
|
-
reason: z.string().optional()
|
|
158
|
-
})
|
|
165
|
+
params: CancelledNotificationParamsSchema
|
|
159
166
|
});
|
|
160
167
|
/* Base Metadata */
|
|
161
168
|
/**
|
|
162
169
|
* Icon schema for use in tools, prompts, resources, and implementations.
|
|
163
170
|
*/
|
|
164
|
-
export const IconSchema = z
|
|
165
|
-
.object({
|
|
171
|
+
export const IconSchema = z.object({
|
|
166
172
|
/**
|
|
167
173
|
* URL or data URI for the icon.
|
|
168
174
|
*/
|
|
@@ -170,22 +176,20 @@ export const IconSchema = z
|
|
|
170
176
|
/**
|
|
171
177
|
* Optional MIME type for the icon.
|
|
172
178
|
*/
|
|
173
|
-
mimeType: z.
|
|
179
|
+
mimeType: z.string().optional(),
|
|
174
180
|
/**
|
|
175
181
|
* Optional array of strings that specify sizes at which the icon can be used.
|
|
176
182
|
* Each string should be in WxH format (e.g., `"48x48"`, `"96x96"`) or `"any"` for scalable formats like SVG.
|
|
177
183
|
*
|
|
178
184
|
* If not provided, the client should assume that the icon can be used at any size.
|
|
179
185
|
*/
|
|
180
|
-
sizes: z.
|
|
181
|
-
})
|
|
182
|
-
.passthrough();
|
|
186
|
+
sizes: z.array(z.string()).optional()
|
|
187
|
+
});
|
|
183
188
|
/**
|
|
184
189
|
* Base schema to add `icons` property.
|
|
185
190
|
*
|
|
186
191
|
*/
|
|
187
|
-
export const IconsSchema = z
|
|
188
|
-
.object({
|
|
192
|
+
export const IconsSchema = z.object({
|
|
189
193
|
/**
|
|
190
194
|
* Optional set of sized icons that the client can display in a user interface.
|
|
191
195
|
*
|
|
@@ -198,13 +202,11 @@ export const IconsSchema = z
|
|
|
198
202
|
* - `image/webp` - WebP images (modern, efficient format)
|
|
199
203
|
*/
|
|
200
204
|
icons: z.array(IconSchema).optional()
|
|
201
|
-
})
|
|
202
|
-
.passthrough();
|
|
205
|
+
});
|
|
203
206
|
/**
|
|
204
207
|
* Base metadata interface for common properties across resources, tools, prompts, and implementations.
|
|
205
208
|
*/
|
|
206
|
-
export const BaseMetadataSchema = z
|
|
207
|
-
.object({
|
|
209
|
+
export const BaseMetadataSchema = z.object({
|
|
208
210
|
/** Intended for programmatic or logical use, but used as a display name in past specs or fallback */
|
|
209
211
|
name: z.string(),
|
|
210
212
|
/**
|
|
@@ -215,121 +217,143 @@ export const BaseMetadataSchema = z
|
|
|
215
217
|
* where `annotations.title` should be given precedence over using `name`,
|
|
216
218
|
* if present).
|
|
217
219
|
*/
|
|
218
|
-
title: z.
|
|
219
|
-
})
|
|
220
|
-
.passthrough();
|
|
220
|
+
title: z.string().optional()
|
|
221
|
+
});
|
|
221
222
|
/* Initialization */
|
|
222
223
|
/**
|
|
223
224
|
* Describes the name and version of an MCP implementation.
|
|
224
225
|
*/
|
|
225
226
|
export const ImplementationSchema = BaseMetadataSchema.extend({
|
|
227
|
+
...BaseMetadataSchema.shape,
|
|
228
|
+
...IconsSchema.shape,
|
|
226
229
|
version: z.string(),
|
|
227
230
|
/**
|
|
228
231
|
* An optional URL of the website for this implementation.
|
|
229
232
|
*/
|
|
230
|
-
websiteUrl: z.
|
|
231
|
-
})
|
|
233
|
+
websiteUrl: z.string().optional()
|
|
234
|
+
});
|
|
235
|
+
const FormElicitationCapabilitySchema = z.intersection(z.object({
|
|
236
|
+
applyDefaults: z.boolean().optional()
|
|
237
|
+
}), z.record(z.string(), z.unknown()));
|
|
238
|
+
const ElicitationCapabilitySchema = z.preprocess(value => {
|
|
239
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
240
|
+
if (Object.keys(value).length === 0) {
|
|
241
|
+
return { form: {} };
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return value;
|
|
245
|
+
}, z.intersection(z.object({
|
|
246
|
+
form: FormElicitationCapabilitySchema.optional(),
|
|
247
|
+
url: AssertObjectSchema.optional()
|
|
248
|
+
}), z.record(z.string(), z.unknown()).optional()));
|
|
232
249
|
/**
|
|
233
250
|
* Capabilities a client may support. Known capabilities are defined here, in this schema, but this is not a closed set: any client can define its own, additional capabilities.
|
|
234
251
|
*/
|
|
235
|
-
export const ClientCapabilitiesSchema = z
|
|
236
|
-
.object({
|
|
252
|
+
export const ClientCapabilitiesSchema = z.object({
|
|
237
253
|
/**
|
|
238
254
|
* Experimental, non-standard capabilities that the client supports.
|
|
239
255
|
*/
|
|
240
|
-
experimental: z.
|
|
256
|
+
experimental: z.record(z.string(), AssertObjectSchema).optional(),
|
|
241
257
|
/**
|
|
242
258
|
* Present if the client supports sampling from an LLM.
|
|
243
259
|
*/
|
|
244
|
-
sampling: z
|
|
260
|
+
sampling: z
|
|
261
|
+
.object({
|
|
262
|
+
/**
|
|
263
|
+
* Present if the client supports context inclusion via includeContext parameter.
|
|
264
|
+
* If not declared, servers SHOULD only use `includeContext: "none"` (or omit it).
|
|
265
|
+
*/
|
|
266
|
+
context: AssertObjectSchema.optional(),
|
|
267
|
+
/**
|
|
268
|
+
* Present if the client supports tool use via tools and toolChoice parameters.
|
|
269
|
+
*/
|
|
270
|
+
tools: AssertObjectSchema.optional()
|
|
271
|
+
})
|
|
272
|
+
.optional(),
|
|
245
273
|
/**
|
|
246
274
|
* Present if the client supports eliciting user input.
|
|
247
275
|
*/
|
|
248
|
-
elicitation:
|
|
276
|
+
elicitation: ElicitationCapabilitySchema.optional(),
|
|
249
277
|
/**
|
|
250
278
|
* Present if the client supports listing roots.
|
|
251
279
|
*/
|
|
252
|
-
roots: z
|
|
280
|
+
roots: z
|
|
253
281
|
.object({
|
|
254
282
|
/**
|
|
255
283
|
* Whether the client supports issuing notifications for changes to the roots list.
|
|
256
284
|
*/
|
|
257
|
-
listChanged: z.
|
|
285
|
+
listChanged: z.boolean().optional()
|
|
258
286
|
})
|
|
259
|
-
.
|
|
260
|
-
})
|
|
261
|
-
|
|
287
|
+
.optional()
|
|
288
|
+
});
|
|
289
|
+
export const InitializeRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
290
|
+
/**
|
|
291
|
+
* The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well.
|
|
292
|
+
*/
|
|
293
|
+
protocolVersion: z.string(),
|
|
294
|
+
capabilities: ClientCapabilitiesSchema,
|
|
295
|
+
clientInfo: ImplementationSchema
|
|
296
|
+
});
|
|
262
297
|
/**
|
|
263
298
|
* This request is sent from the client to the server when it first connects, asking it to begin initialization.
|
|
264
299
|
*/
|
|
265
300
|
export const InitializeRequestSchema = RequestSchema.extend({
|
|
266
301
|
method: z.literal('initialize'),
|
|
267
|
-
params:
|
|
268
|
-
/**
|
|
269
|
-
* The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well.
|
|
270
|
-
*/
|
|
271
|
-
protocolVersion: z.string(),
|
|
272
|
-
capabilities: ClientCapabilitiesSchema,
|
|
273
|
-
clientInfo: ImplementationSchema
|
|
274
|
-
})
|
|
302
|
+
params: InitializeRequestParamsSchema
|
|
275
303
|
});
|
|
276
304
|
export const isInitializeRequest = (value) => InitializeRequestSchema.safeParse(value).success;
|
|
277
305
|
/**
|
|
278
306
|
* Capabilities that a server may support. Known capabilities are defined here, in this schema, but this is not a closed set: any server can define its own, additional capabilities.
|
|
279
307
|
*/
|
|
280
|
-
export const ServerCapabilitiesSchema = z
|
|
281
|
-
.object({
|
|
308
|
+
export const ServerCapabilitiesSchema = z.object({
|
|
282
309
|
/**
|
|
283
310
|
* Experimental, non-standard capabilities that the server supports.
|
|
284
311
|
*/
|
|
285
|
-
experimental: z.
|
|
312
|
+
experimental: z.record(z.string(), AssertObjectSchema).optional(),
|
|
286
313
|
/**
|
|
287
314
|
* Present if the server supports sending log messages to the client.
|
|
288
315
|
*/
|
|
289
|
-
logging:
|
|
316
|
+
logging: AssertObjectSchema.optional(),
|
|
290
317
|
/**
|
|
291
318
|
* Present if the server supports sending completions to the client.
|
|
292
319
|
*/
|
|
293
|
-
completions:
|
|
320
|
+
completions: AssertObjectSchema.optional(),
|
|
294
321
|
/**
|
|
295
322
|
* Present if the server offers any prompt templates.
|
|
296
323
|
*/
|
|
297
|
-
prompts: z.optional(z
|
|
298
|
-
.object({
|
|
324
|
+
prompts: z.optional(z.object({
|
|
299
325
|
/**
|
|
300
326
|
* Whether this server supports issuing notifications for changes to the prompt list.
|
|
301
327
|
*/
|
|
302
328
|
listChanged: z.optional(z.boolean())
|
|
303
|
-
})
|
|
304
|
-
.passthrough()),
|
|
329
|
+
})),
|
|
305
330
|
/**
|
|
306
331
|
* Present if the server offers any resources to read.
|
|
307
332
|
*/
|
|
308
|
-
resources: z
|
|
333
|
+
resources: z
|
|
309
334
|
.object({
|
|
310
335
|
/**
|
|
311
336
|
* Whether this server supports clients subscribing to resource updates.
|
|
312
337
|
*/
|
|
313
|
-
subscribe: z.
|
|
338
|
+
subscribe: z.boolean().optional(),
|
|
314
339
|
/**
|
|
315
340
|
* Whether this server supports issuing notifications for changes to the resource list.
|
|
316
341
|
*/
|
|
317
|
-
listChanged: z.
|
|
342
|
+
listChanged: z.boolean().optional()
|
|
318
343
|
})
|
|
319
|
-
.
|
|
344
|
+
.optional(),
|
|
320
345
|
/**
|
|
321
346
|
* Present if the server offers any tools to call.
|
|
322
347
|
*/
|
|
323
|
-
tools: z
|
|
348
|
+
tools: z
|
|
324
349
|
.object({
|
|
325
350
|
/**
|
|
326
351
|
* Whether this server supports issuing notifications for changes to the tool list.
|
|
327
352
|
*/
|
|
328
|
-
listChanged: z.
|
|
353
|
+
listChanged: z.boolean().optional()
|
|
329
354
|
})
|
|
330
|
-
.
|
|
331
|
-
})
|
|
332
|
-
.passthrough();
|
|
355
|
+
.optional()
|
|
356
|
+
});
|
|
333
357
|
/**
|
|
334
358
|
* After receiving an initialize request from the client, the server sends this response.
|
|
335
359
|
*/
|
|
@@ -345,7 +369,7 @@ export const InitializeResultSchema = ResultSchema.extend({
|
|
|
345
369
|
*
|
|
346
370
|
* This can be used by clients to improve the LLM's understanding of available tools, resources, etc. It can be thought of like a "hint" to the model. For example, this information MAY be added to the system prompt.
|
|
347
371
|
*/
|
|
348
|
-
instructions: z.
|
|
372
|
+
instructions: z.string().optional()
|
|
349
373
|
});
|
|
350
374
|
/**
|
|
351
375
|
* This notification is sent from the client to the server after initialization has finished.
|
|
@@ -362,8 +386,7 @@ export const PingRequestSchema = RequestSchema.extend({
|
|
|
362
386
|
method: z.literal('ping')
|
|
363
387
|
});
|
|
364
388
|
/* Progress notifications */
|
|
365
|
-
export const ProgressSchema = z
|
|
366
|
-
.object({
|
|
389
|
+
export const ProgressSchema = z.object({
|
|
367
390
|
/**
|
|
368
391
|
* The progress thus far. This should increase every time progress is made, even if the total is unknown.
|
|
369
392
|
*/
|
|
@@ -376,29 +399,34 @@ export const ProgressSchema = z
|
|
|
376
399
|
* An optional message describing the current progress.
|
|
377
400
|
*/
|
|
378
401
|
message: z.optional(z.string())
|
|
379
|
-
})
|
|
380
|
-
|
|
402
|
+
});
|
|
403
|
+
export const ProgressNotificationParamsSchema = z.object({
|
|
404
|
+
...NotificationsParamsSchema.shape,
|
|
405
|
+
...ProgressSchema.shape,
|
|
406
|
+
/**
|
|
407
|
+
* The progress token which was given in the initial request, used to associate this notification with the request that is proceeding.
|
|
408
|
+
*/
|
|
409
|
+
progressToken: ProgressTokenSchema
|
|
410
|
+
});
|
|
381
411
|
/**
|
|
382
412
|
* An out-of-band notification used to inform the receiver of a progress update for a long-running request.
|
|
413
|
+
*
|
|
414
|
+
* @category notifications/progress
|
|
383
415
|
*/
|
|
384
416
|
export const ProgressNotificationSchema = NotificationSchema.extend({
|
|
385
417
|
method: z.literal('notifications/progress'),
|
|
386
|
-
params:
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
418
|
+
params: ProgressNotificationParamsSchema
|
|
419
|
+
});
|
|
420
|
+
export const PaginatedRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
421
|
+
/**
|
|
422
|
+
* An opaque token representing the current pagination position.
|
|
423
|
+
* If provided, the server should return results starting after this cursor.
|
|
424
|
+
*/
|
|
425
|
+
cursor: CursorSchema.optional()
|
|
392
426
|
});
|
|
393
427
|
/* Pagination */
|
|
394
428
|
export const PaginatedRequestSchema = RequestSchema.extend({
|
|
395
|
-
params:
|
|
396
|
-
/**
|
|
397
|
-
* An opaque token representing the current pagination position.
|
|
398
|
-
* If provided, the server should return results starting after this cursor.
|
|
399
|
-
*/
|
|
400
|
-
cursor: z.optional(CursorSchema)
|
|
401
|
-
}).optional()
|
|
429
|
+
params: PaginatedRequestParamsSchema.optional()
|
|
402
430
|
});
|
|
403
431
|
export const PaginatedResultSchema = ResultSchema.extend({
|
|
404
432
|
/**
|
|
@@ -411,8 +439,7 @@ export const PaginatedResultSchema = ResultSchema.extend({
|
|
|
411
439
|
/**
|
|
412
440
|
* The contents of a specific resource or sub-resource.
|
|
413
441
|
*/
|
|
414
|
-
export const ResourceContentsSchema = z
|
|
415
|
-
.object({
|
|
442
|
+
export const ResourceContentsSchema = z.object({
|
|
416
443
|
/**
|
|
417
444
|
* The URI of this resource.
|
|
418
445
|
*/
|
|
@@ -425,9 +452,8 @@ export const ResourceContentsSchema = z
|
|
|
425
452
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
426
453
|
* for notes on _meta usage.
|
|
427
454
|
*/
|
|
428
|
-
_meta: z.
|
|
429
|
-
})
|
|
430
|
-
.passthrough();
|
|
455
|
+
_meta: z.record(z.string(), z.unknown()).optional()
|
|
456
|
+
});
|
|
431
457
|
export const TextResourceContentsSchema = ResourceContentsSchema.extend({
|
|
432
458
|
/**
|
|
433
459
|
* The text of the item. This must only be set if the item can actually be represented as text (not binary data).
|
|
@@ -459,7 +485,9 @@ export const BlobResourceContentsSchema = ResourceContentsSchema.extend({
|
|
|
459
485
|
/**
|
|
460
486
|
* A known resource that the server is capable of reading.
|
|
461
487
|
*/
|
|
462
|
-
export const ResourceSchema =
|
|
488
|
+
export const ResourceSchema = z.object({
|
|
489
|
+
...BaseMetadataSchema.shape,
|
|
490
|
+
...IconsSchema.shape,
|
|
463
491
|
/**
|
|
464
492
|
* The URI of this resource.
|
|
465
493
|
*/
|
|
@@ -478,12 +506,14 @@ export const ResourceSchema = BaseMetadataSchema.extend({
|
|
|
478
506
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
479
507
|
* for notes on _meta usage.
|
|
480
508
|
*/
|
|
481
|
-
_meta: z.optional(z.
|
|
482
|
-
})
|
|
509
|
+
_meta: z.optional(z.looseObject({}))
|
|
510
|
+
});
|
|
483
511
|
/**
|
|
484
512
|
* A template description for resources available on the server.
|
|
485
513
|
*/
|
|
486
|
-
export const ResourceTemplateSchema =
|
|
514
|
+
export const ResourceTemplateSchema = z.object({
|
|
515
|
+
...BaseMetadataSchema.shape,
|
|
516
|
+
...IconsSchema.shape,
|
|
487
517
|
/**
|
|
488
518
|
* A URI template (according to RFC 6570) that can be used to construct resource URIs.
|
|
489
519
|
*/
|
|
@@ -502,8 +532,8 @@ export const ResourceTemplateSchema = BaseMetadataSchema.extend({
|
|
|
502
532
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
503
533
|
* for notes on _meta usage.
|
|
504
534
|
*/
|
|
505
|
-
_meta: z.optional(z.
|
|
506
|
-
})
|
|
535
|
+
_meta: z.optional(z.looseObject({}))
|
|
536
|
+
});
|
|
507
537
|
/**
|
|
508
538
|
* Sent from the client to request a list of resources the server has.
|
|
509
539
|
*/
|
|
@@ -528,17 +558,24 @@ export const ListResourceTemplatesRequestSchema = PaginatedRequestSchema.extend(
|
|
|
528
558
|
export const ListResourceTemplatesResultSchema = PaginatedResultSchema.extend({
|
|
529
559
|
resourceTemplates: z.array(ResourceTemplateSchema)
|
|
530
560
|
});
|
|
561
|
+
export const ResourceRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
562
|
+
/**
|
|
563
|
+
* The URI of the resource to read. The URI can use any protocol; it is up to the server how to interpret it.
|
|
564
|
+
*
|
|
565
|
+
* @format uri
|
|
566
|
+
*/
|
|
567
|
+
uri: z.string()
|
|
568
|
+
});
|
|
569
|
+
/**
|
|
570
|
+
* Parameters for a `resources/read` request.
|
|
571
|
+
*/
|
|
572
|
+
export const ReadResourceRequestParamsSchema = ResourceRequestParamsSchema;
|
|
531
573
|
/**
|
|
532
574
|
* Sent from the client to the server, to read a specific resource URI.
|
|
533
575
|
*/
|
|
534
576
|
export const ReadResourceRequestSchema = RequestSchema.extend({
|
|
535
577
|
method: z.literal('resources/read'),
|
|
536
|
-
params:
|
|
537
|
-
/**
|
|
538
|
-
* The URI of the resource to read. The URI can use any protocol; it is up to the server how to interpret it.
|
|
539
|
-
*/
|
|
540
|
-
uri: z.string()
|
|
541
|
-
})
|
|
578
|
+
params: ReadResourceRequestParamsSchema
|
|
542
579
|
});
|
|
543
580
|
/**
|
|
544
581
|
* The server's response to a resources/read request from the client.
|
|
@@ -552,48 +589,43 @@ export const ReadResourceResultSchema = ResultSchema.extend({
|
|
|
552
589
|
export const ResourceListChangedNotificationSchema = NotificationSchema.extend({
|
|
553
590
|
method: z.literal('notifications/resources/list_changed')
|
|
554
591
|
});
|
|
592
|
+
export const SubscribeRequestParamsSchema = ResourceRequestParamsSchema;
|
|
555
593
|
/**
|
|
556
594
|
* Sent from the client to request resources/updated notifications from the server whenever a particular resource changes.
|
|
557
595
|
*/
|
|
558
596
|
export const SubscribeRequestSchema = RequestSchema.extend({
|
|
559
597
|
method: z.literal('resources/subscribe'),
|
|
560
|
-
params:
|
|
561
|
-
/**
|
|
562
|
-
* The URI of the resource to subscribe to. The URI can use any protocol; it is up to the server how to interpret it.
|
|
563
|
-
*/
|
|
564
|
-
uri: z.string()
|
|
565
|
-
})
|
|
598
|
+
params: SubscribeRequestParamsSchema
|
|
566
599
|
});
|
|
600
|
+
export const UnsubscribeRequestParamsSchema = ResourceRequestParamsSchema;
|
|
567
601
|
/**
|
|
568
602
|
* Sent from the client to request cancellation of resources/updated notifications from the server. This should follow a previous resources/subscribe request.
|
|
569
603
|
*/
|
|
570
604
|
export const UnsubscribeRequestSchema = RequestSchema.extend({
|
|
571
605
|
method: z.literal('resources/unsubscribe'),
|
|
572
|
-
params:
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
606
|
+
params: UnsubscribeRequestParamsSchema
|
|
607
|
+
});
|
|
608
|
+
/**
|
|
609
|
+
* Parameters for a `notifications/resources/updated` notification.
|
|
610
|
+
*/
|
|
611
|
+
export const ResourceUpdatedNotificationParamsSchema = NotificationsParamsSchema.extend({
|
|
612
|
+
/**
|
|
613
|
+
* The URI of the resource that has been updated. This might be a sub-resource of the one that the client actually subscribed to.
|
|
614
|
+
*/
|
|
615
|
+
uri: z.string()
|
|
578
616
|
});
|
|
579
617
|
/**
|
|
580
618
|
* A notification from the server to the client, informing it that a resource has changed and may need to be read again. This should only be sent if the client previously sent a resources/subscribe request.
|
|
581
619
|
*/
|
|
582
620
|
export const ResourceUpdatedNotificationSchema = NotificationSchema.extend({
|
|
583
621
|
method: z.literal('notifications/resources/updated'),
|
|
584
|
-
params:
|
|
585
|
-
/**
|
|
586
|
-
* The URI of the resource that has been updated. This might be a sub-resource of the one that the client actually subscribed to.
|
|
587
|
-
*/
|
|
588
|
-
uri: z.string()
|
|
589
|
-
})
|
|
622
|
+
params: ResourceUpdatedNotificationParamsSchema
|
|
590
623
|
});
|
|
591
624
|
/* Prompts */
|
|
592
625
|
/**
|
|
593
626
|
* Describes an argument that a prompt can accept.
|
|
594
627
|
*/
|
|
595
|
-
export const PromptArgumentSchema = z
|
|
596
|
-
.object({
|
|
628
|
+
export const PromptArgumentSchema = z.object({
|
|
597
629
|
/**
|
|
598
630
|
* The name of the argument.
|
|
599
631
|
*/
|
|
@@ -606,12 +638,13 @@ export const PromptArgumentSchema = z
|
|
|
606
638
|
* Whether this argument must be provided.
|
|
607
639
|
*/
|
|
608
640
|
required: z.optional(z.boolean())
|
|
609
|
-
})
|
|
610
|
-
.passthrough();
|
|
641
|
+
});
|
|
611
642
|
/**
|
|
612
643
|
* A prompt or prompt template that the server offers.
|
|
613
644
|
*/
|
|
614
|
-
export const PromptSchema =
|
|
645
|
+
export const PromptSchema = z.object({
|
|
646
|
+
...BaseMetadataSchema.shape,
|
|
647
|
+
...IconsSchema.shape,
|
|
615
648
|
/**
|
|
616
649
|
* An optional description of what this prompt provides
|
|
617
650
|
*/
|
|
@@ -624,8 +657,8 @@ export const PromptSchema = BaseMetadataSchema.extend({
|
|
|
624
657
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
625
658
|
* for notes on _meta usage.
|
|
626
659
|
*/
|
|
627
|
-
_meta: z.optional(z.
|
|
628
|
-
})
|
|
660
|
+
_meta: z.optional(z.looseObject({}))
|
|
661
|
+
});
|
|
629
662
|
/**
|
|
630
663
|
* Sent from the client to request a list of prompts and prompt templates the server has.
|
|
631
664
|
*/
|
|
@@ -638,27 +671,30 @@ export const ListPromptsRequestSchema = PaginatedRequestSchema.extend({
|
|
|
638
671
|
export const ListPromptsResultSchema = PaginatedResultSchema.extend({
|
|
639
672
|
prompts: z.array(PromptSchema)
|
|
640
673
|
});
|
|
674
|
+
/**
|
|
675
|
+
* Parameters for a `prompts/get` request.
|
|
676
|
+
*/
|
|
677
|
+
export const GetPromptRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
678
|
+
/**
|
|
679
|
+
* The name of the prompt or prompt template.
|
|
680
|
+
*/
|
|
681
|
+
name: z.string(),
|
|
682
|
+
/**
|
|
683
|
+
* Arguments to use for templating the prompt.
|
|
684
|
+
*/
|
|
685
|
+
arguments: z.record(z.string(), z.string()).optional()
|
|
686
|
+
});
|
|
641
687
|
/**
|
|
642
688
|
* Used by the client to get a prompt provided by the server.
|
|
643
689
|
*/
|
|
644
690
|
export const GetPromptRequestSchema = RequestSchema.extend({
|
|
645
691
|
method: z.literal('prompts/get'),
|
|
646
|
-
params:
|
|
647
|
-
/**
|
|
648
|
-
* The name of the prompt or prompt template.
|
|
649
|
-
*/
|
|
650
|
-
name: z.string(),
|
|
651
|
-
/**
|
|
652
|
-
* Arguments to use for templating the prompt.
|
|
653
|
-
*/
|
|
654
|
-
arguments: z.optional(z.record(z.string()))
|
|
655
|
-
})
|
|
692
|
+
params: GetPromptRequestParamsSchema
|
|
656
693
|
});
|
|
657
694
|
/**
|
|
658
695
|
* Text provided to or from an LLM.
|
|
659
696
|
*/
|
|
660
|
-
export const TextContentSchema = z
|
|
661
|
-
.object({
|
|
697
|
+
export const TextContentSchema = z.object({
|
|
662
698
|
type: z.literal('text'),
|
|
663
699
|
/**
|
|
664
700
|
* The text content of the message.
|
|
@@ -668,14 +704,12 @@ export const TextContentSchema = z
|
|
|
668
704
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
669
705
|
* for notes on _meta usage.
|
|
670
706
|
*/
|
|
671
|
-
_meta: z.
|
|
672
|
-
})
|
|
673
|
-
.passthrough();
|
|
707
|
+
_meta: z.record(z.string(), z.unknown()).optional()
|
|
708
|
+
});
|
|
674
709
|
/**
|
|
675
710
|
* An image provided to or from an LLM.
|
|
676
711
|
*/
|
|
677
|
-
export const ImageContentSchema = z
|
|
678
|
-
.object({
|
|
712
|
+
export const ImageContentSchema = z.object({
|
|
679
713
|
type: z.literal('image'),
|
|
680
714
|
/**
|
|
681
715
|
* The base64-encoded image data.
|
|
@@ -689,14 +723,12 @@ export const ImageContentSchema = z
|
|
|
689
723
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
690
724
|
* for notes on _meta usage.
|
|
691
725
|
*/
|
|
692
|
-
_meta: z.
|
|
693
|
-
})
|
|
694
|
-
.passthrough();
|
|
726
|
+
_meta: z.record(z.string(), z.unknown()).optional()
|
|
727
|
+
});
|
|
695
728
|
/**
|
|
696
729
|
* An Audio provided to or from an LLM.
|
|
697
730
|
*/
|
|
698
|
-
export const AudioContentSchema = z
|
|
699
|
-
.object({
|
|
731
|
+
export const AudioContentSchema = z.object({
|
|
700
732
|
type: z.literal('audio'),
|
|
701
733
|
/**
|
|
702
734
|
* The base64-encoded audio data.
|
|
@@ -706,6 +738,34 @@ export const AudioContentSchema = z
|
|
|
706
738
|
* The MIME type of the audio. Different providers may support different audio types.
|
|
707
739
|
*/
|
|
708
740
|
mimeType: z.string(),
|
|
741
|
+
/**
|
|
742
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
743
|
+
* for notes on _meta usage.
|
|
744
|
+
*/
|
|
745
|
+
_meta: z.record(z.string(), z.unknown()).optional()
|
|
746
|
+
});
|
|
747
|
+
/**
|
|
748
|
+
* A tool call request from an assistant (LLM).
|
|
749
|
+
* Represents the assistant's request to use a tool.
|
|
750
|
+
*/
|
|
751
|
+
export const ToolUseContentSchema = z
|
|
752
|
+
.object({
|
|
753
|
+
type: z.literal('tool_use'),
|
|
754
|
+
/**
|
|
755
|
+
* The name of the tool to invoke.
|
|
756
|
+
* Must match a tool name from the request's tools array.
|
|
757
|
+
*/
|
|
758
|
+
name: z.string(),
|
|
759
|
+
/**
|
|
760
|
+
* Unique identifier for this tool call.
|
|
761
|
+
* Used to correlate with ToolResultContent in subsequent messages.
|
|
762
|
+
*/
|
|
763
|
+
id: z.string(),
|
|
764
|
+
/**
|
|
765
|
+
* Arguments to pass to the tool.
|
|
766
|
+
* Must conform to the tool's inputSchema.
|
|
767
|
+
*/
|
|
768
|
+
input: z.object({}).passthrough(),
|
|
709
769
|
/**
|
|
710
770
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
711
771
|
* for notes on _meta usage.
|
|
@@ -716,17 +776,15 @@ export const AudioContentSchema = z
|
|
|
716
776
|
/**
|
|
717
777
|
* The contents of a resource, embedded into a prompt or tool call result.
|
|
718
778
|
*/
|
|
719
|
-
export const EmbeddedResourceSchema = z
|
|
720
|
-
.object({
|
|
779
|
+
export const EmbeddedResourceSchema = z.object({
|
|
721
780
|
type: z.literal('resource'),
|
|
722
781
|
resource: z.union([TextResourceContentsSchema, BlobResourceContentsSchema]),
|
|
723
782
|
/**
|
|
724
783
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
725
784
|
* for notes on _meta usage.
|
|
726
785
|
*/
|
|
727
|
-
_meta: z.
|
|
728
|
-
})
|
|
729
|
-
.passthrough();
|
|
786
|
+
_meta: z.record(z.string(), z.unknown()).optional()
|
|
787
|
+
});
|
|
730
788
|
/**
|
|
731
789
|
* A resource that the server is capable of reading, included in a prompt or tool call result.
|
|
732
790
|
*
|
|
@@ -748,12 +806,10 @@ export const ContentBlockSchema = z.union([
|
|
|
748
806
|
/**
|
|
749
807
|
* Describes a message returned as part of a prompt.
|
|
750
808
|
*/
|
|
751
|
-
export const PromptMessageSchema = z
|
|
752
|
-
.object({
|
|
809
|
+
export const PromptMessageSchema = z.object({
|
|
753
810
|
role: z.enum(['user', 'assistant']),
|
|
754
811
|
content: ContentBlockSchema
|
|
755
|
-
})
|
|
756
|
-
.passthrough();
|
|
812
|
+
});
|
|
757
813
|
/**
|
|
758
814
|
* The server's response to a prompts/get request from the client.
|
|
759
815
|
*/
|
|
@@ -781,18 +837,17 @@ export const PromptListChangedNotificationSchema = NotificationSchema.extend({
|
|
|
781
837
|
* Clients should never make tool use decisions based on ToolAnnotations
|
|
782
838
|
* received from untrusted servers.
|
|
783
839
|
*/
|
|
784
|
-
export const ToolAnnotationsSchema = z
|
|
785
|
-
.object({
|
|
840
|
+
export const ToolAnnotationsSchema = z.object({
|
|
786
841
|
/**
|
|
787
842
|
* A human-readable title for the tool.
|
|
788
843
|
*/
|
|
789
|
-
title: z.
|
|
844
|
+
title: z.string().optional(),
|
|
790
845
|
/**
|
|
791
846
|
* If true, the tool does not modify its environment.
|
|
792
847
|
*
|
|
793
848
|
* Default: false
|
|
794
849
|
*/
|
|
795
|
-
readOnlyHint: z.
|
|
850
|
+
readOnlyHint: z.boolean().optional(),
|
|
796
851
|
/**
|
|
797
852
|
* If true, the tool may perform destructive updates to its environment.
|
|
798
853
|
* If false, the tool performs only additive updates.
|
|
@@ -801,7 +856,7 @@ export const ToolAnnotationsSchema = z
|
|
|
801
856
|
*
|
|
802
857
|
* Default: true
|
|
803
858
|
*/
|
|
804
|
-
destructiveHint: z.
|
|
859
|
+
destructiveHint: z.boolean().optional(),
|
|
805
860
|
/**
|
|
806
861
|
* If true, calling the tool repeatedly with the same arguments
|
|
807
862
|
* will have no additional effect on the its environment.
|
|
@@ -810,7 +865,7 @@ export const ToolAnnotationsSchema = z
|
|
|
810
865
|
*
|
|
811
866
|
* Default: false
|
|
812
867
|
*/
|
|
813
|
-
idempotentHint: z.
|
|
868
|
+
idempotentHint: z.boolean().optional(),
|
|
814
869
|
/**
|
|
815
870
|
* If true, this tool may interact with an "open world" of external
|
|
816
871
|
* entities. If false, the tool's domain of interaction is closed.
|
|
@@ -819,38 +874,38 @@ export const ToolAnnotationsSchema = z
|
|
|
819
874
|
*
|
|
820
875
|
* Default: true
|
|
821
876
|
*/
|
|
822
|
-
openWorldHint: z.
|
|
823
|
-
})
|
|
824
|
-
.passthrough();
|
|
877
|
+
openWorldHint: z.boolean().optional()
|
|
878
|
+
});
|
|
825
879
|
/**
|
|
826
880
|
* Definition for a tool the client can call.
|
|
827
881
|
*/
|
|
828
|
-
export const ToolSchema =
|
|
882
|
+
export const ToolSchema = z.object({
|
|
883
|
+
...BaseMetadataSchema.shape,
|
|
884
|
+
...IconsSchema.shape,
|
|
829
885
|
/**
|
|
830
886
|
* A human-readable description of the tool.
|
|
831
887
|
*/
|
|
832
|
-
description: z.
|
|
888
|
+
description: z.string().optional(),
|
|
833
889
|
/**
|
|
834
890
|
* A JSON Schema object defining the expected parameters for the tool.
|
|
835
891
|
*/
|
|
836
|
-
inputSchema: z
|
|
837
|
-
.object({
|
|
892
|
+
inputSchema: z.object({
|
|
838
893
|
type: z.literal('object'),
|
|
839
|
-
properties: z.
|
|
894
|
+
properties: z.record(z.string(), AssertObjectSchema).optional(),
|
|
840
895
|
required: z.optional(z.array(z.string()))
|
|
841
|
-
})
|
|
842
|
-
.passthrough(),
|
|
896
|
+
}),
|
|
843
897
|
/**
|
|
844
898
|
* An optional JSON Schema object defining the structure of the tool's output returned in
|
|
845
899
|
* the structuredContent field of a CallToolResult.
|
|
846
900
|
*/
|
|
847
|
-
outputSchema: z
|
|
901
|
+
outputSchema: z
|
|
848
902
|
.object({
|
|
849
903
|
type: z.literal('object'),
|
|
850
|
-
properties: z.
|
|
851
|
-
required: z.optional(z.array(z.string()))
|
|
904
|
+
properties: z.record(z.string(), AssertObjectSchema).optional(),
|
|
905
|
+
required: z.optional(z.array(z.string())),
|
|
906
|
+
additionalProperties: z.optional(z.boolean())
|
|
852
907
|
})
|
|
853
|
-
.
|
|
908
|
+
.optional(),
|
|
854
909
|
/**
|
|
855
910
|
* Optional additional tool information.
|
|
856
911
|
*/
|
|
@@ -859,8 +914,8 @@ export const ToolSchema = BaseMetadataSchema.extend({
|
|
|
859
914
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
860
915
|
* for notes on _meta usage.
|
|
861
916
|
*/
|
|
862
|
-
_meta: z.
|
|
863
|
-
})
|
|
917
|
+
_meta: z.record(z.string(), z.unknown()).optional()
|
|
918
|
+
});
|
|
864
919
|
/**
|
|
865
920
|
* Sent from the client to request a list of tools the server has.
|
|
866
921
|
*/
|
|
@@ -889,7 +944,7 @@ export const CallToolResultSchema = ResultSchema.extend({
|
|
|
889
944
|
*
|
|
890
945
|
* If the Tool defines an outputSchema, this field MUST be present in the result, and contain a JSON object that matches the schema.
|
|
891
946
|
*/
|
|
892
|
-
structuredContent: z.
|
|
947
|
+
structuredContent: z.record(z.string(), z.unknown()).optional(),
|
|
893
948
|
/**
|
|
894
949
|
* Whether the tool call ended in an error.
|
|
895
950
|
*
|
|
@@ -912,15 +967,25 @@ export const CallToolResultSchema = ResultSchema.extend({
|
|
|
912
967
|
export const CompatibilityCallToolResultSchema = CallToolResultSchema.or(ResultSchema.extend({
|
|
913
968
|
toolResult: z.unknown()
|
|
914
969
|
}));
|
|
970
|
+
/**
|
|
971
|
+
* Parameters for a `tools/call` request.
|
|
972
|
+
*/
|
|
973
|
+
export const CallToolRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
974
|
+
/**
|
|
975
|
+
* The name of the tool to call.
|
|
976
|
+
*/
|
|
977
|
+
name: z.string(),
|
|
978
|
+
/**
|
|
979
|
+
* Arguments to pass to the tool.
|
|
980
|
+
*/
|
|
981
|
+
arguments: z.optional(z.record(z.string(), z.unknown()))
|
|
982
|
+
});
|
|
915
983
|
/**
|
|
916
984
|
* Used by the client to invoke a tool provided by the server.
|
|
917
985
|
*/
|
|
918
986
|
export const CallToolRequestSchema = RequestSchema.extend({
|
|
919
987
|
method: z.literal('tools/call'),
|
|
920
|
-
params:
|
|
921
|
-
name: z.string(),
|
|
922
|
-
arguments: z.optional(z.record(z.unknown()))
|
|
923
|
-
})
|
|
988
|
+
params: CallToolRequestParamsSchema
|
|
924
989
|
});
|
|
925
990
|
/**
|
|
926
991
|
* An optional notification from the server to the client, informing it that the list of tools it offers has changed. This may be issued by servers without any previous subscription from the client.
|
|
@@ -933,55 +998,60 @@ export const ToolListChangedNotificationSchema = NotificationSchema.extend({
|
|
|
933
998
|
* The severity of a log message.
|
|
934
999
|
*/
|
|
935
1000
|
export const LoggingLevelSchema = z.enum(['debug', 'info', 'notice', 'warning', 'error', 'critical', 'alert', 'emergency']);
|
|
1001
|
+
/**
|
|
1002
|
+
* Parameters for a `logging/setLevel` request.
|
|
1003
|
+
*/
|
|
1004
|
+
export const SetLevelRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
1005
|
+
/**
|
|
1006
|
+
* The level of logging that the client wants to receive from the server. The server should send all logs at this level and higher (i.e., more severe) to the client as notifications/logging/message.
|
|
1007
|
+
*/
|
|
1008
|
+
level: LoggingLevelSchema
|
|
1009
|
+
});
|
|
936
1010
|
/**
|
|
937
1011
|
* A request from the client to the server, to enable or adjust logging.
|
|
938
1012
|
*/
|
|
939
1013
|
export const SetLevelRequestSchema = RequestSchema.extend({
|
|
940
1014
|
method: z.literal('logging/setLevel'),
|
|
941
|
-
params:
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
1015
|
+
params: SetLevelRequestParamsSchema
|
|
1016
|
+
});
|
|
1017
|
+
/**
|
|
1018
|
+
* Parameters for a `notifications/message` notification.
|
|
1019
|
+
*/
|
|
1020
|
+
export const LoggingMessageNotificationParamsSchema = NotificationsParamsSchema.extend({
|
|
1021
|
+
/**
|
|
1022
|
+
* The severity of this log message.
|
|
1023
|
+
*/
|
|
1024
|
+
level: LoggingLevelSchema,
|
|
1025
|
+
/**
|
|
1026
|
+
* An optional name of the logger issuing this message.
|
|
1027
|
+
*/
|
|
1028
|
+
logger: z.string().optional(),
|
|
1029
|
+
/**
|
|
1030
|
+
* The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here.
|
|
1031
|
+
*/
|
|
1032
|
+
data: z.unknown()
|
|
947
1033
|
});
|
|
948
1034
|
/**
|
|
949
1035
|
* Notification of a log message passed from server to client. If no logging/setLevel request has been sent from the client, the server MAY decide which messages to send automatically.
|
|
950
1036
|
*/
|
|
951
1037
|
export const LoggingMessageNotificationSchema = NotificationSchema.extend({
|
|
952
1038
|
method: z.literal('notifications/message'),
|
|
953
|
-
params:
|
|
954
|
-
/**
|
|
955
|
-
* The severity of this log message.
|
|
956
|
-
*/
|
|
957
|
-
level: LoggingLevelSchema,
|
|
958
|
-
/**
|
|
959
|
-
* An optional name of the logger issuing this message.
|
|
960
|
-
*/
|
|
961
|
-
logger: z.optional(z.string()),
|
|
962
|
-
/**
|
|
963
|
-
* The data to be logged, such as a string message or an object. Any JSON serializable type is allowed here.
|
|
964
|
-
*/
|
|
965
|
-
data: z.unknown()
|
|
966
|
-
})
|
|
1039
|
+
params: LoggingMessageNotificationParamsSchema
|
|
967
1040
|
});
|
|
968
1041
|
/* Sampling */
|
|
969
1042
|
/**
|
|
970
1043
|
* Hints to use for model selection.
|
|
971
1044
|
*/
|
|
972
|
-
export const ModelHintSchema = z
|
|
973
|
-
.object({
|
|
1045
|
+
export const ModelHintSchema = z.object({
|
|
974
1046
|
/**
|
|
975
1047
|
* A hint for a model name.
|
|
976
1048
|
*/
|
|
977
1049
|
name: z.string().optional()
|
|
978
|
-
})
|
|
979
|
-
.passthrough();
|
|
1050
|
+
});
|
|
980
1051
|
/**
|
|
981
1052
|
* The server's preferences for model selection, requested of the client during sampling.
|
|
982
1053
|
*/
|
|
983
|
-
export const ModelPreferencesSchema = z
|
|
984
|
-
.object({
|
|
1054
|
+
export const ModelPreferencesSchema = z.object({
|
|
985
1055
|
/**
|
|
986
1056
|
* Optional hints to use for model selection.
|
|
987
1057
|
*/
|
|
@@ -998,47 +1068,113 @@ export const ModelPreferencesSchema = z
|
|
|
998
1068
|
* How much to prioritize intelligence and capabilities when selecting a model.
|
|
999
1069
|
*/
|
|
1000
1070
|
intelligencePriority: z.optional(z.number().min(0).max(1))
|
|
1071
|
+
});
|
|
1072
|
+
/**
|
|
1073
|
+
* Controls tool usage behavior in sampling requests.
|
|
1074
|
+
*/
|
|
1075
|
+
export const ToolChoiceSchema = z.object({
|
|
1076
|
+
/**
|
|
1077
|
+
* Controls when tools are used:
|
|
1078
|
+
* - "auto": Model decides whether to use tools (default)
|
|
1079
|
+
* - "required": Model MUST use at least one tool before completing
|
|
1080
|
+
* - "none": Model MUST NOT use any tools
|
|
1081
|
+
*/
|
|
1082
|
+
mode: z.optional(z.enum(['auto', 'required', 'none']))
|
|
1083
|
+
});
|
|
1084
|
+
/**
|
|
1085
|
+
* The result of a tool execution, provided by the user (server).
|
|
1086
|
+
* Represents the outcome of invoking a tool requested via ToolUseContent.
|
|
1087
|
+
*/
|
|
1088
|
+
export const ToolResultContentSchema = z
|
|
1089
|
+
.object({
|
|
1090
|
+
type: z.literal('tool_result'),
|
|
1091
|
+
toolUseId: z.string().describe('The unique identifier for the corresponding tool call.'),
|
|
1092
|
+
content: z.array(ContentBlockSchema).default([]),
|
|
1093
|
+
structuredContent: z.object({}).passthrough().optional(),
|
|
1094
|
+
isError: z.optional(z.boolean()),
|
|
1095
|
+
/**
|
|
1096
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
1097
|
+
* for notes on _meta usage.
|
|
1098
|
+
*/
|
|
1099
|
+
_meta: z.optional(z.object({}).passthrough())
|
|
1001
1100
|
})
|
|
1002
1101
|
.passthrough();
|
|
1102
|
+
/**
|
|
1103
|
+
* Content block types allowed in sampling messages.
|
|
1104
|
+
* This includes text, image, audio, tool use requests, and tool results.
|
|
1105
|
+
*/
|
|
1106
|
+
export const SamplingMessageContentBlockSchema = z.discriminatedUnion('type', [
|
|
1107
|
+
TextContentSchema,
|
|
1108
|
+
ImageContentSchema,
|
|
1109
|
+
AudioContentSchema,
|
|
1110
|
+
ToolUseContentSchema,
|
|
1111
|
+
ToolResultContentSchema
|
|
1112
|
+
]);
|
|
1003
1113
|
/**
|
|
1004
1114
|
* Describes a message issued to or received from an LLM API.
|
|
1005
1115
|
*/
|
|
1006
1116
|
export const SamplingMessageSchema = z
|
|
1007
1117
|
.object({
|
|
1008
1118
|
role: z.enum(['user', 'assistant']),
|
|
1009
|
-
content: z.union([
|
|
1119
|
+
content: z.union([SamplingMessageContentBlockSchema, z.array(SamplingMessageContentBlockSchema)]),
|
|
1120
|
+
/**
|
|
1121
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
1122
|
+
* for notes on _meta usage.
|
|
1123
|
+
*/
|
|
1124
|
+
_meta: z.optional(z.object({}).passthrough())
|
|
1010
1125
|
})
|
|
1011
1126
|
.passthrough();
|
|
1127
|
+
/**
|
|
1128
|
+
* Parameters for a `sampling/createMessage` request.
|
|
1129
|
+
*/
|
|
1130
|
+
export const CreateMessageRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
1131
|
+
messages: z.array(SamplingMessageSchema),
|
|
1132
|
+
/**
|
|
1133
|
+
* The server's preferences for which model to select. The client MAY modify or omit this request.
|
|
1134
|
+
*/
|
|
1135
|
+
modelPreferences: ModelPreferencesSchema.optional(),
|
|
1136
|
+
/**
|
|
1137
|
+
* An optional system prompt the server wants to use for sampling. The client MAY modify or omit this prompt.
|
|
1138
|
+
*/
|
|
1139
|
+
systemPrompt: z.string().optional(),
|
|
1140
|
+
/**
|
|
1141
|
+
* A request to include context from one or more MCP servers (including the caller), to be attached to the prompt.
|
|
1142
|
+
* The client MAY ignore this request.
|
|
1143
|
+
*
|
|
1144
|
+
* Default is "none". Values "thisServer" and "allServers" are soft-deprecated. Servers SHOULD only use these values if the client
|
|
1145
|
+
* declares ClientCapabilities.sampling.context. These values may be removed in future spec releases.
|
|
1146
|
+
*/
|
|
1147
|
+
includeContext: z.enum(['none', 'thisServer', 'allServers']).optional(),
|
|
1148
|
+
temperature: z.number().optional(),
|
|
1149
|
+
/**
|
|
1150
|
+
* The requested maximum number of tokens to sample (to prevent runaway completions).
|
|
1151
|
+
*
|
|
1152
|
+
* The client MAY choose to sample fewer tokens than the requested maximum.
|
|
1153
|
+
*/
|
|
1154
|
+
maxTokens: z.number().int(),
|
|
1155
|
+
stopSequences: z.array(z.string()).optional(),
|
|
1156
|
+
/**
|
|
1157
|
+
* Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific.
|
|
1158
|
+
*/
|
|
1159
|
+
metadata: AssertObjectSchema.optional(),
|
|
1160
|
+
/**
|
|
1161
|
+
* Tools that the model may use during generation.
|
|
1162
|
+
* The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
|
|
1163
|
+
*/
|
|
1164
|
+
tools: z.optional(z.array(ToolSchema)),
|
|
1165
|
+
/**
|
|
1166
|
+
* Controls how the model uses tools.
|
|
1167
|
+
* The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
|
|
1168
|
+
* Default is `{ mode: "auto" }`.
|
|
1169
|
+
*/
|
|
1170
|
+
toolChoice: z.optional(ToolChoiceSchema)
|
|
1171
|
+
});
|
|
1012
1172
|
/**
|
|
1013
1173
|
* A request from the server to sample an LLM via the client. The client has full discretion over which model to select. The client should also inform the user before beginning sampling, to allow them to inspect the request (human in the loop) and decide whether to approve it.
|
|
1014
1174
|
*/
|
|
1015
1175
|
export const CreateMessageRequestSchema = RequestSchema.extend({
|
|
1016
1176
|
method: z.literal('sampling/createMessage'),
|
|
1017
|
-
params:
|
|
1018
|
-
messages: z.array(SamplingMessageSchema),
|
|
1019
|
-
/**
|
|
1020
|
-
* An optional system prompt the server wants to use for sampling. The client MAY modify or omit this prompt.
|
|
1021
|
-
*/
|
|
1022
|
-
systemPrompt: z.optional(z.string()),
|
|
1023
|
-
/**
|
|
1024
|
-
* A request to include context from one or more MCP servers (including the caller), to be attached to the prompt. The client MAY ignore this request.
|
|
1025
|
-
*/
|
|
1026
|
-
includeContext: z.optional(z.enum(['none', 'thisServer', 'allServers'])),
|
|
1027
|
-
temperature: z.optional(z.number()),
|
|
1028
|
-
/**
|
|
1029
|
-
* The maximum number of tokens to sample, as requested by the server. The client MAY choose to sample fewer tokens than requested.
|
|
1030
|
-
*/
|
|
1031
|
-
maxTokens: z.number().int(),
|
|
1032
|
-
stopSequences: z.optional(z.array(z.string())),
|
|
1033
|
-
/**
|
|
1034
|
-
* Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific.
|
|
1035
|
-
*/
|
|
1036
|
-
metadata: z.optional(z.object({}).passthrough()),
|
|
1037
|
-
/**
|
|
1038
|
-
* The server's preferences for which model to select.
|
|
1039
|
-
*/
|
|
1040
|
-
modelPreferences: z.optional(ModelPreferencesSchema)
|
|
1041
|
-
})
|
|
1177
|
+
params: CreateMessageRequestParamsSchema
|
|
1042
1178
|
});
|
|
1043
1179
|
/**
|
|
1044
1180
|
* The client's response to a sampling/create_message request from the server. The client should inform the user before returning the sampled message, to allow them to inspect the response (human in the loop) and decide whether to allow the server to see it.
|
|
@@ -1049,114 +1185,242 @@ export const CreateMessageResultSchema = ResultSchema.extend({
|
|
|
1049
1185
|
*/
|
|
1050
1186
|
model: z.string(),
|
|
1051
1187
|
/**
|
|
1052
|
-
* The reason why sampling stopped.
|
|
1188
|
+
* The reason why sampling stopped, if known.
|
|
1189
|
+
*
|
|
1190
|
+
* Standard values:
|
|
1191
|
+
* - "endTurn": Natural end of the assistant's turn
|
|
1192
|
+
* - "stopSequence": A stop sequence was encountered
|
|
1193
|
+
* - "maxTokens": Maximum token limit was reached
|
|
1194
|
+
* - "toolUse": The model wants to use one or more tools
|
|
1195
|
+
*
|
|
1196
|
+
* This field is an open string to allow for provider-specific stop reasons.
|
|
1053
1197
|
*/
|
|
1054
|
-
stopReason: z.optional(z.enum(['endTurn', 'stopSequence', 'maxTokens']).or(z.string())),
|
|
1198
|
+
stopReason: z.optional(z.enum(['endTurn', 'stopSequence', 'maxTokens', 'toolUse']).or(z.string())),
|
|
1055
1199
|
role: z.enum(['user', 'assistant']),
|
|
1056
|
-
|
|
1200
|
+
/**
|
|
1201
|
+
* Response content. May be ToolUseContent if stopReason is "toolUse".
|
|
1202
|
+
*/
|
|
1203
|
+
content: z.union([SamplingMessageContentBlockSchema, z.array(SamplingMessageContentBlockSchema)])
|
|
1057
1204
|
});
|
|
1058
1205
|
/* Elicitation */
|
|
1059
1206
|
/**
|
|
1060
1207
|
* Primitive schema definition for boolean fields.
|
|
1061
1208
|
*/
|
|
1062
|
-
export const BooleanSchemaSchema = z
|
|
1063
|
-
.object({
|
|
1209
|
+
export const BooleanSchemaSchema = z.object({
|
|
1064
1210
|
type: z.literal('boolean'),
|
|
1065
|
-
title: z.
|
|
1066
|
-
description: z.
|
|
1067
|
-
default: z.
|
|
1068
|
-
})
|
|
1069
|
-
.passthrough();
|
|
1211
|
+
title: z.string().optional(),
|
|
1212
|
+
description: z.string().optional(),
|
|
1213
|
+
default: z.boolean().optional()
|
|
1214
|
+
});
|
|
1070
1215
|
/**
|
|
1071
1216
|
* Primitive schema definition for string fields.
|
|
1072
1217
|
*/
|
|
1073
|
-
export const StringSchemaSchema = z
|
|
1074
|
-
.object({
|
|
1218
|
+
export const StringSchemaSchema = z.object({
|
|
1075
1219
|
type: z.literal('string'),
|
|
1076
|
-
title: z.
|
|
1077
|
-
description: z.
|
|
1078
|
-
minLength: z.
|
|
1079
|
-
maxLength: z.
|
|
1080
|
-
format: z.
|
|
1081
|
-
|
|
1082
|
-
|
|
1220
|
+
title: z.string().optional(),
|
|
1221
|
+
description: z.string().optional(),
|
|
1222
|
+
minLength: z.number().optional(),
|
|
1223
|
+
maxLength: z.number().optional(),
|
|
1224
|
+
format: z.enum(['email', 'uri', 'date', 'date-time']).optional(),
|
|
1225
|
+
default: z.string().optional()
|
|
1226
|
+
});
|
|
1083
1227
|
/**
|
|
1084
1228
|
* Primitive schema definition for number fields.
|
|
1085
1229
|
*/
|
|
1086
|
-
export const NumberSchemaSchema = z
|
|
1087
|
-
.object({
|
|
1230
|
+
export const NumberSchemaSchema = z.object({
|
|
1088
1231
|
type: z.enum(['number', 'integer']),
|
|
1089
|
-
title: z.
|
|
1090
|
-
description: z.
|
|
1091
|
-
minimum: z.
|
|
1092
|
-
maximum: z.
|
|
1093
|
-
|
|
1094
|
-
|
|
1232
|
+
title: z.string().optional(),
|
|
1233
|
+
description: z.string().optional(),
|
|
1234
|
+
minimum: z.number().optional(),
|
|
1235
|
+
maximum: z.number().optional(),
|
|
1236
|
+
default: z.number().optional()
|
|
1237
|
+
});
|
|
1095
1238
|
/**
|
|
1096
|
-
*
|
|
1239
|
+
* Schema for single-selection enumeration without display titles for options.
|
|
1097
1240
|
*/
|
|
1098
|
-
export const
|
|
1099
|
-
.object({
|
|
1241
|
+
export const UntitledSingleSelectEnumSchemaSchema = z.object({
|
|
1100
1242
|
type: z.literal('string'),
|
|
1101
|
-
title: z.
|
|
1102
|
-
description: z.
|
|
1243
|
+
title: z.string().optional(),
|
|
1244
|
+
description: z.string().optional(),
|
|
1103
1245
|
enum: z.array(z.string()),
|
|
1104
|
-
|
|
1105
|
-
})
|
|
1106
|
-
|
|
1246
|
+
default: z.string().optional()
|
|
1247
|
+
});
|
|
1248
|
+
/**
|
|
1249
|
+
* Schema for single-selection enumeration with display titles for each option.
|
|
1250
|
+
*/
|
|
1251
|
+
export const TitledSingleSelectEnumSchemaSchema = z.object({
|
|
1252
|
+
type: z.literal('string'),
|
|
1253
|
+
title: z.string().optional(),
|
|
1254
|
+
description: z.string().optional(),
|
|
1255
|
+
oneOf: z.array(z.object({
|
|
1256
|
+
const: z.string(),
|
|
1257
|
+
title: z.string()
|
|
1258
|
+
})),
|
|
1259
|
+
default: z.string().optional()
|
|
1260
|
+
});
|
|
1261
|
+
/**
|
|
1262
|
+
* Use TitledSingleSelectEnumSchema instead.
|
|
1263
|
+
* This interface will be removed in a future version.
|
|
1264
|
+
*/
|
|
1265
|
+
export const LegacyTitledEnumSchemaSchema = z.object({
|
|
1266
|
+
type: z.literal('string'),
|
|
1267
|
+
title: z.string().optional(),
|
|
1268
|
+
description: z.string().optional(),
|
|
1269
|
+
enum: z.array(z.string()),
|
|
1270
|
+
enumNames: z.array(z.string()).optional(),
|
|
1271
|
+
default: z.string().optional()
|
|
1272
|
+
});
|
|
1273
|
+
// Combined single selection enumeration
|
|
1274
|
+
export const SingleSelectEnumSchemaSchema = z.union([UntitledSingleSelectEnumSchemaSchema, TitledSingleSelectEnumSchemaSchema]);
|
|
1275
|
+
/**
|
|
1276
|
+
* Schema for multiple-selection enumeration without display titles for options.
|
|
1277
|
+
*/
|
|
1278
|
+
export const UntitledMultiSelectEnumSchemaSchema = z.object({
|
|
1279
|
+
type: z.literal('array'),
|
|
1280
|
+
title: z.string().optional(),
|
|
1281
|
+
description: z.string().optional(),
|
|
1282
|
+
minItems: z.number().optional(),
|
|
1283
|
+
maxItems: z.number().optional(),
|
|
1284
|
+
items: z.object({
|
|
1285
|
+
type: z.literal('string'),
|
|
1286
|
+
enum: z.array(z.string())
|
|
1287
|
+
}),
|
|
1288
|
+
default: z.array(z.string()).optional()
|
|
1289
|
+
});
|
|
1290
|
+
/**
|
|
1291
|
+
* Schema for multiple-selection enumeration with display titles for each option.
|
|
1292
|
+
*/
|
|
1293
|
+
export const TitledMultiSelectEnumSchemaSchema = z.object({
|
|
1294
|
+
type: z.literal('array'),
|
|
1295
|
+
title: z.string().optional(),
|
|
1296
|
+
description: z.string().optional(),
|
|
1297
|
+
minItems: z.number().optional(),
|
|
1298
|
+
maxItems: z.number().optional(),
|
|
1299
|
+
items: z.object({
|
|
1300
|
+
anyOf: z.array(z.object({
|
|
1301
|
+
const: z.string(),
|
|
1302
|
+
title: z.string()
|
|
1303
|
+
}))
|
|
1304
|
+
}),
|
|
1305
|
+
default: z.array(z.string()).optional()
|
|
1306
|
+
});
|
|
1307
|
+
/**
|
|
1308
|
+
* Combined schema for multiple-selection enumeration
|
|
1309
|
+
*/
|
|
1310
|
+
export const MultiSelectEnumSchemaSchema = z.union([UntitledMultiSelectEnumSchemaSchema, TitledMultiSelectEnumSchemaSchema]);
|
|
1311
|
+
/**
|
|
1312
|
+
* Primitive schema definition for enum fields.
|
|
1313
|
+
*/
|
|
1314
|
+
export const EnumSchemaSchema = z.union([LegacyTitledEnumSchemaSchema, SingleSelectEnumSchemaSchema, MultiSelectEnumSchemaSchema]);
|
|
1107
1315
|
/**
|
|
1108
1316
|
* Union of all primitive schema definitions.
|
|
1109
1317
|
*/
|
|
1110
|
-
export const PrimitiveSchemaDefinitionSchema = z.union([BooleanSchemaSchema, StringSchemaSchema, NumberSchemaSchema
|
|
1318
|
+
export const PrimitiveSchemaDefinitionSchema = z.union([EnumSchemaSchema, BooleanSchemaSchema, StringSchemaSchema, NumberSchemaSchema]);
|
|
1319
|
+
/**
|
|
1320
|
+
* Parameters for an `elicitation/create` request for form-based elicitation.
|
|
1321
|
+
*/
|
|
1322
|
+
export const ElicitRequestFormParamsSchema = BaseRequestParamsSchema.extend({
|
|
1323
|
+
/**
|
|
1324
|
+
* The elicitation mode.
|
|
1325
|
+
*/
|
|
1326
|
+
mode: z.literal('form'),
|
|
1327
|
+
/**
|
|
1328
|
+
* The message to present to the user describing what information is being requested.
|
|
1329
|
+
*/
|
|
1330
|
+
message: z.string(),
|
|
1331
|
+
/**
|
|
1332
|
+
* A restricted subset of JSON Schema.
|
|
1333
|
+
* Only top-level properties are allowed, without nesting.
|
|
1334
|
+
*/
|
|
1335
|
+
requestedSchema: z.object({
|
|
1336
|
+
type: z.literal('object'),
|
|
1337
|
+
properties: z.record(z.string(), PrimitiveSchemaDefinitionSchema),
|
|
1338
|
+
required: z.array(z.string()).optional()
|
|
1339
|
+
})
|
|
1340
|
+
});
|
|
1341
|
+
/**
|
|
1342
|
+
* Parameters for an `elicitation/create` request for URL-based elicitation.
|
|
1343
|
+
*/
|
|
1344
|
+
export const ElicitRequestURLParamsSchema = BaseRequestParamsSchema.extend({
|
|
1345
|
+
/**
|
|
1346
|
+
* The elicitation mode.
|
|
1347
|
+
*/
|
|
1348
|
+
mode: z.literal('url'),
|
|
1349
|
+
/**
|
|
1350
|
+
* The message to present to the user explaining why the interaction is needed.
|
|
1351
|
+
*/
|
|
1352
|
+
message: z.string(),
|
|
1353
|
+
/**
|
|
1354
|
+
* The ID of the elicitation, which must be unique within the context of the server.
|
|
1355
|
+
* The client MUST treat this ID as an opaque value.
|
|
1356
|
+
*/
|
|
1357
|
+
elicitationId: z.string(),
|
|
1358
|
+
/**
|
|
1359
|
+
* The URL that the user should navigate to.
|
|
1360
|
+
*/
|
|
1361
|
+
url: z.string().url()
|
|
1362
|
+
});
|
|
1363
|
+
/**
|
|
1364
|
+
* The parameters for a request to elicit additional information from the user via the client.
|
|
1365
|
+
*/
|
|
1366
|
+
export const ElicitRequestParamsSchema = z.union([ElicitRequestFormParamsSchema, ElicitRequestURLParamsSchema]);
|
|
1111
1367
|
/**
|
|
1112
1368
|
* A request from the server to elicit user input via the client.
|
|
1113
|
-
* The client should present the message and form fields to the user
|
|
1369
|
+
* The client should present the message and form fields to the user (form mode)
|
|
1370
|
+
* or navigate to a URL (URL mode).
|
|
1114
1371
|
*/
|
|
1115
1372
|
export const ElicitRequestSchema = RequestSchema.extend({
|
|
1116
1373
|
method: z.literal('elicitation/create'),
|
|
1117
|
-
params:
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1374
|
+
params: ElicitRequestParamsSchema
|
|
1375
|
+
});
|
|
1376
|
+
/**
|
|
1377
|
+
* Parameters for a `notifications/elicitation/complete` notification.
|
|
1378
|
+
*
|
|
1379
|
+
* @category notifications/elicitation/complete
|
|
1380
|
+
*/
|
|
1381
|
+
export const ElicitationCompleteNotificationParamsSchema = NotificationsParamsSchema.extend({
|
|
1382
|
+
/**
|
|
1383
|
+
* The ID of the elicitation that completed.
|
|
1384
|
+
*/
|
|
1385
|
+
elicitationId: z.string()
|
|
1386
|
+
});
|
|
1387
|
+
/**
|
|
1388
|
+
* A notification from the server to the client, informing it of a completion of an out-of-band elicitation request.
|
|
1389
|
+
*
|
|
1390
|
+
* @category notifications/elicitation/complete
|
|
1391
|
+
*/
|
|
1392
|
+
export const ElicitationCompleteNotificationSchema = NotificationSchema.extend({
|
|
1393
|
+
method: z.literal('notifications/elicitation/complete'),
|
|
1394
|
+
params: ElicitationCompleteNotificationParamsSchema
|
|
1133
1395
|
});
|
|
1134
1396
|
/**
|
|
1135
1397
|
* The client's response to an elicitation/create request from the server.
|
|
1136
1398
|
*/
|
|
1137
1399
|
export const ElicitResultSchema = ResultSchema.extend({
|
|
1138
1400
|
/**
|
|
1139
|
-
* The user
|
|
1401
|
+
* The user action in response to the elicitation.
|
|
1402
|
+
* - "accept": User submitted the form/confirmed the action
|
|
1403
|
+
* - "decline": User explicitly decline the action
|
|
1404
|
+
* - "cancel": User dismissed without making an explicit choice
|
|
1140
1405
|
*/
|
|
1141
1406
|
action: z.enum(['accept', 'decline', 'cancel']),
|
|
1142
1407
|
/**
|
|
1143
|
-
* The
|
|
1408
|
+
* The submitted form data, only present when action is "accept".
|
|
1409
|
+
* Contains values matching the requested schema.
|
|
1144
1410
|
*/
|
|
1145
|
-
content: z.
|
|
1411
|
+
content: z.record(z.string(), z.union([z.string(), z.number(), z.boolean(), z.array(z.string())])).optional()
|
|
1146
1412
|
});
|
|
1147
1413
|
/* Autocomplete */
|
|
1148
1414
|
/**
|
|
1149
1415
|
* A reference to a resource or resource template definition.
|
|
1150
1416
|
*/
|
|
1151
|
-
export const ResourceTemplateReferenceSchema = z
|
|
1152
|
-
.object({
|
|
1417
|
+
export const ResourceTemplateReferenceSchema = z.object({
|
|
1153
1418
|
type: z.literal('ref/resource'),
|
|
1154
1419
|
/**
|
|
1155
1420
|
* The URI or URI template of the resource.
|
|
1156
1421
|
*/
|
|
1157
1422
|
uri: z.string()
|
|
1158
|
-
})
|
|
1159
|
-
.passthrough();
|
|
1423
|
+
});
|
|
1160
1424
|
/**
|
|
1161
1425
|
* @deprecated Use ResourceTemplateReferenceSchema instead
|
|
1162
1426
|
*/
|
|
@@ -1164,51 +1428,64 @@ export const ResourceReferenceSchema = ResourceTemplateReferenceSchema;
|
|
|
1164
1428
|
/**
|
|
1165
1429
|
* Identifies a prompt.
|
|
1166
1430
|
*/
|
|
1167
|
-
export const PromptReferenceSchema = z
|
|
1168
|
-
.object({
|
|
1431
|
+
export const PromptReferenceSchema = z.object({
|
|
1169
1432
|
type: z.literal('ref/prompt'),
|
|
1170
1433
|
/**
|
|
1171
1434
|
* The name of the prompt or prompt template
|
|
1172
1435
|
*/
|
|
1173
1436
|
name: z.string()
|
|
1174
|
-
})
|
|
1175
|
-
.passthrough();
|
|
1437
|
+
});
|
|
1176
1438
|
/**
|
|
1177
|
-
*
|
|
1439
|
+
* Parameters for a `completion/complete` request.
|
|
1178
1440
|
*/
|
|
1179
|
-
export const
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1441
|
+
export const CompleteRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
1442
|
+
ref: z.union([PromptReferenceSchema, ResourceTemplateReferenceSchema]),
|
|
1443
|
+
/**
|
|
1444
|
+
* The argument's information
|
|
1445
|
+
*/
|
|
1446
|
+
argument: z.object({
|
|
1183
1447
|
/**
|
|
1184
|
-
* The argument
|
|
1448
|
+
* The name of the argument
|
|
1185
1449
|
*/
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
context: z.optional(z.object({
|
|
1199
|
-
/**
|
|
1200
|
-
* Previously-resolved variables in a URI template or prompt.
|
|
1201
|
-
*/
|
|
1202
|
-
arguments: z.optional(z.record(z.string(), z.string()))
|
|
1203
|
-
}))
|
|
1450
|
+
name: z.string(),
|
|
1451
|
+
/**
|
|
1452
|
+
* The value of the argument to use for completion matching.
|
|
1453
|
+
*/
|
|
1454
|
+
value: z.string()
|
|
1455
|
+
}),
|
|
1456
|
+
context: z
|
|
1457
|
+
.object({
|
|
1458
|
+
/**
|
|
1459
|
+
* Previously-resolved variables in a URI template or prompt.
|
|
1460
|
+
*/
|
|
1461
|
+
arguments: z.record(z.string(), z.string()).optional()
|
|
1204
1462
|
})
|
|
1463
|
+
.optional()
|
|
1205
1464
|
});
|
|
1465
|
+
/**
|
|
1466
|
+
* A request from the client to the server, to ask for completion options.
|
|
1467
|
+
*/
|
|
1468
|
+
export const CompleteRequestSchema = RequestSchema.extend({
|
|
1469
|
+
method: z.literal('completion/complete'),
|
|
1470
|
+
params: CompleteRequestParamsSchema
|
|
1471
|
+
});
|
|
1472
|
+
export function assertCompleteRequestPrompt(request) {
|
|
1473
|
+
if (request.params.ref.type !== 'ref/prompt') {
|
|
1474
|
+
throw new TypeError(`Expected CompleteRequestPrompt, but got ${request.params.ref.type}`);
|
|
1475
|
+
}
|
|
1476
|
+
void request;
|
|
1477
|
+
}
|
|
1478
|
+
export function assertCompleteRequestResourceTemplate(request) {
|
|
1479
|
+
if (request.params.ref.type !== 'ref/resource') {
|
|
1480
|
+
throw new TypeError(`Expected CompleteRequestResourceTemplate, but got ${request.params.ref.type}`);
|
|
1481
|
+
}
|
|
1482
|
+
void request;
|
|
1483
|
+
}
|
|
1206
1484
|
/**
|
|
1207
1485
|
* The server's response to a completion/complete request
|
|
1208
1486
|
*/
|
|
1209
1487
|
export const CompleteResultSchema = ResultSchema.extend({
|
|
1210
|
-
completion: z
|
|
1211
|
-
.object({
|
|
1488
|
+
completion: z.looseObject({
|
|
1212
1489
|
/**
|
|
1213
1490
|
* An array of completion values. Must not exceed 100 items.
|
|
1214
1491
|
*/
|
|
@@ -1222,14 +1499,12 @@ export const CompleteResultSchema = ResultSchema.extend({
|
|
|
1222
1499
|
*/
|
|
1223
1500
|
hasMore: z.optional(z.boolean())
|
|
1224
1501
|
})
|
|
1225
|
-
.passthrough()
|
|
1226
1502
|
});
|
|
1227
1503
|
/* Roots */
|
|
1228
1504
|
/**
|
|
1229
1505
|
* Represents a root directory or file that the server can operate on.
|
|
1230
1506
|
*/
|
|
1231
|
-
export const RootSchema = z
|
|
1232
|
-
.object({
|
|
1507
|
+
export const RootSchema = z.object({
|
|
1233
1508
|
/**
|
|
1234
1509
|
* The URI identifying the root. This *must* start with file:// for now.
|
|
1235
1510
|
*/
|
|
@@ -1237,14 +1512,13 @@ export const RootSchema = z
|
|
|
1237
1512
|
/**
|
|
1238
1513
|
* An optional name for the root.
|
|
1239
1514
|
*/
|
|
1240
|
-
name: z.
|
|
1515
|
+
name: z.string().optional(),
|
|
1241
1516
|
/**
|
|
1242
1517
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
1243
1518
|
* for notes on _meta usage.
|
|
1244
1519
|
*/
|
|
1245
|
-
_meta: z.
|
|
1246
|
-
})
|
|
1247
|
-
.passthrough();
|
|
1520
|
+
_meta: z.record(z.string(), z.unknown()).optional()
|
|
1521
|
+
});
|
|
1248
1522
|
/**
|
|
1249
1523
|
* Sent from the server to request a list of root URIs from the client.
|
|
1250
1524
|
*/
|
|
@@ -1295,7 +1569,8 @@ export const ServerNotificationSchema = z.union([
|
|
|
1295
1569
|
ResourceUpdatedNotificationSchema,
|
|
1296
1570
|
ResourceListChangedNotificationSchema,
|
|
1297
1571
|
ToolListChangedNotificationSchema,
|
|
1298
|
-
PromptListChangedNotificationSchema
|
|
1572
|
+
PromptListChangedNotificationSchema,
|
|
1573
|
+
ElicitationCompleteNotificationSchema
|
|
1299
1574
|
]);
|
|
1300
1575
|
export const ServerResultSchema = z.union([
|
|
1301
1576
|
EmptyResultSchema,
|
|
@@ -1316,5 +1591,34 @@ export class McpError extends Error {
|
|
|
1316
1591
|
this.data = data;
|
|
1317
1592
|
this.name = 'McpError';
|
|
1318
1593
|
}
|
|
1594
|
+
/**
|
|
1595
|
+
* Factory method to create the appropriate error type based on the error code and data
|
|
1596
|
+
*/
|
|
1597
|
+
static fromError(code, message, data) {
|
|
1598
|
+
// Check for specific error types
|
|
1599
|
+
if (code === ErrorCode.UrlElicitationRequired && data) {
|
|
1600
|
+
const errorData = data;
|
|
1601
|
+
if (errorData.elicitations) {
|
|
1602
|
+
return new UrlElicitationRequiredError(errorData.elicitations, message);
|
|
1603
|
+
}
|
|
1604
|
+
}
|
|
1605
|
+
// Default to generic McpError
|
|
1606
|
+
return new McpError(code, message, data);
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
/**
|
|
1610
|
+
* Specialized error type when a tool requires a URL mode elicitation.
|
|
1611
|
+
* This makes it nicer for the client to handle since there is specific data to work with instead of just a code to check against.
|
|
1612
|
+
*/
|
|
1613
|
+
export class UrlElicitationRequiredError extends McpError {
|
|
1614
|
+
constructor(elicitations, message = `URL elicitation${elicitations.length > 1 ? 's' : ''} required`) {
|
|
1615
|
+
super(ErrorCode.UrlElicitationRequired, message, {
|
|
1616
|
+
elicitations: elicitations
|
|
1617
|
+
});
|
|
1618
|
+
}
|
|
1619
|
+
get elicitations() {
|
|
1620
|
+
var _a, _b;
|
|
1621
|
+
return (_b = (_a = this.data) === null || _a === void 0 ? void 0 : _a.elicitations) !== null && _b !== void 0 ? _b : [];
|
|
1622
|
+
}
|
|
1319
1623
|
}
|
|
1320
1624
|
//# sourceMappingURL=types.js.map
|