@modelcontextprotocol/sdk 1.24.3 → 1.25.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/client/auth-extensions.js +5 -9
- package/dist/cjs/client/auth-extensions.js.map +1 -1
- package/dist/cjs/client/auth.js +30 -37
- package/dist/cjs/client/auth.js.map +1 -1
- package/dist/cjs/client/index.d.ts +61 -14
- package/dist/cjs/client/index.d.ts.map +1 -1
- package/dist/cjs/client/index.js +117 -36
- package/dist/cjs/client/index.js.map +1 -1
- package/dist/cjs/client/middleware.js +3 -3
- package/dist/cjs/client/middleware.js.map +1 -1
- package/dist/cjs/client/sse.js +19 -27
- package/dist/cjs/client/sse.js.map +1 -1
- package/dist/cjs/client/stdio.js +18 -28
- package/dist/cjs/client/stdio.js.map +1 -1
- package/dist/cjs/client/streamableHttp.d.ts.map +1 -1
- package/dist/cjs/client/streamableHttp.js +39 -49
- package/dist/cjs/client/streamableHttp.js.map +1 -1
- package/dist/cjs/client/websocket.js +6 -11
- package/dist/cjs/client/websocket.js.map +1 -1
- package/dist/cjs/examples/client/elicitationUrlExample.js +4 -5
- package/dist/cjs/examples/client/elicitationUrlExample.js.map +1 -1
- package/dist/cjs/examples/client/simpleOAuthClient.js +3 -3
- package/dist/cjs/examples/client/simpleOAuthClient.js.map +1 -1
- package/dist/cjs/examples/client/simpleStreamableHttp.js +7 -9
- package/dist/cjs/examples/client/simpleStreamableHttp.js.map +1 -1
- package/dist/cjs/examples/client/simpleTaskInteractiveClient.js +1 -2
- package/dist/cjs/examples/client/simpleTaskInteractiveClient.js.map +1 -1
- package/dist/cjs/examples/server/honoWebStandardStreamableHttp.d.ts +10 -0
- package/dist/cjs/examples/server/honoWebStandardStreamableHttp.d.ts.map +1 -0
- package/dist/cjs/examples/server/honoWebStandardStreamableHttp.js +81 -0
- package/dist/cjs/examples/server/honoWebStandardStreamableHttp.js.map +1 -0
- package/dist/cjs/examples/server/jsonResponseStreamableHttp.js +10 -4
- package/dist/cjs/examples/server/jsonResponseStreamableHttp.js.map +1 -1
- package/dist/cjs/examples/server/simpleSseServer.js +6 -3
- package/dist/cjs/examples/server/simpleSseServer.js.map +1 -1
- package/dist/cjs/examples/server/simpleStatelessStreamableHttp.js +12 -6
- package/dist/cjs/examples/server/simpleStatelessStreamableHttp.js.map +1 -1
- package/dist/cjs/examples/server/simpleStreamableHttp.js +21 -11
- package/dist/cjs/examples/server/simpleStreamableHttp.js.map +1 -1
- package/dist/cjs/examples/server/simpleTaskInteractive.js +7 -11
- package/dist/cjs/examples/server/simpleTaskInteractive.js.map +1 -1
- package/dist/cjs/examples/server/sseAndStreamableHttpCompatibleServer.js +10 -7
- package/dist/cjs/examples/server/sseAndStreamableHttpCompatibleServer.js.map +1 -1
- package/dist/cjs/examples/server/standaloneSseWithGetStreamableHttp.js +1 -1
- package/dist/cjs/examples/server/standaloneSseWithGetStreamableHttp.js.map +1 -1
- package/dist/cjs/experimental/tasks/client.js +1 -2
- package/dist/cjs/experimental/tasks/client.js.map +1 -1
- package/dist/cjs/experimental/tasks/helpers.js +3 -5
- package/dist/cjs/experimental/tasks/helpers.js.map +1 -1
- package/dist/cjs/experimental/tasks/interfaces.d.ts +3 -3
- package/dist/cjs/experimental/tasks/interfaces.d.ts.map +1 -1
- package/dist/cjs/experimental/tasks/stores/in-memory.d.ts +1 -1
- package/dist/cjs/experimental/tasks/stores/in-memory.d.ts.map +1 -1
- package/dist/cjs/experimental/tasks/stores/in-memory.js +3 -5
- package/dist/cjs/experimental/tasks/stores/in-memory.js.map +1 -1
- package/dist/cjs/inMemory.js +5 -7
- package/dist/cjs/inMemory.js.map +1 -1
- package/dist/cjs/server/auth/handlers/token.js +1 -1
- package/dist/cjs/server/auth/handlers/token.js.map +1 -1
- package/dist/cjs/server/auth/providers/proxyProvider.js +11 -17
- package/dist/cjs/server/auth/providers/proxyProvider.js.map +1 -1
- package/dist/cjs/server/auth/router.js +3 -6
- package/dist/cjs/server/auth/router.js.map +1 -1
- package/dist/cjs/server/completable.js +1 -1
- package/dist/cjs/server/completable.js.map +1 -1
- package/dist/cjs/server/index.d.ts +3 -3
- package/dist/cjs/server/index.d.ts.map +1 -1
- package/dist/cjs/server/index.js +20 -30
- package/dist/cjs/server/index.js.map +1 -1
- package/dist/cjs/server/mcp.d.ts.map +1 -1
- package/dist/cjs/server/mcp.js +25 -11
- package/dist/cjs/server/mcp.js.map +1 -1
- package/dist/cjs/server/middleware/hostHeaderValidation.js +1 -1
- package/dist/cjs/server/middleware/hostHeaderValidation.js.map +1 -1
- package/dist/cjs/server/sse.js +14 -17
- package/dist/cjs/server/sse.js.map +1 -1
- package/dist/cjs/server/stdio.js +4 -7
- package/dist/cjs/server/stdio.js.map +1 -1
- package/dist/cjs/server/streamableHttp.d.ts +52 -154
- package/dist/cjs/server/streamableHttp.d.ts.map +1 -1
- package/dist/cjs/server/streamableHttp.js +78 -653
- package/dist/cjs/server/streamableHttp.js.map +1 -1
- package/dist/cjs/server/webStandardStreamableHttp.d.ts +267 -0
- package/dist/cjs/server/webStandardStreamableHttp.d.ts.map +1 -0
- package/dist/cjs/server/webStandardStreamableHttp.js +729 -0
- package/dist/cjs/server/webStandardStreamableHttp.js.map +1 -0
- package/dist/cjs/server/zod-compat.d.ts +3 -1
- package/dist/cjs/server/zod-compat.d.ts.map +1 -1
- package/dist/cjs/server/zod-compat.js +11 -19
- package/dist/cjs/server/zod-compat.js.map +1 -1
- package/dist/cjs/server/zod-json-schema-compat.js +5 -6
- package/dist/cjs/server/zod-json-schema-compat.js.map +1 -1
- package/dist/cjs/shared/metadataUtils.js +1 -2
- package/dist/cjs/shared/metadataUtils.js.map +1 -1
- package/dist/cjs/shared/protocol.d.ts +1 -1
- package/dist/cjs/shared/protocol.d.ts.map +1 -1
- package/dist/cjs/shared/protocol.js +76 -88
- package/dist/cjs/shared/protocol.js.map +1 -1
- package/dist/cjs/shared/transport.js +1 -1
- package/dist/cjs/shared/transport.js.map +1 -1
- package/dist/cjs/spec.types.d.ts +315 -26
- package/dist/cjs/spec.types.d.ts.map +1 -1
- package/dist/cjs/spec.types.js +2 -2
- package/dist/cjs/spec.types.js.map +1 -1
- package/dist/cjs/types.d.ts +1424 -1240
- package/dist/cjs/types.d.ts.map +1 -1
- package/dist/cjs/types.js +227 -136
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/validation/ajv-provider.d.ts +1 -1
- package/dist/cjs/validation/ajv-provider.d.ts.map +1 -1
- package/dist/cjs/validation/ajv-provider.js +4 -5
- package/dist/cjs/validation/ajv-provider.js.map +1 -1
- package/dist/cjs/validation/cfworker-provider.js +4 -5
- package/dist/cjs/validation/cfworker-provider.js.map +1 -1
- package/dist/cjs/validation/types.d.ts +12 -2
- package/dist/cjs/validation/types.d.ts.map +1 -1
- package/dist/esm/client/auth-extensions.js +5 -9
- package/dist/esm/client/auth-extensions.js.map +1 -1
- package/dist/esm/client/auth.js +30 -37
- package/dist/esm/client/auth.js.map +1 -1
- package/dist/esm/client/index.d.ts +61 -14
- package/dist/esm/client/index.d.ts.map +1 -1
- package/dist/esm/client/index.js +118 -37
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/client/middleware.js +3 -3
- package/dist/esm/client/middleware.js.map +1 -1
- package/dist/esm/client/sse.js +19 -27
- package/dist/esm/client/sse.js.map +1 -1
- package/dist/esm/client/stdio.js +18 -28
- package/dist/esm/client/stdio.js.map +1 -1
- package/dist/esm/client/streamableHttp.d.ts.map +1 -1
- package/dist/esm/client/streamableHttp.js +40 -50
- package/dist/esm/client/streamableHttp.js.map +1 -1
- package/dist/esm/client/websocket.js +6 -11
- package/dist/esm/client/websocket.js.map +1 -1
- package/dist/esm/examples/client/elicitationUrlExample.js +4 -5
- package/dist/esm/examples/client/elicitationUrlExample.js.map +1 -1
- package/dist/esm/examples/client/simpleOAuthClient.js +3 -3
- package/dist/esm/examples/client/simpleOAuthClient.js.map +1 -1
- package/dist/esm/examples/client/simpleStreamableHttp.js +7 -9
- package/dist/esm/examples/client/simpleStreamableHttp.js.map +1 -1
- package/dist/esm/examples/client/simpleTaskInteractiveClient.js +1 -2
- package/dist/esm/examples/client/simpleTaskInteractiveClient.js.map +1 -1
- package/dist/esm/examples/server/honoWebStandardStreamableHttp.d.ts +10 -0
- package/dist/esm/examples/server/honoWebStandardStreamableHttp.d.ts.map +1 -0
- package/dist/esm/examples/server/honoWebStandardStreamableHttp.js +56 -0
- package/dist/esm/examples/server/honoWebStandardStreamableHttp.js.map +1 -0
- package/dist/esm/examples/server/jsonResponseStreamableHttp.js +10 -4
- package/dist/esm/examples/server/jsonResponseStreamableHttp.js.map +1 -1
- package/dist/esm/examples/server/simpleSseServer.js +6 -3
- package/dist/esm/examples/server/simpleSseServer.js.map +1 -1
- package/dist/esm/examples/server/simpleStatelessStreamableHttp.js +12 -6
- package/dist/esm/examples/server/simpleStatelessStreamableHttp.js.map +1 -1
- package/dist/esm/examples/server/simpleStreamableHttp.js +21 -11
- package/dist/esm/examples/server/simpleStreamableHttp.js.map +1 -1
- package/dist/esm/examples/server/simpleTaskInteractive.js +7 -11
- package/dist/esm/examples/server/simpleTaskInteractive.js.map +1 -1
- package/dist/esm/examples/server/sseAndStreamableHttpCompatibleServer.js +10 -7
- package/dist/esm/examples/server/sseAndStreamableHttpCompatibleServer.js.map +1 -1
- package/dist/esm/examples/server/standaloneSseWithGetStreamableHttp.js +1 -1
- package/dist/esm/examples/server/standaloneSseWithGetStreamableHttp.js.map +1 -1
- package/dist/esm/experimental/tasks/client.js +1 -2
- package/dist/esm/experimental/tasks/client.js.map +1 -1
- package/dist/esm/experimental/tasks/helpers.js +3 -5
- package/dist/esm/experimental/tasks/helpers.js.map +1 -1
- package/dist/esm/experimental/tasks/interfaces.d.ts +3 -3
- package/dist/esm/experimental/tasks/interfaces.d.ts.map +1 -1
- package/dist/esm/experimental/tasks/stores/in-memory.d.ts +1 -1
- package/dist/esm/experimental/tasks/stores/in-memory.d.ts.map +1 -1
- package/dist/esm/experimental/tasks/stores/in-memory.js +3 -5
- package/dist/esm/experimental/tasks/stores/in-memory.js.map +1 -1
- package/dist/esm/inMemory.js +5 -7
- package/dist/esm/inMemory.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/providers/proxyProvider.js +11 -17
- package/dist/esm/server/auth/providers/proxyProvider.js.map +1 -1
- package/dist/esm/server/auth/router.js +3 -6
- package/dist/esm/server/auth/router.js.map +1 -1
- package/dist/esm/server/completable.js +1 -1
- package/dist/esm/server/completable.js.map +1 -1
- package/dist/esm/server/index.d.ts +3 -3
- package/dist/esm/server/index.d.ts.map +1 -1
- package/dist/esm/server/index.js +20 -30
- package/dist/esm/server/index.js.map +1 -1
- package/dist/esm/server/mcp.d.ts.map +1 -1
- package/dist/esm/server/mcp.js +25 -11
- package/dist/esm/server/mcp.js.map +1 -1
- package/dist/esm/server/middleware/hostHeaderValidation.js +1 -1
- package/dist/esm/server/middleware/hostHeaderValidation.js.map +1 -1
- package/dist/esm/server/sse.js +14 -17
- package/dist/esm/server/sse.js.map +1 -1
- package/dist/esm/server/stdio.js +4 -7
- package/dist/esm/server/stdio.js.map +1 -1
- package/dist/esm/server/streamableHttp.d.ts +52 -154
- package/dist/esm/server/streamableHttp.d.ts.map +1 -1
- package/dist/esm/server/streamableHttp.js +78 -650
- package/dist/esm/server/streamableHttp.js.map +1 -1
- package/dist/esm/server/webStandardStreamableHttp.d.ts +267 -0
- package/dist/esm/server/webStandardStreamableHttp.d.ts.map +1 -0
- package/dist/esm/server/webStandardStreamableHttp.js +725 -0
- package/dist/esm/server/webStandardStreamableHttp.js.map +1 -0
- package/dist/esm/server/zod-compat.d.ts +3 -1
- package/dist/esm/server/zod-compat.d.ts.map +1 -1
- package/dist/esm/server/zod-compat.js +11 -19
- package/dist/esm/server/zod-compat.js.map +1 -1
- package/dist/esm/server/zod-json-schema-compat.js +5 -6
- package/dist/esm/server/zod-json-schema-compat.js.map +1 -1
- package/dist/esm/shared/metadataUtils.js +1 -2
- package/dist/esm/shared/metadataUtils.js.map +1 -1
- package/dist/esm/shared/protocol.d.ts +1 -1
- package/dist/esm/shared/protocol.d.ts.map +1 -1
- package/dist/esm/shared/protocol.js +77 -89
- package/dist/esm/shared/protocol.js.map +1 -1
- package/dist/esm/shared/transport.js +1 -1
- package/dist/esm/shared/transport.js.map +1 -1
- package/dist/esm/spec.types.d.ts +315 -26
- package/dist/esm/spec.types.d.ts.map +1 -1
- package/dist/esm/spec.types.js +2 -2
- package/dist/esm/spec.types.js.map +1 -1
- package/dist/esm/types.d.ts +1430 -1246
- package/dist/esm/types.d.ts.map +1 -1
- package/dist/esm/types.js +220 -130
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/validation/ajv-provider.d.ts +1 -1
- package/dist/esm/validation/ajv-provider.d.ts.map +1 -1
- package/dist/esm/validation/ajv-provider.js +3 -4
- package/dist/esm/validation/ajv-provider.js.map +1 -1
- package/dist/esm/validation/cfworker-provider.js +4 -5
- package/dist/esm/validation/cfworker-provider.js.map +1 -1
- package/dist/esm/validation/types.d.ts +12 -2
- package/dist/esm/validation/types.d.ts.map +1 -1
- package/package.json +3 -1
package/dist/esm/types.js
CHANGED
|
@@ -33,10 +33,14 @@ export const TaskCreationParamsSchema = z.looseObject({
|
|
|
33
33
|
*/
|
|
34
34
|
pollInterval: z.number().optional()
|
|
35
35
|
});
|
|
36
|
+
export const TaskMetadataSchema = z.object({
|
|
37
|
+
ttl: z.number().optional()
|
|
38
|
+
});
|
|
36
39
|
/**
|
|
37
|
-
*
|
|
40
|
+
* Metadata for associating messages with a task.
|
|
41
|
+
* Include this in the `_meta` field under the key `io.modelcontextprotocol/related-task`.
|
|
38
42
|
*/
|
|
39
|
-
export const RelatedTaskMetadataSchema = z.
|
|
43
|
+
export const RelatedTaskMetadataSchema = z.object({
|
|
40
44
|
taskId: z.string()
|
|
41
45
|
});
|
|
42
46
|
const RequestMetaSchema = z.looseObject({
|
|
@@ -52,53 +56,54 @@ const RequestMetaSchema = z.looseObject({
|
|
|
52
56
|
/**
|
|
53
57
|
* Common params for any request.
|
|
54
58
|
*/
|
|
55
|
-
const BaseRequestParamsSchema = z.
|
|
56
|
-
/**
|
|
57
|
-
* If specified, the caller is requesting that the receiver create a task to represent the request.
|
|
58
|
-
* Task creation parameters are now at the top level instead of in _meta.
|
|
59
|
-
*/
|
|
60
|
-
task: TaskCreationParamsSchema.optional(),
|
|
59
|
+
const BaseRequestParamsSchema = z.object({
|
|
61
60
|
/**
|
|
62
61
|
* See [General fields: `_meta`](/specification/draft/basic/index#meta) for notes on `_meta` usage.
|
|
63
62
|
*/
|
|
64
63
|
_meta: RequestMetaSchema.optional()
|
|
65
64
|
});
|
|
65
|
+
/**
|
|
66
|
+
* Common params for any task-augmented request.
|
|
67
|
+
*/
|
|
68
|
+
export const TaskAugmentedRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
69
|
+
/**
|
|
70
|
+
* If specified, the caller is requesting task-augmented execution for this request.
|
|
71
|
+
* The request will return a CreateTaskResult immediately, and the actual result can be
|
|
72
|
+
* retrieved later via tasks/result.
|
|
73
|
+
*
|
|
74
|
+
* Task augmentation is subject to capability negotiation - receivers MUST declare support
|
|
75
|
+
* for task augmentation of specific request types in their capabilities.
|
|
76
|
+
*/
|
|
77
|
+
task: TaskMetadataSchema.optional()
|
|
78
|
+
});
|
|
79
|
+
/**
|
|
80
|
+
* Checks if a value is a valid TaskAugmentedRequestParams.
|
|
81
|
+
* @param value - The value to check.
|
|
82
|
+
*
|
|
83
|
+
* @returns True if the value is a valid TaskAugmentedRequestParams, false otherwise.
|
|
84
|
+
*/
|
|
85
|
+
export const isTaskAugmentedRequestParams = (value) => TaskAugmentedRequestParamsSchema.safeParse(value).success;
|
|
66
86
|
export const RequestSchema = z.object({
|
|
67
87
|
method: z.string(),
|
|
68
|
-
params: BaseRequestParamsSchema.optional()
|
|
88
|
+
params: BaseRequestParamsSchema.loose().optional()
|
|
69
89
|
});
|
|
70
|
-
const NotificationsParamsSchema = z.
|
|
90
|
+
const NotificationsParamsSchema = z.object({
|
|
71
91
|
/**
|
|
72
92
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
73
93
|
* for notes on _meta usage.
|
|
74
94
|
*/
|
|
75
|
-
_meta:
|
|
76
|
-
.object({
|
|
77
|
-
/**
|
|
78
|
-
* If specified, this notification is related to the provided task.
|
|
79
|
-
*/
|
|
80
|
-
[RELATED_TASK_META_KEY]: z.optional(RelatedTaskMetadataSchema)
|
|
81
|
-
})
|
|
82
|
-
.passthrough()
|
|
83
|
-
.optional()
|
|
95
|
+
_meta: RequestMetaSchema.optional()
|
|
84
96
|
});
|
|
85
97
|
export const NotificationSchema = z.object({
|
|
86
98
|
method: z.string(),
|
|
87
|
-
params: NotificationsParamsSchema.optional()
|
|
99
|
+
params: NotificationsParamsSchema.loose().optional()
|
|
88
100
|
});
|
|
89
101
|
export const ResultSchema = z.looseObject({
|
|
90
102
|
/**
|
|
91
103
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
92
104
|
* for notes on _meta usage.
|
|
93
105
|
*/
|
|
94
|
-
_meta:
|
|
95
|
-
.looseObject({
|
|
96
|
-
/**
|
|
97
|
-
* If specified, this result is related to the provided task.
|
|
98
|
-
*/
|
|
99
|
-
[RELATED_TASK_META_KEY]: RelatedTaskMetadataSchema.optional()
|
|
100
|
-
})
|
|
101
|
-
.optional()
|
|
106
|
+
_meta: RequestMetaSchema.optional()
|
|
102
107
|
});
|
|
103
108
|
/**
|
|
104
109
|
* A uniquely identifying ID for a request in JSON-RPC.
|
|
@@ -128,14 +133,26 @@ export const isJSONRPCNotification = (value) => JSONRPCNotificationSchema.safePa
|
|
|
128
133
|
/**
|
|
129
134
|
* A successful (non-error) response to a request.
|
|
130
135
|
*/
|
|
131
|
-
export const
|
|
136
|
+
export const JSONRPCResultResponseSchema = z
|
|
132
137
|
.object({
|
|
133
138
|
jsonrpc: z.literal(JSONRPC_VERSION),
|
|
134
139
|
id: RequestIdSchema,
|
|
135
140
|
result: ResultSchema
|
|
136
141
|
})
|
|
137
142
|
.strict();
|
|
138
|
-
|
|
143
|
+
/**
|
|
144
|
+
* Checks if a value is a valid JSONRPCResultResponse.
|
|
145
|
+
* @param value - The value to check.
|
|
146
|
+
*
|
|
147
|
+
* @returns True if the value is a valid JSONRPCResultResponse, false otherwise.
|
|
148
|
+
*/
|
|
149
|
+
export const isJSONRPCResultResponse = (value) => JSONRPCResultResponseSchema.safeParse(value).success;
|
|
150
|
+
/**
|
|
151
|
+
* @deprecated Use {@link isJSONRPCResultResponse} instead.
|
|
152
|
+
*
|
|
153
|
+
* Please note that {@link JSONRPCResponse} is a union of {@link JSONRPCResultResponse} and {@link JSONRPCErrorResponse} as per the updated JSON-RPC specification. (was previously just {@link JSONRPCResultResponse})
|
|
154
|
+
*/
|
|
155
|
+
export const isJSONRPCResponse = isJSONRPCResultResponse;
|
|
139
156
|
/**
|
|
140
157
|
* Error codes defined by the JSON-RPC specification.
|
|
141
158
|
*/
|
|
@@ -156,10 +173,10 @@ export var ErrorCode;
|
|
|
156
173
|
/**
|
|
157
174
|
* A response to a request that indicates an error occurred.
|
|
158
175
|
*/
|
|
159
|
-
export const
|
|
176
|
+
export const JSONRPCErrorResponseSchema = z
|
|
160
177
|
.object({
|
|
161
178
|
jsonrpc: z.literal(JSONRPC_VERSION),
|
|
162
|
-
id: RequestIdSchema,
|
|
179
|
+
id: RequestIdSchema.optional(),
|
|
163
180
|
error: z.object({
|
|
164
181
|
/**
|
|
165
182
|
* The error type that occurred.
|
|
@@ -172,12 +189,32 @@ export const JSONRPCErrorSchema = z
|
|
|
172
189
|
/**
|
|
173
190
|
* Additional information about the error. The value of this member is defined by the sender (e.g. detailed error information, nested errors etc.).
|
|
174
191
|
*/
|
|
175
|
-
data: z.
|
|
192
|
+
data: z.unknown().optional()
|
|
176
193
|
})
|
|
177
194
|
})
|
|
178
195
|
.strict();
|
|
179
|
-
|
|
180
|
-
|
|
196
|
+
/**
|
|
197
|
+
* @deprecated Use {@link JSONRPCErrorResponseSchema} instead.
|
|
198
|
+
*/
|
|
199
|
+
export const JSONRPCErrorSchema = JSONRPCErrorResponseSchema;
|
|
200
|
+
/**
|
|
201
|
+
* Checks if a value is a valid JSONRPCErrorResponse.
|
|
202
|
+
* @param value - The value to check.
|
|
203
|
+
*
|
|
204
|
+
* @returns True if the value is a valid JSONRPCErrorResponse, false otherwise.
|
|
205
|
+
*/
|
|
206
|
+
export const isJSONRPCErrorResponse = (value) => JSONRPCErrorResponseSchema.safeParse(value).success;
|
|
207
|
+
/**
|
|
208
|
+
* @deprecated Use {@link isJSONRPCErrorResponse} instead.
|
|
209
|
+
*/
|
|
210
|
+
export const isJSONRPCError = isJSONRPCErrorResponse;
|
|
211
|
+
export const JSONRPCMessageSchema = z.union([
|
|
212
|
+
JSONRPCRequestSchema,
|
|
213
|
+
JSONRPCNotificationSchema,
|
|
214
|
+
JSONRPCResultResponseSchema,
|
|
215
|
+
JSONRPCErrorResponseSchema
|
|
216
|
+
]);
|
|
217
|
+
export const JSONRPCResponseSchema = z.union([JSONRPCResultResponseSchema, JSONRPCErrorResponseSchema]);
|
|
181
218
|
/* Empty result */
|
|
182
219
|
/**
|
|
183
220
|
* A response that indicates success but carries no data.
|
|
@@ -189,7 +226,7 @@ export const CancelledNotificationParamsSchema = NotificationsParamsSchema.exten
|
|
|
189
226
|
*
|
|
190
227
|
* This MUST correspond to the ID of a request previously issued in the same direction.
|
|
191
228
|
*/
|
|
192
|
-
requestId: RequestIdSchema,
|
|
229
|
+
requestId: RequestIdSchema.optional(),
|
|
193
230
|
/**
|
|
194
231
|
* An optional string describing the reason for the cancellation. This MAY be logged or presented to the user.
|
|
195
232
|
*/
|
|
@@ -228,7 +265,15 @@ export const IconSchema = z.object({
|
|
|
228
265
|
*
|
|
229
266
|
* If not provided, the client should assume that the icon can be used at any size.
|
|
230
267
|
*/
|
|
231
|
-
sizes: z.array(z.string()).optional()
|
|
268
|
+
sizes: z.array(z.string()).optional(),
|
|
269
|
+
/**
|
|
270
|
+
* Optional specifier for the theme this icon is designed for. `light` indicates
|
|
271
|
+
* the icon is designed to be used with a light background, and `dark` indicates
|
|
272
|
+
* the icon is designed to be used with a dark background.
|
|
273
|
+
*
|
|
274
|
+
* If not provided, the client should assume the icon can be used with any theme.
|
|
275
|
+
*/
|
|
276
|
+
theme: z.enum(['light', 'dark']).optional()
|
|
232
277
|
});
|
|
233
278
|
/**
|
|
234
279
|
* Base schema to add `icons` property.
|
|
@@ -275,7 +320,15 @@ export const ImplementationSchema = BaseMetadataSchema.extend({
|
|
|
275
320
|
/**
|
|
276
321
|
* An optional URL of the website for this implementation.
|
|
277
322
|
*/
|
|
278
|
-
websiteUrl: z.string().optional()
|
|
323
|
+
websiteUrl: z.string().optional(),
|
|
324
|
+
/**
|
|
325
|
+
* An optional human-readable description of what this implementation does.
|
|
326
|
+
*
|
|
327
|
+
* This can be used by clients or servers to provide context about their purpose
|
|
328
|
+
* and capabilities. For example, a server might describe the types of resources
|
|
329
|
+
* or tools it provides, while a client might describe its intended use case.
|
|
330
|
+
*/
|
|
331
|
+
description: z.string().optional()
|
|
279
332
|
});
|
|
280
333
|
const FormElicitationCapabilitySchema = z.intersection(z.object({
|
|
281
334
|
applyDefaults: z.boolean().optional()
|
|
@@ -294,71 +347,67 @@ const ElicitationCapabilitySchema = z.preprocess(value => {
|
|
|
294
347
|
/**
|
|
295
348
|
* Task capabilities for clients, indicating which request types support task creation.
|
|
296
349
|
*/
|
|
297
|
-
export const ClientTasksCapabilitySchema = z
|
|
298
|
-
.object({
|
|
350
|
+
export const ClientTasksCapabilitySchema = z.looseObject({
|
|
299
351
|
/**
|
|
300
352
|
* Present if the client supports listing tasks.
|
|
301
353
|
*/
|
|
302
|
-
list:
|
|
354
|
+
list: AssertObjectSchema.optional(),
|
|
303
355
|
/**
|
|
304
356
|
* Present if the client supports cancelling tasks.
|
|
305
357
|
*/
|
|
306
|
-
cancel:
|
|
358
|
+
cancel: AssertObjectSchema.optional(),
|
|
307
359
|
/**
|
|
308
360
|
* Capabilities for task creation on specific request types.
|
|
309
361
|
*/
|
|
310
|
-
requests: z
|
|
311
|
-
.
|
|
362
|
+
requests: z
|
|
363
|
+
.looseObject({
|
|
312
364
|
/**
|
|
313
365
|
* Task support for sampling requests.
|
|
314
366
|
*/
|
|
315
|
-
sampling: z
|
|
316
|
-
.
|
|
317
|
-
createMessage:
|
|
367
|
+
sampling: z
|
|
368
|
+
.looseObject({
|
|
369
|
+
createMessage: AssertObjectSchema.optional()
|
|
318
370
|
})
|
|
319
|
-
.
|
|
371
|
+
.optional(),
|
|
320
372
|
/**
|
|
321
373
|
* Task support for elicitation requests.
|
|
322
374
|
*/
|
|
323
|
-
elicitation: z
|
|
324
|
-
.
|
|
325
|
-
create:
|
|
375
|
+
elicitation: z
|
|
376
|
+
.looseObject({
|
|
377
|
+
create: AssertObjectSchema.optional()
|
|
326
378
|
})
|
|
327
|
-
.
|
|
379
|
+
.optional()
|
|
328
380
|
})
|
|
329
|
-
.
|
|
330
|
-
})
|
|
331
|
-
.passthrough();
|
|
381
|
+
.optional()
|
|
382
|
+
});
|
|
332
383
|
/**
|
|
333
384
|
* Task capabilities for servers, indicating which request types support task creation.
|
|
334
385
|
*/
|
|
335
|
-
export const ServerTasksCapabilitySchema = z
|
|
336
|
-
.object({
|
|
386
|
+
export const ServerTasksCapabilitySchema = z.looseObject({
|
|
337
387
|
/**
|
|
338
388
|
* Present if the server supports listing tasks.
|
|
339
389
|
*/
|
|
340
|
-
list:
|
|
390
|
+
list: AssertObjectSchema.optional(),
|
|
341
391
|
/**
|
|
342
392
|
* Present if the server supports cancelling tasks.
|
|
343
393
|
*/
|
|
344
|
-
cancel:
|
|
394
|
+
cancel: AssertObjectSchema.optional(),
|
|
345
395
|
/**
|
|
346
396
|
* Capabilities for task creation on specific request types.
|
|
347
397
|
*/
|
|
348
|
-
requests: z
|
|
349
|
-
.
|
|
398
|
+
requests: z
|
|
399
|
+
.looseObject({
|
|
350
400
|
/**
|
|
351
401
|
* Task support for tool requests.
|
|
352
402
|
*/
|
|
353
|
-
tools: z
|
|
354
|
-
.
|
|
355
|
-
call:
|
|
403
|
+
tools: z
|
|
404
|
+
.looseObject({
|
|
405
|
+
call: AssertObjectSchema.optional()
|
|
356
406
|
})
|
|
357
|
-
.
|
|
407
|
+
.optional()
|
|
358
408
|
})
|
|
359
|
-
.
|
|
360
|
-
})
|
|
361
|
-
.passthrough();
|
|
409
|
+
.optional()
|
|
410
|
+
});
|
|
362
411
|
/**
|
|
363
412
|
* 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.
|
|
364
413
|
*/
|
|
@@ -401,7 +450,7 @@ export const ClientCapabilitiesSchema = z.object({
|
|
|
401
450
|
/**
|
|
402
451
|
* Present if the client supports task creation.
|
|
403
452
|
*/
|
|
404
|
-
tasks:
|
|
453
|
+
tasks: ClientTasksCapabilitySchema.optional()
|
|
405
454
|
});
|
|
406
455
|
export const InitializeRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
407
456
|
/**
|
|
@@ -422,8 +471,7 @@ export const isInitializeRequest = (value) => InitializeRequestSchema.safeParse(
|
|
|
422
471
|
/**
|
|
423
472
|
* 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.
|
|
424
473
|
*/
|
|
425
|
-
export const ServerCapabilitiesSchema = z
|
|
426
|
-
.object({
|
|
474
|
+
export const ServerCapabilitiesSchema = z.object({
|
|
427
475
|
/**
|
|
428
476
|
* Experimental, non-standard capabilities that the server supports.
|
|
429
477
|
*/
|
|
@@ -439,12 +487,14 @@ export const ServerCapabilitiesSchema = z
|
|
|
439
487
|
/**
|
|
440
488
|
* Present if the server offers any prompt templates.
|
|
441
489
|
*/
|
|
442
|
-
prompts: z
|
|
490
|
+
prompts: z
|
|
491
|
+
.object({
|
|
443
492
|
/**
|
|
444
493
|
* Whether this server supports issuing notifications for changes to the prompt list.
|
|
445
494
|
*/
|
|
446
|
-
listChanged: z.
|
|
447
|
-
})
|
|
495
|
+
listChanged: z.boolean().optional()
|
|
496
|
+
})
|
|
497
|
+
.optional(),
|
|
448
498
|
/**
|
|
449
499
|
* Present if the server offers any resources to read.
|
|
450
500
|
*/
|
|
@@ -474,9 +524,8 @@ export const ServerCapabilitiesSchema = z
|
|
|
474
524
|
/**
|
|
475
525
|
* Present if the server supports task creation.
|
|
476
526
|
*/
|
|
477
|
-
tasks:
|
|
478
|
-
})
|
|
479
|
-
.passthrough();
|
|
527
|
+
tasks: ServerTasksCapabilitySchema.optional()
|
|
528
|
+
});
|
|
480
529
|
/**
|
|
481
530
|
* After receiving an initialize request from the client, the server sends this response.
|
|
482
531
|
*/
|
|
@@ -498,7 +547,8 @@ export const InitializeResultSchema = ResultSchema.extend({
|
|
|
498
547
|
* This notification is sent from the client to the server after initialization has finished.
|
|
499
548
|
*/
|
|
500
549
|
export const InitializedNotificationSchema = NotificationSchema.extend({
|
|
501
|
-
method: z.literal('notifications/initialized')
|
|
550
|
+
method: z.literal('notifications/initialized'),
|
|
551
|
+
params: NotificationsParamsSchema.optional()
|
|
502
552
|
});
|
|
503
553
|
export const isInitializedNotification = (value) => InitializedNotificationSchema.safeParse(value).success;
|
|
504
554
|
/* Ping */
|
|
@@ -506,7 +556,8 @@ export const isInitializedNotification = (value) => InitializedNotificationSchem
|
|
|
506
556
|
* A ping, issued by either the server or the client, to check that the other party is still alive. The receiver must promptly respond, or else may be disconnected.
|
|
507
557
|
*/
|
|
508
558
|
export const PingRequestSchema = RequestSchema.extend({
|
|
509
|
-
method: z.literal('ping')
|
|
559
|
+
method: z.literal('ping'),
|
|
560
|
+
params: BaseRequestParamsSchema.optional()
|
|
510
561
|
});
|
|
511
562
|
/* Progress notifications */
|
|
512
563
|
export const ProgressSchema = z.object({
|
|
@@ -556,15 +607,19 @@ export const PaginatedResultSchema = ResultSchema.extend({
|
|
|
556
607
|
* An opaque token representing the pagination position after the last returned result.
|
|
557
608
|
* If present, there may be more results available.
|
|
558
609
|
*/
|
|
559
|
-
nextCursor:
|
|
610
|
+
nextCursor: CursorSchema.optional()
|
|
560
611
|
});
|
|
612
|
+
/**
|
|
613
|
+
* The status of a task.
|
|
614
|
+
* */
|
|
615
|
+
export const TaskStatusSchema = z.enum(['working', 'input_required', 'completed', 'failed', 'cancelled']);
|
|
561
616
|
/* Tasks */
|
|
562
617
|
/**
|
|
563
618
|
* A pollable state object associated with a request.
|
|
564
619
|
*/
|
|
565
620
|
export const TaskSchema = z.object({
|
|
566
621
|
taskId: z.string(),
|
|
567
|
-
status:
|
|
622
|
+
status: TaskStatusSchema,
|
|
568
623
|
/**
|
|
569
624
|
* Time in milliseconds to keep task results available after completion.
|
|
570
625
|
* If null, the task has unlimited lifetime until manually cleaned up.
|
|
@@ -623,6 +678,13 @@ export const GetTaskPayloadRequestSchema = RequestSchema.extend({
|
|
|
623
678
|
taskId: z.string()
|
|
624
679
|
})
|
|
625
680
|
});
|
|
681
|
+
/**
|
|
682
|
+
* The response to a tasks/result request.
|
|
683
|
+
* The structure matches the result type of the original request.
|
|
684
|
+
* For example, a tools/call task would return the CallToolResult structure.
|
|
685
|
+
*
|
|
686
|
+
*/
|
|
687
|
+
export const GetTaskPayloadResultSchema = ResultSchema.loose();
|
|
626
688
|
/**
|
|
627
689
|
* A request to list tasks.
|
|
628
690
|
*/
|
|
@@ -685,7 +747,7 @@ const Base64Schema = z.string().refine(val => {
|
|
|
685
747
|
atob(val);
|
|
686
748
|
return true;
|
|
687
749
|
}
|
|
688
|
-
catch
|
|
750
|
+
catch {
|
|
689
751
|
return false;
|
|
690
752
|
}
|
|
691
753
|
}, { message: 'Invalid Base64 string' });
|
|
@@ -695,6 +757,10 @@ export const BlobResourceContentsSchema = ResourceContentsSchema.extend({
|
|
|
695
757
|
*/
|
|
696
758
|
blob: Base64Schema
|
|
697
759
|
});
|
|
760
|
+
/**
|
|
761
|
+
* The sender or recipient of messages and data in a conversation.
|
|
762
|
+
*/
|
|
763
|
+
export const RoleSchema = z.enum(['user', 'assistant']);
|
|
698
764
|
/**
|
|
699
765
|
* Optional annotations providing clients additional context about a resource.
|
|
700
766
|
*/
|
|
@@ -702,7 +768,7 @@ export const AnnotationsSchema = z.object({
|
|
|
702
768
|
/**
|
|
703
769
|
* Intended audience(s) for the resource.
|
|
704
770
|
*/
|
|
705
|
-
audience: z.array(
|
|
771
|
+
audience: z.array(RoleSchema).optional(),
|
|
706
772
|
/**
|
|
707
773
|
* Importance hint for the resource, from 0 (least) to 1 (most).
|
|
708
774
|
*/
|
|
@@ -825,7 +891,8 @@ export const ReadResourceResultSchema = ResultSchema.extend({
|
|
|
825
891
|
* An optional notification from the server to the client, informing it that the list of resources it can read from has changed. This may be issued by servers without any previous subscription from the client.
|
|
826
892
|
*/
|
|
827
893
|
export const ResourceListChangedNotificationSchema = NotificationSchema.extend({
|
|
828
|
-
method: z.literal('notifications/resources/list_changed')
|
|
894
|
+
method: z.literal('notifications/resources/list_changed'),
|
|
895
|
+
params: NotificationsParamsSchema.optional()
|
|
829
896
|
});
|
|
830
897
|
export const SubscribeRequestParamsSchema = ResourceRequestParamsSchema;
|
|
831
898
|
/**
|
|
@@ -998,8 +1065,7 @@ export const AudioContentSchema = z.object({
|
|
|
998
1065
|
* A tool call request from an assistant (LLM).
|
|
999
1066
|
* Represents the assistant's request to use a tool.
|
|
1000
1067
|
*/
|
|
1001
|
-
export const ToolUseContentSchema = z
|
|
1002
|
-
.object({
|
|
1068
|
+
export const ToolUseContentSchema = z.object({
|
|
1003
1069
|
type: z.literal('tool_use'),
|
|
1004
1070
|
/**
|
|
1005
1071
|
* The name of the tool to invoke.
|
|
@@ -1015,14 +1081,13 @@ export const ToolUseContentSchema = z
|
|
|
1015
1081
|
* Arguments to pass to the tool.
|
|
1016
1082
|
* Must conform to the tool's inputSchema.
|
|
1017
1083
|
*/
|
|
1018
|
-
input: z.
|
|
1084
|
+
input: z.record(z.string(), z.unknown()),
|
|
1019
1085
|
/**
|
|
1020
1086
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
1021
1087
|
* for notes on _meta usage.
|
|
1022
1088
|
*/
|
|
1023
|
-
_meta: z.
|
|
1024
|
-
})
|
|
1025
|
-
.passthrough();
|
|
1089
|
+
_meta: z.record(z.string(), z.unknown()).optional()
|
|
1090
|
+
});
|
|
1026
1091
|
/**
|
|
1027
1092
|
* The contents of a resource, embedded into a prompt or tool call result.
|
|
1028
1093
|
*/
|
|
@@ -1061,7 +1126,7 @@ export const ContentBlockSchema = z.union([
|
|
|
1061
1126
|
* Describes a message returned as part of a prompt.
|
|
1062
1127
|
*/
|
|
1063
1128
|
export const PromptMessageSchema = z.object({
|
|
1064
|
-
role:
|
|
1129
|
+
role: RoleSchema,
|
|
1065
1130
|
content: ContentBlockSchema
|
|
1066
1131
|
});
|
|
1067
1132
|
/**
|
|
@@ -1071,14 +1136,15 @@ export const GetPromptResultSchema = ResultSchema.extend({
|
|
|
1071
1136
|
/**
|
|
1072
1137
|
* An optional description for the prompt.
|
|
1073
1138
|
*/
|
|
1074
|
-
description: z.
|
|
1139
|
+
description: z.string().optional(),
|
|
1075
1140
|
messages: z.array(PromptMessageSchema)
|
|
1076
1141
|
});
|
|
1077
1142
|
/**
|
|
1078
1143
|
* An optional notification from the server to the client, informing it that the list of prompts it offers has changed. This may be issued by servers without any previous subscription from the client.
|
|
1079
1144
|
*/
|
|
1080
1145
|
export const PromptListChangedNotificationSchema = NotificationSchema.extend({
|
|
1081
|
-
method: z.literal('notifications/prompts/list_changed')
|
|
1146
|
+
method: z.literal('notifications/prompts/list_changed'),
|
|
1147
|
+
params: NotificationsParamsSchema.optional()
|
|
1082
1148
|
});
|
|
1083
1149
|
/* Tools */
|
|
1084
1150
|
/**
|
|
@@ -1181,11 +1247,11 @@ export const ToolSchema = z.object({
|
|
|
1181
1247
|
/**
|
|
1182
1248
|
* Optional additional tool information.
|
|
1183
1249
|
*/
|
|
1184
|
-
annotations:
|
|
1250
|
+
annotations: ToolAnnotationsSchema.optional(),
|
|
1185
1251
|
/**
|
|
1186
1252
|
* Execution-related properties for this tool.
|
|
1187
1253
|
*/
|
|
1188
|
-
execution:
|
|
1254
|
+
execution: ToolExecutionSchema.optional(),
|
|
1189
1255
|
/**
|
|
1190
1256
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
1191
1257
|
* for notes on _meta usage.
|
|
@@ -1235,7 +1301,7 @@ export const CallToolResultSchema = ResultSchema.extend({
|
|
|
1235
1301
|
* server does not support tool calls, or any other exceptional conditions,
|
|
1236
1302
|
* should be reported as an MCP error response.
|
|
1237
1303
|
*/
|
|
1238
|
-
isError: z.
|
|
1304
|
+
isError: z.boolean().optional()
|
|
1239
1305
|
});
|
|
1240
1306
|
/**
|
|
1241
1307
|
* CallToolResultSchema extended with backwards compatibility to protocol version 2024-10-07.
|
|
@@ -1246,7 +1312,7 @@ export const CompatibilityCallToolResultSchema = CallToolResultSchema.or(ResultS
|
|
|
1246
1312
|
/**
|
|
1247
1313
|
* Parameters for a `tools/call` request.
|
|
1248
1314
|
*/
|
|
1249
|
-
export const CallToolRequestParamsSchema =
|
|
1315
|
+
export const CallToolRequestParamsSchema = TaskAugmentedRequestParamsSchema.extend({
|
|
1250
1316
|
/**
|
|
1251
1317
|
* The name of the tool to call.
|
|
1252
1318
|
*/
|
|
@@ -1254,7 +1320,7 @@ export const CallToolRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
|
1254
1320
|
/**
|
|
1255
1321
|
* Arguments to pass to the tool.
|
|
1256
1322
|
*/
|
|
1257
|
-
arguments: z.
|
|
1323
|
+
arguments: z.record(z.string(), z.unknown()).optional()
|
|
1258
1324
|
});
|
|
1259
1325
|
/**
|
|
1260
1326
|
* Used by the client to invoke a tool provided by the server.
|
|
@@ -1267,7 +1333,32 @@ export const CallToolRequestSchema = RequestSchema.extend({
|
|
|
1267
1333
|
* 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.
|
|
1268
1334
|
*/
|
|
1269
1335
|
export const ToolListChangedNotificationSchema = NotificationSchema.extend({
|
|
1270
|
-
method: z.literal('notifications/tools/list_changed')
|
|
1336
|
+
method: z.literal('notifications/tools/list_changed'),
|
|
1337
|
+
params: NotificationsParamsSchema.optional()
|
|
1338
|
+
});
|
|
1339
|
+
/**
|
|
1340
|
+
* Base schema for list changed subscription options (without callback).
|
|
1341
|
+
* Used internally for Zod validation of autoRefresh and debounceMs.
|
|
1342
|
+
*/
|
|
1343
|
+
export const ListChangedOptionsBaseSchema = z.object({
|
|
1344
|
+
/**
|
|
1345
|
+
* If true, the list will be refreshed automatically when a list changed notification is received.
|
|
1346
|
+
* The callback will be called with the updated list.
|
|
1347
|
+
*
|
|
1348
|
+
* If false, the callback will be called with null items, allowing manual refresh.
|
|
1349
|
+
*
|
|
1350
|
+
* @default true
|
|
1351
|
+
*/
|
|
1352
|
+
autoRefresh: z.boolean().default(true),
|
|
1353
|
+
/**
|
|
1354
|
+
* Debounce time in milliseconds for list changed notification processing.
|
|
1355
|
+
*
|
|
1356
|
+
* Multiple notifications received within this timeframe will only trigger one refresh.
|
|
1357
|
+
* Set to 0 to disable debouncing.
|
|
1358
|
+
*
|
|
1359
|
+
* @default 300
|
|
1360
|
+
*/
|
|
1361
|
+
debounceMs: z.number().int().nonnegative().default(300)
|
|
1271
1362
|
});
|
|
1272
1363
|
/* Logging */
|
|
1273
1364
|
/**
|
|
@@ -1331,19 +1422,19 @@ export const ModelPreferencesSchema = z.object({
|
|
|
1331
1422
|
/**
|
|
1332
1423
|
* Optional hints to use for model selection.
|
|
1333
1424
|
*/
|
|
1334
|
-
hints: z.
|
|
1425
|
+
hints: z.array(ModelHintSchema).optional(),
|
|
1335
1426
|
/**
|
|
1336
1427
|
* How much to prioritize cost when selecting a model.
|
|
1337
1428
|
*/
|
|
1338
|
-
costPriority: z.
|
|
1429
|
+
costPriority: z.number().min(0).max(1).optional(),
|
|
1339
1430
|
/**
|
|
1340
1431
|
* How much to prioritize sampling speed (latency) when selecting a model.
|
|
1341
1432
|
*/
|
|
1342
|
-
speedPriority: z.
|
|
1433
|
+
speedPriority: z.number().min(0).max(1).optional(),
|
|
1343
1434
|
/**
|
|
1344
1435
|
* How much to prioritize intelligence and capabilities when selecting a model.
|
|
1345
1436
|
*/
|
|
1346
|
-
intelligencePriority: z.
|
|
1437
|
+
intelligencePriority: z.number().min(0).max(1).optional()
|
|
1347
1438
|
});
|
|
1348
1439
|
/**
|
|
1349
1440
|
* Controls tool usage behavior in sampling requests.
|
|
@@ -1355,26 +1446,24 @@ export const ToolChoiceSchema = z.object({
|
|
|
1355
1446
|
* - "required": Model MUST use at least one tool before completing
|
|
1356
1447
|
* - "none": Model MUST NOT use any tools
|
|
1357
1448
|
*/
|
|
1358
|
-
mode: z.
|
|
1449
|
+
mode: z.enum(['auto', 'required', 'none']).optional()
|
|
1359
1450
|
});
|
|
1360
1451
|
/**
|
|
1361
1452
|
* The result of a tool execution, provided by the user (server).
|
|
1362
1453
|
* Represents the outcome of invoking a tool requested via ToolUseContent.
|
|
1363
1454
|
*/
|
|
1364
|
-
export const ToolResultContentSchema = z
|
|
1365
|
-
.object({
|
|
1455
|
+
export const ToolResultContentSchema = z.object({
|
|
1366
1456
|
type: z.literal('tool_result'),
|
|
1367
1457
|
toolUseId: z.string().describe('The unique identifier for the corresponding tool call.'),
|
|
1368
1458
|
content: z.array(ContentBlockSchema).default([]),
|
|
1369
|
-
structuredContent: z.object({}).
|
|
1370
|
-
isError: z.
|
|
1459
|
+
structuredContent: z.object({}).loose().optional(),
|
|
1460
|
+
isError: z.boolean().optional(),
|
|
1371
1461
|
/**
|
|
1372
1462
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
1373
1463
|
* for notes on _meta usage.
|
|
1374
1464
|
*/
|
|
1375
|
-
_meta: z.
|
|
1376
|
-
})
|
|
1377
|
-
.passthrough();
|
|
1465
|
+
_meta: z.record(z.string(), z.unknown()).optional()
|
|
1466
|
+
});
|
|
1378
1467
|
/**
|
|
1379
1468
|
* Basic content types for sampling responses (without tool use).
|
|
1380
1469
|
* Used for backwards-compatible CreateMessageResult when tools are not used.
|
|
@@ -1394,21 +1483,19 @@ export const SamplingMessageContentBlockSchema = z.discriminatedUnion('type', [
|
|
|
1394
1483
|
/**
|
|
1395
1484
|
* Describes a message issued to or received from an LLM API.
|
|
1396
1485
|
*/
|
|
1397
|
-
export const SamplingMessageSchema = z
|
|
1398
|
-
|
|
1399
|
-
role: z.enum(['user', 'assistant']),
|
|
1486
|
+
export const SamplingMessageSchema = z.object({
|
|
1487
|
+
role: RoleSchema,
|
|
1400
1488
|
content: z.union([SamplingMessageContentBlockSchema, z.array(SamplingMessageContentBlockSchema)]),
|
|
1401
1489
|
/**
|
|
1402
1490
|
* See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
|
|
1403
1491
|
* for notes on _meta usage.
|
|
1404
1492
|
*/
|
|
1405
|
-
_meta: z.
|
|
1406
|
-
})
|
|
1407
|
-
.passthrough();
|
|
1493
|
+
_meta: z.record(z.string(), z.unknown()).optional()
|
|
1494
|
+
});
|
|
1408
1495
|
/**
|
|
1409
1496
|
* Parameters for a `sampling/createMessage` request.
|
|
1410
1497
|
*/
|
|
1411
|
-
export const CreateMessageRequestParamsSchema =
|
|
1498
|
+
export const CreateMessageRequestParamsSchema = TaskAugmentedRequestParamsSchema.extend({
|
|
1412
1499
|
messages: z.array(SamplingMessageSchema),
|
|
1413
1500
|
/**
|
|
1414
1501
|
* The server's preferences for which model to select. The client MAY modify or omit this request.
|
|
@@ -1442,13 +1529,13 @@ export const CreateMessageRequestParamsSchema = BaseRequestParamsSchema.extend({
|
|
|
1442
1529
|
* Tools that the model may use during generation.
|
|
1443
1530
|
* The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
|
|
1444
1531
|
*/
|
|
1445
|
-
tools: z.
|
|
1532
|
+
tools: z.array(ToolSchema).optional(),
|
|
1446
1533
|
/**
|
|
1447
1534
|
* Controls how the model uses tools.
|
|
1448
1535
|
* The client MUST return an error if this field is provided but ClientCapabilities.sampling.tools is not declared.
|
|
1449
1536
|
* Default is `{ mode: "auto" }`.
|
|
1450
1537
|
*/
|
|
1451
|
-
toolChoice:
|
|
1538
|
+
toolChoice: ToolChoiceSchema.optional()
|
|
1452
1539
|
});
|
|
1453
1540
|
/**
|
|
1454
1541
|
* 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.
|
|
@@ -1478,7 +1565,7 @@ export const CreateMessageResultSchema = ResultSchema.extend({
|
|
|
1478
1565
|
* This field is an open string to allow for provider-specific stop reasons.
|
|
1479
1566
|
*/
|
|
1480
1567
|
stopReason: z.optional(z.enum(['endTurn', 'stopSequence', 'maxTokens']).or(z.string())),
|
|
1481
|
-
role:
|
|
1568
|
+
role: RoleSchema,
|
|
1482
1569
|
/**
|
|
1483
1570
|
* Response content. Single content block (text, image, or audio).
|
|
1484
1571
|
*/
|
|
@@ -1505,7 +1592,7 @@ export const CreateMessageResultWithToolsSchema = ResultSchema.extend({
|
|
|
1505
1592
|
* This field is an open string to allow for provider-specific stop reasons.
|
|
1506
1593
|
*/
|
|
1507
1594
|
stopReason: z.optional(z.enum(['endTurn', 'stopSequence', 'maxTokens', 'toolUse']).or(z.string())),
|
|
1508
|
-
role:
|
|
1595
|
+
role: RoleSchema,
|
|
1509
1596
|
/**
|
|
1510
1597
|
* Response content. May be a single block or array. May include ToolUseContent if stopReason is "toolUse".
|
|
1511
1598
|
*/
|
|
@@ -1628,7 +1715,7 @@ export const PrimitiveSchemaDefinitionSchema = z.union([EnumSchemaSchema, Boolea
|
|
|
1628
1715
|
/**
|
|
1629
1716
|
* Parameters for an `elicitation/create` request for form-based elicitation.
|
|
1630
1717
|
*/
|
|
1631
|
-
export const ElicitRequestFormParamsSchema =
|
|
1718
|
+
export const ElicitRequestFormParamsSchema = TaskAugmentedRequestParamsSchema.extend({
|
|
1632
1719
|
/**
|
|
1633
1720
|
* The elicitation mode.
|
|
1634
1721
|
*
|
|
@@ -1652,7 +1739,7 @@ export const ElicitRequestFormParamsSchema = BaseRequestParamsSchema.extend({
|
|
|
1652
1739
|
/**
|
|
1653
1740
|
* Parameters for an `elicitation/create` request for URL-based elicitation.
|
|
1654
1741
|
*/
|
|
1655
|
-
export const ElicitRequestURLParamsSchema =
|
|
1742
|
+
export const ElicitRequestURLParamsSchema = TaskAugmentedRequestParamsSchema.extend({
|
|
1656
1743
|
/**
|
|
1657
1744
|
* The elicitation mode.
|
|
1658
1745
|
*/
|
|
@@ -1836,7 +1923,8 @@ export const RootSchema = z.object({
|
|
|
1836
1923
|
* Sent from the server to request a list of root URIs from the client.
|
|
1837
1924
|
*/
|
|
1838
1925
|
export const ListRootsRequestSchema = RequestSchema.extend({
|
|
1839
|
-
method: z.literal('roots/list')
|
|
1926
|
+
method: z.literal('roots/list'),
|
|
1927
|
+
params: BaseRequestParamsSchema.optional()
|
|
1840
1928
|
});
|
|
1841
1929
|
/**
|
|
1842
1930
|
* The client's response to a roots/list request from the server.
|
|
@@ -1848,7 +1936,8 @@ export const ListRootsResultSchema = ResultSchema.extend({
|
|
|
1848
1936
|
* A notification from the client to the server, informing it that the list of roots has changed.
|
|
1849
1937
|
*/
|
|
1850
1938
|
export const RootsListChangedNotificationSchema = NotificationSchema.extend({
|
|
1851
|
-
method: z.literal('notifications/roots/list_changed')
|
|
1939
|
+
method: z.literal('notifications/roots/list_changed'),
|
|
1940
|
+
params: NotificationsParamsSchema.optional()
|
|
1852
1941
|
});
|
|
1853
1942
|
/* Client messages */
|
|
1854
1943
|
export const ClientRequestSchema = z.union([
|
|
@@ -1867,7 +1956,8 @@ export const ClientRequestSchema = z.union([
|
|
|
1867
1956
|
ListToolsRequestSchema,
|
|
1868
1957
|
GetTaskRequestSchema,
|
|
1869
1958
|
GetTaskPayloadRequestSchema,
|
|
1870
|
-
ListTasksRequestSchema
|
|
1959
|
+
ListTasksRequestSchema,
|
|
1960
|
+
CancelTaskRequestSchema
|
|
1871
1961
|
]);
|
|
1872
1962
|
export const ClientNotificationSchema = z.union([
|
|
1873
1963
|
CancelledNotificationSchema,
|
|
@@ -1894,7 +1984,8 @@ export const ServerRequestSchema = z.union([
|
|
|
1894
1984
|
ListRootsRequestSchema,
|
|
1895
1985
|
GetTaskRequestSchema,
|
|
1896
1986
|
GetTaskPayloadRequestSchema,
|
|
1897
|
-
ListTasksRequestSchema
|
|
1987
|
+
ListTasksRequestSchema,
|
|
1988
|
+
CancelTaskRequestSchema
|
|
1898
1989
|
]);
|
|
1899
1990
|
export const ServerNotificationSchema = z.union([
|
|
1900
1991
|
CancelledNotificationSchema,
|
|
@@ -1955,8 +2046,7 @@ export class UrlElicitationRequiredError extends McpError {
|
|
|
1955
2046
|
});
|
|
1956
2047
|
}
|
|
1957
2048
|
get elicitations() {
|
|
1958
|
-
|
|
1959
|
-
return (_b = (_a = this.data) === null || _a === void 0 ? void 0 : _a.elicitations) !== null && _b !== void 0 ? _b : [];
|
|
2049
|
+
return this.data?.elicitations ?? [];
|
|
1960
2050
|
}
|
|
1961
2051
|
}
|
|
1962
2052
|
//# sourceMappingURL=types.js.map
|