@modelcontextprotocol/sdk 1.22.0 → 1.23.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 +122 -662
- package/dist/cjs/client/index.d.ts.map +1 -1
- package/dist/cjs/client/index.js +72 -15
- 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 +14 -2
- package/dist/cjs/client/streamableHttp.d.ts.map +1 -1
- package/dist/cjs/client/streamableHttp.js +79 -19
- 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 +10 -5
- package/dist/cjs/examples/client/simpleStreamableHttp.js.map +1 -1
- package/dist/cjs/examples/client/ssePollingClient.d.ts +2 -0
- package/dist/cjs/examples/client/ssePollingClient.d.ts.map +1 -0
- package/dist/cjs/examples/client/ssePollingClient.js +95 -0
- package/dist/cjs/examples/client/ssePollingClient.js.map +1 -0
- 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} +14 -8
- 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/ssePollingExample.d.ts +2 -0
- package/dist/cjs/examples/server/ssePollingExample.d.ts.map +1 -0
- package/dist/cjs/examples/server/ssePollingExample.js +116 -0
- package/dist/cjs/examples/server/ssePollingExample.js.map +1 -0
- 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 +176 -50
- package/dist/cjs/server/index.d.ts.map +1 -1
- package/dist/cjs/server/index.js +99 -13
- 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 +83 -40
- package/dist/cjs/server/mcp.js.map +1 -1
- package/dist/cjs/server/streamableHttp.d.ts +27 -0
- package/dist/cjs/server/streamableHttp.d.ts.map +1 -1
- package/dist/cjs/server/streamableHttp.js +70 -5
- package/dist/cjs/server/streamableHttp.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/protocol.d.ts +5 -9
- package/dist/cjs/shared/protocol.d.ts.map +1 -1
- package/dist/cjs/shared/protocol.js +24 -10
- package/dist/cjs/shared/protocol.js.map +1 -1
- package/dist/cjs/shared/transport.d.ts +14 -0
- 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 +393 -70
- package/dist/cjs/spec.types.d.ts.map +1 -1
- package/dist/cjs/spec.types.js +5 -7
- package/dist/cjs/spec.types.js.map +1 -1
- package/dist/cjs/types.d.ts +3580 -23866
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/cjs/types.js +574 -340
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/validation/cfworker-provider.d.ts +0 -1
- package/dist/cjs/validation/cfworker-provider.d.ts.map +1 -1
- package/dist/cjs/validation/cfworker-provider.js +0 -1
- package/dist/cjs/validation/cfworker-provider.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 +122 -662
- package/dist/esm/client/index.d.ts.map +1 -1
- package/dist/esm/client/index.js +71 -15
- 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 +14 -2
- package/dist/esm/client/streamableHttp.d.ts.map +1 -1
- package/dist/esm/client/streamableHttp.js +79 -19
- 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 +11 -6
- package/dist/esm/examples/client/simpleStreamableHttp.js.map +1 -1
- package/dist/esm/examples/client/ssePollingClient.d.ts +2 -0
- package/dist/esm/examples/client/ssePollingClient.d.ts.map +1 -0
- package/dist/esm/examples/client/ssePollingClient.js +93 -0
- package/dist/esm/examples/client/ssePollingClient.js.map +1 -0
- 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} +14 -8
- 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/ssePollingExample.d.ts +2 -0
- package/dist/esm/examples/server/ssePollingExample.d.ts.map +1 -0
- package/dist/esm/examples/server/ssePollingExample.js +111 -0
- package/dist/esm/examples/server/ssePollingExample.js.map +1 -0
- 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 +176 -50
- package/dist/esm/server/index.d.ts.map +1 -1
- package/dist/esm/server/index.js +99 -13
- 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 +84 -41
- package/dist/esm/server/mcp.js.map +1 -1
- package/dist/esm/server/streamableHttp.d.ts +27 -0
- package/dist/esm/server/streamableHttp.d.ts.map +1 -1
- package/dist/esm/server/streamableHttp.js +70 -5
- package/dist/esm/server/streamableHttp.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/protocol.d.ts +5 -9
- package/dist/esm/shared/protocol.d.ts.map +1 -1
- package/dist/esm/shared/protocol.js +24 -10
- package/dist/esm/shared/protocol.js.map +1 -1
- package/dist/esm/shared/transport.d.ts +14 -0
- 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 +393 -70
- package/dist/esm/spec.types.d.ts.map +1 -1
- package/dist/esm/spec.types.js +4 -6
- package/dist/esm/spec.types.js.map +1 -1
- package/dist/esm/types.d.ts +3580 -23866
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js +282 -72
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/validation/cfworker-provider.d.ts +0 -1
- package/dist/esm/validation/cfworker-provider.d.ts.map +1 -1
- package/dist/esm/validation/cfworker-provider.js +0 -1
- package/dist/esm/validation/cfworker-provider.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,4 +1,4 @@
|
|
|
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'];
|
|
@@ -18,21 +18,16 @@ export const ProgressTokenSchema = z.union([z.string(), z.number().int()]);
|
|
|
18
18
|
* An opaque token used to represent a cursor for pagination.
|
|
19
19
|
*/
|
|
20
20
|
export const CursorSchema = z.string();
|
|
21
|
-
const RequestMetaSchema = z
|
|
22
|
-
.object({
|
|
21
|
+
const RequestMetaSchema = z.looseObject({
|
|
23
22
|
/**
|
|
24
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.
|
|
25
24
|
*/
|
|
26
25
|
progressToken: ProgressTokenSchema.optional()
|
|
27
|
-
})
|
|
28
|
-
/**
|
|
29
|
-
* Passthrough required here because we want to allow any additional fields to be added to the request meta.
|
|
30
|
-
*/
|
|
31
|
-
.passthrough();
|
|
26
|
+
});
|
|
32
27
|
/**
|
|
33
28
|
* Common params for any request.
|
|
34
29
|
*/
|
|
35
|
-
const BaseRequestParamsSchema = z.
|
|
30
|
+
const BaseRequestParamsSchema = z.looseObject({
|
|
36
31
|
/**
|
|
37
32
|
* See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage.
|
|
38
33
|
*/
|
|
@@ -40,9 +35,9 @@ const BaseRequestParamsSchema = z.object({
|
|
|
40
35
|
});
|
|
41
36
|
export const RequestSchema = z.object({
|
|
42
37
|
method: z.string(),
|
|
43
|
-
params: BaseRequestParamsSchema.
|
|
38
|
+
params: BaseRequestParamsSchema.optional()
|
|
44
39
|
});
|
|
45
|
-
const NotificationsParamsSchema = z.
|
|
40
|
+
const NotificationsParamsSchema = z.looseObject({
|
|
46
41
|
/**
|
|
47
42
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
48
43
|
* for notes on _meta usage.
|
|
@@ -51,20 +46,15 @@ const NotificationsParamsSchema = z.object({
|
|
|
51
46
|
});
|
|
52
47
|
export const NotificationSchema = z.object({
|
|
53
48
|
method: z.string(),
|
|
54
|
-
params: NotificationsParamsSchema.
|
|
49
|
+
params: NotificationsParamsSchema.optional()
|
|
55
50
|
});
|
|
56
|
-
export const ResultSchema = z
|
|
57
|
-
.object({
|
|
51
|
+
export const ResultSchema = z.looseObject({
|
|
58
52
|
/**
|
|
59
53
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
60
54
|
* for notes on _meta usage.
|
|
61
55
|
*/
|
|
62
56
|
_meta: z.record(z.string(), z.unknown()).optional()
|
|
63
|
-
})
|
|
64
|
-
/**
|
|
65
|
-
* Passthrough required here because we want to allow any additional fields to be added to the result.
|
|
66
|
-
*/
|
|
67
|
-
.passthrough();
|
|
57
|
+
});
|
|
68
58
|
/**
|
|
69
59
|
* A uniquely identifying ID for a request in JSON-RPC.
|
|
70
60
|
*/
|
|
@@ -75,9 +65,9 @@ export const RequestIdSchema = z.union([z.string(), z.number().int()]);
|
|
|
75
65
|
export const JSONRPCRequestSchema = z
|
|
76
66
|
.object({
|
|
77
67
|
jsonrpc: z.literal(JSONRPC_VERSION),
|
|
78
|
-
id: RequestIdSchema
|
|
68
|
+
id: RequestIdSchema,
|
|
69
|
+
...RequestSchema.shape
|
|
79
70
|
})
|
|
80
|
-
.merge(RequestSchema)
|
|
81
71
|
.strict();
|
|
82
72
|
export const isJSONRPCRequest = (value) => JSONRPCRequestSchema.safeParse(value).success;
|
|
83
73
|
/**
|
|
@@ -85,9 +75,9 @@ export const isJSONRPCRequest = (value) => JSONRPCRequestSchema.safeParse(value)
|
|
|
85
75
|
*/
|
|
86
76
|
export const JSONRPCNotificationSchema = z
|
|
87
77
|
.object({
|
|
88
|
-
jsonrpc: z.literal(JSONRPC_VERSION)
|
|
78
|
+
jsonrpc: z.literal(JSONRPC_VERSION),
|
|
79
|
+
...NotificationSchema.shape
|
|
89
80
|
})
|
|
90
|
-
.merge(NotificationSchema)
|
|
91
81
|
.strict();
|
|
92
82
|
export const isJSONRPCNotification = (value) => JSONRPCNotificationSchema.safeParse(value).success;
|
|
93
83
|
/**
|
|
@@ -115,6 +105,8 @@ export var ErrorCode;
|
|
|
115
105
|
ErrorCode[ErrorCode["MethodNotFound"] = -32601] = "MethodNotFound";
|
|
116
106
|
ErrorCode[ErrorCode["InvalidParams"] = -32602] = "InvalidParams";
|
|
117
107
|
ErrorCode[ErrorCode["InternalError"] = -32603] = "InternalError";
|
|
108
|
+
// MCP-specific error codes
|
|
109
|
+
ErrorCode[ErrorCode["UrlElicitationRequired"] = -32042] = "UrlElicitationRequired";
|
|
118
110
|
})(ErrorCode || (ErrorCode = {}));
|
|
119
111
|
/**
|
|
120
112
|
* A response to a request that indicates an error occurred.
|
|
@@ -232,12 +224,28 @@ export const BaseMetadataSchema = z.object({
|
|
|
232
224
|
* Describes the name and version of an MCP implementation.
|
|
233
225
|
*/
|
|
234
226
|
export const ImplementationSchema = BaseMetadataSchema.extend({
|
|
227
|
+
...BaseMetadataSchema.shape,
|
|
228
|
+
...IconsSchema.shape,
|
|
235
229
|
version: z.string(),
|
|
236
230
|
/**
|
|
237
231
|
* An optional URL of the website for this implementation.
|
|
238
232
|
*/
|
|
239
233
|
websiteUrl: z.string().optional()
|
|
240
|
-
})
|
|
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()));
|
|
241
249
|
/**
|
|
242
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.
|
|
243
251
|
*/
|
|
@@ -249,18 +257,23 @@ export const ClientCapabilitiesSchema = z.object({
|
|
|
249
257
|
/**
|
|
250
258
|
* Present if the client supports sampling from an LLM.
|
|
251
259
|
*/
|
|
252
|
-
sampling:
|
|
253
|
-
/**
|
|
254
|
-
* Present if the client supports eliciting user input.
|
|
255
|
-
*/
|
|
256
|
-
elicitation: z.intersection(z
|
|
260
|
+
sampling: z
|
|
257
261
|
.object({
|
|
258
262
|
/**
|
|
259
|
-
*
|
|
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.
|
|
260
269
|
*/
|
|
261
|
-
|
|
270
|
+
tools: AssertObjectSchema.optional()
|
|
262
271
|
})
|
|
263
|
-
.optional(),
|
|
272
|
+
.optional(),
|
|
273
|
+
/**
|
|
274
|
+
* Present if the client supports eliciting user input.
|
|
275
|
+
*/
|
|
276
|
+
elicitation: ElicitationCapabilitySchema.optional(),
|
|
264
277
|
/**
|
|
265
278
|
* Present if the client supports listing roots.
|
|
266
279
|
*/
|
|
@@ -387,7 +400,9 @@ export const ProgressSchema = z.object({
|
|
|
387
400
|
*/
|
|
388
401
|
message: z.optional(z.string())
|
|
389
402
|
});
|
|
390
|
-
export const ProgressNotificationParamsSchema =
|
|
403
|
+
export const ProgressNotificationParamsSchema = z.object({
|
|
404
|
+
...NotificationsParamsSchema.shape,
|
|
405
|
+
...ProgressSchema.shape,
|
|
391
406
|
/**
|
|
392
407
|
* The progress token which was given in the initial request, used to associate this notification with the request that is proceeding.
|
|
393
408
|
*/
|
|
@@ -470,7 +485,9 @@ export const BlobResourceContentsSchema = ResourceContentsSchema.extend({
|
|
|
470
485
|
/**
|
|
471
486
|
* A known resource that the server is capable of reading.
|
|
472
487
|
*/
|
|
473
|
-
export const ResourceSchema =
|
|
488
|
+
export const ResourceSchema = z.object({
|
|
489
|
+
...BaseMetadataSchema.shape,
|
|
490
|
+
...IconsSchema.shape,
|
|
474
491
|
/**
|
|
475
492
|
* The URI of this resource.
|
|
476
493
|
*/
|
|
@@ -489,12 +506,14 @@ export const ResourceSchema = BaseMetadataSchema.extend({
|
|
|
489
506
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
490
507
|
* for notes on _meta usage.
|
|
491
508
|
*/
|
|
492
|
-
_meta: z.optional(z.
|
|
493
|
-
})
|
|
509
|
+
_meta: z.optional(z.looseObject({}))
|
|
510
|
+
});
|
|
494
511
|
/**
|
|
495
512
|
* A template description for resources available on the server.
|
|
496
513
|
*/
|
|
497
|
-
export const ResourceTemplateSchema =
|
|
514
|
+
export const ResourceTemplateSchema = z.object({
|
|
515
|
+
...BaseMetadataSchema.shape,
|
|
516
|
+
...IconsSchema.shape,
|
|
498
517
|
/**
|
|
499
518
|
* A URI template (according to RFC 6570) that can be used to construct resource URIs.
|
|
500
519
|
*/
|
|
@@ -513,8 +532,8 @@ export const ResourceTemplateSchema = BaseMetadataSchema.extend({
|
|
|
513
532
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
514
533
|
* for notes on _meta usage.
|
|
515
534
|
*/
|
|
516
|
-
_meta: z.optional(z.
|
|
517
|
-
})
|
|
535
|
+
_meta: z.optional(z.looseObject({}))
|
|
536
|
+
});
|
|
518
537
|
/**
|
|
519
538
|
* Sent from the client to request a list of resources the server has.
|
|
520
539
|
*/
|
|
@@ -623,7 +642,9 @@ export const PromptArgumentSchema = z.object({
|
|
|
623
642
|
/**
|
|
624
643
|
* A prompt or prompt template that the server offers.
|
|
625
644
|
*/
|
|
626
|
-
export const PromptSchema =
|
|
645
|
+
export const PromptSchema = z.object({
|
|
646
|
+
...BaseMetadataSchema.shape,
|
|
647
|
+
...IconsSchema.shape,
|
|
627
648
|
/**
|
|
628
649
|
* An optional description of what this prompt provides
|
|
629
650
|
*/
|
|
@@ -636,8 +657,8 @@ export const PromptSchema = BaseMetadataSchema.extend({
|
|
|
636
657
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
637
658
|
* for notes on _meta usage.
|
|
638
659
|
*/
|
|
639
|
-
_meta: z.optional(z.
|
|
640
|
-
})
|
|
660
|
+
_meta: z.optional(z.looseObject({}))
|
|
661
|
+
});
|
|
641
662
|
/**
|
|
642
663
|
* Sent from the client to request a list of prompts and prompt templates the server has.
|
|
643
664
|
*/
|
|
@@ -723,6 +744,35 @@ export const AudioContentSchema = z.object({
|
|
|
723
744
|
*/
|
|
724
745
|
_meta: z.record(z.string(), z.unknown()).optional()
|
|
725
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(),
|
|
769
|
+
/**
|
|
770
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
771
|
+
* for notes on _meta usage.
|
|
772
|
+
*/
|
|
773
|
+
_meta: z.optional(z.object({}).passthrough())
|
|
774
|
+
})
|
|
775
|
+
.passthrough();
|
|
726
776
|
/**
|
|
727
777
|
* The contents of a resource, embedded into a prompt or tool call result.
|
|
728
778
|
*/
|
|
@@ -829,33 +879,36 @@ export const ToolAnnotationsSchema = z.object({
|
|
|
829
879
|
/**
|
|
830
880
|
* Definition for a tool the client can call.
|
|
831
881
|
*/
|
|
832
|
-
export const ToolSchema =
|
|
882
|
+
export const ToolSchema = z.object({
|
|
883
|
+
...BaseMetadataSchema.shape,
|
|
884
|
+
...IconsSchema.shape,
|
|
833
885
|
/**
|
|
834
886
|
* A human-readable description of the tool.
|
|
835
887
|
*/
|
|
836
888
|
description: z.string().optional(),
|
|
837
889
|
/**
|
|
838
|
-
* A JSON Schema object defining the expected parameters for the tool.
|
|
890
|
+
* A JSON Schema 2020-12 object defining the expected parameters for the tool.
|
|
891
|
+
* Must have type: 'object' at the root level per MCP spec.
|
|
839
892
|
*/
|
|
840
|
-
inputSchema: z
|
|
893
|
+
inputSchema: z
|
|
894
|
+
.object({
|
|
841
895
|
type: z.literal('object'),
|
|
842
896
|
properties: z.record(z.string(), AssertObjectSchema).optional(),
|
|
843
|
-
required: z.
|
|
844
|
-
})
|
|
897
|
+
required: z.array(z.string()).optional()
|
|
898
|
+
})
|
|
899
|
+
.catchall(z.unknown()),
|
|
845
900
|
/**
|
|
846
|
-
* An optional JSON Schema object defining the structure of the tool's output
|
|
847
|
-
* the structuredContent field of a CallToolResult.
|
|
901
|
+
* An optional JSON Schema 2020-12 object defining the structure of the tool's output
|
|
902
|
+
* returned in the structuredContent field of a CallToolResult.
|
|
903
|
+
* Must have type: 'object' at the root level per MCP spec.
|
|
848
904
|
*/
|
|
849
905
|
outputSchema: z
|
|
850
906
|
.object({
|
|
851
907
|
type: z.literal('object'),
|
|
852
908
|
properties: z.record(z.string(), AssertObjectSchema).optional(),
|
|
853
|
-
required: z.
|
|
854
|
-
/**
|
|
855
|
-
* Not in the MCP specification, but added to support the Ajv validator while removing .passthrough() which previously allowed additionalProperties to be passed through.
|
|
856
|
-
*/
|
|
857
|
-
additionalProperties: z.optional(z.boolean())
|
|
909
|
+
required: z.array(z.string()).optional()
|
|
858
910
|
})
|
|
911
|
+
.catchall(z.unknown())
|
|
859
912
|
.optional(),
|
|
860
913
|
/**
|
|
861
914
|
* Optional additional tool information.
|
|
@@ -866,7 +919,7 @@ export const ToolSchema = BaseMetadataSchema.extend({
|
|
|
866
919
|
* for notes on _meta usage.
|
|
867
920
|
*/
|
|
868
921
|
_meta: z.record(z.string(), z.unknown()).optional()
|
|
869
|
-
})
|
|
922
|
+
});
|
|
870
923
|
/**
|
|
871
924
|
* Sent from the client to request a list of tools the server has.
|
|
872
925
|
*/
|
|
@@ -1020,13 +1073,61 @@ export const ModelPreferencesSchema = z.object({
|
|
|
1020
1073
|
*/
|
|
1021
1074
|
intelligencePriority: z.optional(z.number().min(0).max(1))
|
|
1022
1075
|
});
|
|
1076
|
+
/**
|
|
1077
|
+
* Controls tool usage behavior in sampling requests.
|
|
1078
|
+
*/
|
|
1079
|
+
export const ToolChoiceSchema = z.object({
|
|
1080
|
+
/**
|
|
1081
|
+
* Controls when tools are used:
|
|
1082
|
+
* - "auto": Model decides whether to use tools (default)
|
|
1083
|
+
* - "required": Model MUST use at least one tool before completing
|
|
1084
|
+
* - "none": Model MUST NOT use any tools
|
|
1085
|
+
*/
|
|
1086
|
+
mode: z.optional(z.enum(['auto', 'required', 'none']))
|
|
1087
|
+
});
|
|
1088
|
+
/**
|
|
1089
|
+
* The result of a tool execution, provided by the user (server).
|
|
1090
|
+
* Represents the outcome of invoking a tool requested via ToolUseContent.
|
|
1091
|
+
*/
|
|
1092
|
+
export const ToolResultContentSchema = z
|
|
1093
|
+
.object({
|
|
1094
|
+
type: z.literal('tool_result'),
|
|
1095
|
+
toolUseId: z.string().describe('The unique identifier for the corresponding tool call.'),
|
|
1096
|
+
content: z.array(ContentBlockSchema).default([]),
|
|
1097
|
+
structuredContent: z.object({}).passthrough().optional(),
|
|
1098
|
+
isError: z.optional(z.boolean()),
|
|
1099
|
+
/**
|
|
1100
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
1101
|
+
* for notes on _meta usage.
|
|
1102
|
+
*/
|
|
1103
|
+
_meta: z.optional(z.object({}).passthrough())
|
|
1104
|
+
})
|
|
1105
|
+
.passthrough();
|
|
1106
|
+
/**
|
|
1107
|
+
* Content block types allowed in sampling messages.
|
|
1108
|
+
* This includes text, image, audio, tool use requests, and tool results.
|
|
1109
|
+
*/
|
|
1110
|
+
export const SamplingMessageContentBlockSchema = z.discriminatedUnion('type', [
|
|
1111
|
+
TextContentSchema,
|
|
1112
|
+
ImageContentSchema,
|
|
1113
|
+
AudioContentSchema,
|
|
1114
|
+
ToolUseContentSchema,
|
|
1115
|
+
ToolResultContentSchema
|
|
1116
|
+
]);
|
|
1023
1117
|
/**
|
|
1024
1118
|
* Describes a message issued to or received from an LLM API.
|
|
1025
1119
|
*/
|
|
1026
|
-
export const SamplingMessageSchema = z
|
|
1120
|
+
export const SamplingMessageSchema = z
|
|
1121
|
+
.object({
|
|
1027
1122
|
role: z.enum(['user', 'assistant']),
|
|
1028
|
-
content: z.union([
|
|
1029
|
-
|
|
1123
|
+
content: z.union([SamplingMessageContentBlockSchema, z.array(SamplingMessageContentBlockSchema)]),
|
|
1124
|
+
/**
|
|
1125
|
+
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
1126
|
+
* for notes on _meta usage.
|
|
1127
|
+
*/
|
|
1128
|
+
_meta: z.optional(z.object({}).passthrough())
|
|
1129
|
+
})
|
|
1130
|
+
.passthrough();
|
|
1030
1131
|
/**
|
|
1031
1132
|
* Parameters for a `sampling/createMessage` request.
|
|
1032
1133
|
*/
|
|
@@ -1041,7 +1142,11 @@ export const CreateMessageRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
|
1041
1142
|
*/
|
|
1042
1143
|
systemPrompt: z.string().optional(),
|
|
1043
1144
|
/**
|
|
1044
|
-
* A request to include context from one or more MCP servers (including the caller), to be attached to the prompt.
|
|
1145
|
+
* A request to include context from one or more MCP servers (including the caller), to be attached to the prompt.
|
|
1146
|
+
* The client MAY ignore this request.
|
|
1147
|
+
*
|
|
1148
|
+
* Default is "none". Values "thisServer" and "allServers" are soft-deprecated. Servers SHOULD only use these values if the client
|
|
1149
|
+
* declares ClientCapabilities.sampling.context. These values may be removed in future spec releases.
|
|
1045
1150
|
*/
|
|
1046
1151
|
includeContext: z.enum(['none', 'thisServer', 'allServers']).optional(),
|
|
1047
1152
|
temperature: z.number().optional(),
|
|
@@ -1055,7 +1160,18 @@ export const CreateMessageRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
|
1055
1160
|
/**
|
|
1056
1161
|
* Optional metadata to pass through to the LLM provider. The format of this metadata is provider-specific.
|
|
1057
1162
|
*/
|
|
1058
|
-
metadata: AssertObjectSchema.optional()
|
|
1163
|
+
metadata: AssertObjectSchema.optional(),
|
|
1164
|
+
/**
|
|
1165
|
+
* Tools that the model may use during generation.
|
|
1166
|
+
* The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
|
|
1167
|
+
*/
|
|
1168
|
+
tools: z.optional(z.array(ToolSchema)),
|
|
1169
|
+
/**
|
|
1170
|
+
* Controls how the model uses tools.
|
|
1171
|
+
* The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
|
|
1172
|
+
* Default is `{ mode: "auto" }`.
|
|
1173
|
+
*/
|
|
1174
|
+
toolChoice: z.optional(ToolChoiceSchema)
|
|
1059
1175
|
});
|
|
1060
1176
|
/**
|
|
1061
1177
|
* 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.
|
|
@@ -1073,11 +1189,22 @@ export const CreateMessageResultSchema = ResultSchema.extend({
|
|
|
1073
1189
|
*/
|
|
1074
1190
|
model: z.string(),
|
|
1075
1191
|
/**
|
|
1076
|
-
* The reason why sampling stopped.
|
|
1192
|
+
* The reason why sampling stopped, if known.
|
|
1193
|
+
*
|
|
1194
|
+
* Standard values:
|
|
1195
|
+
* - "endTurn": Natural end of the assistant's turn
|
|
1196
|
+
* - "stopSequence": A stop sequence was encountered
|
|
1197
|
+
* - "maxTokens": Maximum token limit was reached
|
|
1198
|
+
* - "toolUse": The model wants to use one or more tools
|
|
1199
|
+
*
|
|
1200
|
+
* This field is an open string to allow for provider-specific stop reasons.
|
|
1077
1201
|
*/
|
|
1078
|
-
stopReason: z.optional(z.enum(['endTurn', 'stopSequence', 'maxTokens']).or(z.string())),
|
|
1202
|
+
stopReason: z.optional(z.enum(['endTurn', 'stopSequence', 'maxTokens', 'toolUse']).or(z.string())),
|
|
1079
1203
|
role: z.enum(['user', 'assistant']),
|
|
1080
|
-
|
|
1204
|
+
/**
|
|
1205
|
+
* Response content. May be ToolUseContent if stopReason is "toolUse".
|
|
1206
|
+
*/
|
|
1207
|
+
content: z.union([SamplingMessageContentBlockSchema, z.array(SamplingMessageContentBlockSchema)])
|
|
1081
1208
|
});
|
|
1082
1209
|
/* Elicitation */
|
|
1083
1210
|
/**
|
|
@@ -1194,11 +1321,17 @@ export const EnumSchemaSchema = z.union([LegacyTitledEnumSchemaSchema, SingleSel
|
|
|
1194
1321
|
*/
|
|
1195
1322
|
export const PrimitiveSchemaDefinitionSchema = z.union([EnumSchemaSchema, BooleanSchemaSchema, StringSchemaSchema, NumberSchemaSchema]);
|
|
1196
1323
|
/**
|
|
1197
|
-
* Parameters for an `elicitation/create` request.
|
|
1324
|
+
* Parameters for an `elicitation/create` request for form-based elicitation.
|
|
1198
1325
|
*/
|
|
1199
|
-
export const
|
|
1326
|
+
export const ElicitRequestFormParamsSchema = BaseRequestParamsSchema.extend({
|
|
1327
|
+
/**
|
|
1328
|
+
* The elicitation mode.
|
|
1329
|
+
*
|
|
1330
|
+
* Optional for backward compatibility. Clients MUST treat missing mode as "form".
|
|
1331
|
+
*/
|
|
1332
|
+
mode: z.literal('form').optional(),
|
|
1200
1333
|
/**
|
|
1201
|
-
* The message to present to the user.
|
|
1334
|
+
* The message to present to the user describing what information is being requested.
|
|
1202
1335
|
*/
|
|
1203
1336
|
message: z.string(),
|
|
1204
1337
|
/**
|
|
@@ -1211,14 +1344,61 @@ export const ElicitRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
|
1211
1344
|
required: z.array(z.string()).optional()
|
|
1212
1345
|
})
|
|
1213
1346
|
});
|
|
1347
|
+
/**
|
|
1348
|
+
* Parameters for an `elicitation/create` request for URL-based elicitation.
|
|
1349
|
+
*/
|
|
1350
|
+
export const ElicitRequestURLParamsSchema = BaseRequestParamsSchema.extend({
|
|
1351
|
+
/**
|
|
1352
|
+
* The elicitation mode.
|
|
1353
|
+
*/
|
|
1354
|
+
mode: z.literal('url'),
|
|
1355
|
+
/**
|
|
1356
|
+
* The message to present to the user explaining why the interaction is needed.
|
|
1357
|
+
*/
|
|
1358
|
+
message: z.string(),
|
|
1359
|
+
/**
|
|
1360
|
+
* The ID of the elicitation, which must be unique within the context of the server.
|
|
1361
|
+
* The client MUST treat this ID as an opaque value.
|
|
1362
|
+
*/
|
|
1363
|
+
elicitationId: z.string(),
|
|
1364
|
+
/**
|
|
1365
|
+
* The URL that the user should navigate to.
|
|
1366
|
+
*/
|
|
1367
|
+
url: z.string().url()
|
|
1368
|
+
});
|
|
1369
|
+
/**
|
|
1370
|
+
* The parameters for a request to elicit additional information from the user via the client.
|
|
1371
|
+
*/
|
|
1372
|
+
export const ElicitRequestParamsSchema = z.union([ElicitRequestFormParamsSchema, ElicitRequestURLParamsSchema]);
|
|
1214
1373
|
/**
|
|
1215
1374
|
* A request from the server to elicit user input via the client.
|
|
1216
|
-
* The client should present the message and form fields to the user
|
|
1375
|
+
* The client should present the message and form fields to the user (form mode)
|
|
1376
|
+
* or navigate to a URL (URL mode).
|
|
1217
1377
|
*/
|
|
1218
1378
|
export const ElicitRequestSchema = RequestSchema.extend({
|
|
1219
1379
|
method: z.literal('elicitation/create'),
|
|
1220
1380
|
params: ElicitRequestParamsSchema
|
|
1221
1381
|
});
|
|
1382
|
+
/**
|
|
1383
|
+
* Parameters for a `notifications/elicitation/complete` notification.
|
|
1384
|
+
*
|
|
1385
|
+
* @category notifications/elicitation/complete
|
|
1386
|
+
*/
|
|
1387
|
+
export const ElicitationCompleteNotificationParamsSchema = NotificationsParamsSchema.extend({
|
|
1388
|
+
/**
|
|
1389
|
+
* The ID of the elicitation that completed.
|
|
1390
|
+
*/
|
|
1391
|
+
elicitationId: z.string()
|
|
1392
|
+
});
|
|
1393
|
+
/**
|
|
1394
|
+
* A notification from the server to the client, informing it of a completion of an out-of-band elicitation request.
|
|
1395
|
+
*
|
|
1396
|
+
* @category notifications/elicitation/complete
|
|
1397
|
+
*/
|
|
1398
|
+
export const ElicitationCompleteNotificationSchema = NotificationSchema.extend({
|
|
1399
|
+
method: z.literal('notifications/elicitation/complete'),
|
|
1400
|
+
params: ElicitationCompleteNotificationParamsSchema
|
|
1401
|
+
});
|
|
1222
1402
|
/**
|
|
1223
1403
|
* The client's response to an elicitation/create request from the server.
|
|
1224
1404
|
*/
|
|
@@ -1234,7 +1414,7 @@ export const ElicitResultSchema = ResultSchema.extend({
|
|
|
1234
1414
|
* The submitted form data, only present when action is "accept".
|
|
1235
1415
|
* Contains values matching the requested schema.
|
|
1236
1416
|
*/
|
|
1237
|
-
content: z.record(z.union([z.string(), z.number(), z.boolean(), z.array(z.string())])).optional()
|
|
1417
|
+
content: z.record(z.string(), z.union([z.string(), z.number(), z.boolean(), z.array(z.string())])).optional()
|
|
1238
1418
|
});
|
|
1239
1419
|
/* Autocomplete */
|
|
1240
1420
|
/**
|
|
@@ -1299,18 +1479,19 @@ export function assertCompleteRequestPrompt(request) {
|
|
|
1299
1479
|
if (request.params.ref.type !== 'ref/prompt') {
|
|
1300
1480
|
throw new TypeError(`Expected CompleteRequestPrompt, but got ${request.params.ref.type}`);
|
|
1301
1481
|
}
|
|
1482
|
+
void request;
|
|
1302
1483
|
}
|
|
1303
1484
|
export function assertCompleteRequestResourceTemplate(request) {
|
|
1304
1485
|
if (request.params.ref.type !== 'ref/resource') {
|
|
1305
1486
|
throw new TypeError(`Expected CompleteRequestResourceTemplate, but got ${request.params.ref.type}`);
|
|
1306
1487
|
}
|
|
1488
|
+
void request;
|
|
1307
1489
|
}
|
|
1308
1490
|
/**
|
|
1309
1491
|
* The server's response to a completion/complete request
|
|
1310
1492
|
*/
|
|
1311
1493
|
export const CompleteResultSchema = ResultSchema.extend({
|
|
1312
|
-
completion: z
|
|
1313
|
-
.object({
|
|
1494
|
+
completion: z.looseObject({
|
|
1314
1495
|
/**
|
|
1315
1496
|
* An array of completion values. Must not exceed 100 items.
|
|
1316
1497
|
*/
|
|
@@ -1324,7 +1505,6 @@ export const CompleteResultSchema = ResultSchema.extend({
|
|
|
1324
1505
|
*/
|
|
1325
1506
|
hasMore: z.optional(z.boolean())
|
|
1326
1507
|
})
|
|
1327
|
-
.passthrough()
|
|
1328
1508
|
});
|
|
1329
1509
|
/* Roots */
|
|
1330
1510
|
/**
|
|
@@ -1395,7 +1575,8 @@ export const ServerNotificationSchema = z.union([
|
|
|
1395
1575
|
ResourceUpdatedNotificationSchema,
|
|
1396
1576
|
ResourceListChangedNotificationSchema,
|
|
1397
1577
|
ToolListChangedNotificationSchema,
|
|
1398
|
-
PromptListChangedNotificationSchema
|
|
1578
|
+
PromptListChangedNotificationSchema,
|
|
1579
|
+
ElicitationCompleteNotificationSchema
|
|
1399
1580
|
]);
|
|
1400
1581
|
export const ServerResultSchema = z.union([
|
|
1401
1582
|
EmptyResultSchema,
|
|
@@ -1416,5 +1597,34 @@ export class McpError extends Error {
|
|
|
1416
1597
|
this.data = data;
|
|
1417
1598
|
this.name = 'McpError';
|
|
1418
1599
|
}
|
|
1600
|
+
/**
|
|
1601
|
+
* Factory method to create the appropriate error type based on the error code and data
|
|
1602
|
+
*/
|
|
1603
|
+
static fromError(code, message, data) {
|
|
1604
|
+
// Check for specific error types
|
|
1605
|
+
if (code === ErrorCode.UrlElicitationRequired && data) {
|
|
1606
|
+
const errorData = data;
|
|
1607
|
+
if (errorData.elicitations) {
|
|
1608
|
+
return new UrlElicitationRequiredError(errorData.elicitations, message);
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
// Default to generic McpError
|
|
1612
|
+
return new McpError(code, message, data);
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
/**
|
|
1616
|
+
* Specialized error type when a tool requires a URL mode elicitation.
|
|
1617
|
+
* 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.
|
|
1618
|
+
*/
|
|
1619
|
+
export class UrlElicitationRequiredError extends McpError {
|
|
1620
|
+
constructor(elicitations, message = `URL elicitation${elicitations.length > 1 ? 's' : ''} required`) {
|
|
1621
|
+
super(ErrorCode.UrlElicitationRequired, message, {
|
|
1622
|
+
elicitations: elicitations
|
|
1623
|
+
});
|
|
1624
|
+
}
|
|
1625
|
+
get elicitations() {
|
|
1626
|
+
var _a, _b;
|
|
1627
|
+
return (_b = (_a = this.data) === null || _a === void 0 ? void 0 : _a.elicitations) !== null && _b !== void 0 ? _b : [];
|
|
1628
|
+
}
|
|
1419
1629
|
}
|
|
1420
1630
|
//# sourceMappingURL=types.js.map
|