Squashed 'packages/mcp-typescript/' changes from 2cc7dd1..dcc30be

dcc30be Merge pull request #16 from modelcontextprotocol/ashwin/protocol
05a3e54 fix protocol version in client
73c66f4 Merge pull request #13 from modelcontextprotocol/justin/uris
5cad4b5 Merge pull request #12 from modelcontextprotocol/justin/spec-updates
ec96ffc Treat URIs as 'URL' type
f3a8fb8 yarn build
69daade Update to latest protocol version

git-subtree-dir: packages/mcp-typescript
git-subtree-split: dcc30bea4904b04c50d858f6a369d3015920fab2
This commit is contained in:
Ashwin Bhat
2024-10-15 10:31:11 -07:00
parent 3b583e1f45
commit 4f0bc7bbf7
8 changed files with 1635 additions and 780 deletions

2
dist/client/index.js generated vendored
View File

@@ -18,7 +18,7 @@ export class Client extends Protocol {
const result = await this.request({ const result = await this.request({
method: "initialize", method: "initialize",
params: { params: {
protocolVersion: 1, protocolVersion: PROTOCOL_VERSION,
capabilities: {}, capabilities: {},
clientInfo: this._clientInfo, clientInfo: this._clientInfo,
}, },

2
dist/client/index.js.map generated vendored
View File

@@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAKL,sBAAsB,EACtB,gBAAgB,GAEjB,MAAM,aAAa,CAAC;AAErB;;;;GAIG;AACH,MAAM,OAAO,MAAO,SAAQ,QAI3B;IAIC;;OAEG;IACH,YAAoB,WAA2B;QAC7C,KAAK,EAAE,CAAC;QADU,gBAAW,GAAX,WAAW,CAAgB;IAE/C,CAAC;IAEQ,KAAK,CAAC,OAAO,CAAC,SAAoB;QACzC,MAAM,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAE/B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAC/B;YACE,MAAM,EAAE,YAAY;YACpB,MAAM,EAAE;gBACN,eAAe,EAAE,CAAC;gBAClB,YAAY,EAAE,EAAE;gBAChB,UAAU,EAAE,IAAI,CAAC,WAAW;aAC7B;SACF,EACD,sBAAsB,CACvB,CAAC;QAEF,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,0CAA0C,MAAM,EAAE,CAAC,CAAC;QACtE,CAAC;QAED,IAAI,MAAM,CAAC,eAAe,KAAK,gBAAgB,EAAE,CAAC;YAChD,MAAM,IAAI,KAAK,CACb,+CAA+C,MAAM,CAAC,eAAe,EAAE,CACxE,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,mBAAmB,GAAG,MAAM,CAAC,YAAY,CAAC;QAC/C,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,UAAU,CAAC;QAExC,MAAM,IAAI,CAAC,YAAY,CAAC;YACtB,MAAM,EAAE,2BAA2B;SACpC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,qBAAqB;QACnB,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;IAED;;OAEG;IACH,gBAAgB;QACd,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;CACF"} {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAKL,sBAAsB,EACtB,gBAAgB,GAEjB,MAAM,aAAa,CAAC;AAErB;;;;GAIG;AACH,MAAM,OAAO,MAAO,SAAQ,QAI3B;IAIC;;OAEG;IACH,YAAoB,WAA2B;QAC7C,KAAK,EAAE,CAAC;QADU,gBAAW,GAAX,WAAW,CAAgB;IAE/C,CAAC;IAEQ,KAAK,CAAC,OAAO,CAAC,SAAoB;QACzC,MAAM,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAE/B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAC/B;YACE,MAAM,EAAE,YAAY;YACpB,MAAM,EAAE;gBACN,eAAe,EAAE,gBAAgB;gBACjC,YAAY,EAAE,EAAE;gBAChB,UAAU,EAAE,IAAI,CAAC,WAAW;aAC7B;SACF,EACD,sBAAsB,CACvB,CAAC;QAEF,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,0CAA0C,MAAM,EAAE,CAAC,CAAC;QACtE,CAAC;QAED,IAAI,MAAM,CAAC,eAAe,KAAK,gBAAgB,EAAE,CAAC;YAChD,MAAM,IAAI,KAAK,CACb,+CAA+C,MAAM,CAAC,eAAe,EAAE,CACxE,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,mBAAmB,GAAG,MAAM,CAAC,YAAY,CAAC;QAC/C,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,UAAU,CAAC;QAExC,MAAM,IAAI,CAAC,YAAY,CAAC;YACtB,MAAM,EAAE,2BAA2B;SACpC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,qBAAqB;QACnB,OAAO,IAAI,CAAC,mBAAmB,CAAC;IAClC,CAAC;IAED;;OAEG;IACH,gBAAgB;QACd,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;CACF"}

2165
dist/types.d.ts generated vendored

File diff suppressed because it is too large Load Diff

2
dist/types.d.ts.map generated vendored

File diff suppressed because one or more lines are too long

95
dist/types.js generated vendored
View File

@@ -1,10 +1,15 @@
import { z } from "zod"; import { z } from "zod";
export const PROTOCOL_VERSION = "2024-10-07";
/* JSON-RPC types */ /* JSON-RPC types */
export const JSONRPC_VERSION = "2.0"; export const JSONRPC_VERSION = "2.0";
/** /**
* A progress token, used to associate progress notifications with the original request. * A progress token, used to associate progress notifications with the original request.
*/ */
export const ProgressTokenSchema = z.union([z.string(), z.number().int()]); export const ProgressTokenSchema = z.union([z.string(), z.number().int()]);
/**
* An opaque token used to represent a cursor for pagination.
*/
export const CursorSchema = z.string();
export const RequestSchema = z.object({ export const RequestSchema = z.object({
method: z.string(), method: z.string(),
params: z.optional(z params: z.optional(z
@@ -121,7 +126,6 @@ export const JSONRPCMessageSchema = z.union([
*/ */
export const EmptyResultSchema = ResultSchema.strict(); export const EmptyResultSchema = ResultSchema.strict();
/* Initialization */ /* Initialization */
export const PROTOCOL_VERSION = 1;
/** /**
* Text provided to or from an LLM. * Text provided to or from an LLM.
*/ */
@@ -182,7 +186,7 @@ export const InitializeRequestSchema = RequestSchema.extend({
/** /**
* The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well. * The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well.
*/ */
protocolVersion: z.number().int(), protocolVersion: z.string().or(z.number().int()),
capabilities: ClientCapabilitiesSchema, capabilities: ClientCapabilitiesSchema,
clientInfo: ImplementationSchema, clientInfo: ImplementationSchema,
}), }),
@@ -202,7 +206,14 @@ export const ServerCapabilitiesSchema = z.object({
/** /**
* Present if the server offers any prompt templates. * Present if the server offers any prompt templates.
*/ */
prompts: z.optional(z.object({}).passthrough()), prompts: z.optional(z
.object({
/**
* Whether this server supports notifications for changes to the prompt list.
*/
listChanged: z.optional(z.boolean()),
})
.passthrough()),
/** /**
* Present if the server offers any resources to read. * Present if the server offers any resources to read.
*/ */
@@ -212,12 +223,23 @@ export const ServerCapabilitiesSchema = z.object({
* Whether this server supports subscribing to resource updates. * Whether this server supports subscribing to resource updates.
*/ */
subscribe: z.optional(z.boolean()), subscribe: z.optional(z.boolean()),
/**
* Whether this server supports notifications for changes to the resource list.
*/
listChanged: z.optional(z.boolean()),
}) })
.passthrough()), .passthrough()),
/** /**
* Present if the server offers any tools to call. * Present if the server offers any tools to call.
*/ */
tools: z.optional(z.object({}).passthrough()), tools: z.optional(z
.object({
/**
* Whether this server supports notifications for changes to the tool list.
*/
listChanged: z.optional(z.boolean()),
})
.passthrough()),
}); });
/** /**
* After receiving an initialize request from the client, the server sends this response. * After receiving an initialize request from the client, the server sends this response.
@@ -226,7 +248,7 @@ export const InitializeResultSchema = ResultSchema.extend({
/** /**
* The version of the Model Context Protocol that the server wants to use. This may not match the version that the client requested. If the client cannot support this version, it MUST disconnect. * The version of the Model Context Protocol that the server wants to use. This may not match the version that the client requested. If the client cannot support this version, it MUST disconnect.
*/ */
protocolVersion: z.number().int(), protocolVersion: z.string().or(z.number().int()),
capabilities: ServerCapabilitiesSchema, capabilities: ServerCapabilitiesSchema,
serverInfo: ImplementationSchema, serverInfo: ImplementationSchema,
}); });
@@ -266,6 +288,23 @@ export const ProgressNotificationSchema = NotificationSchema.extend({
progressToken: ProgressTokenSchema, progressToken: ProgressTokenSchema,
}), }),
}); });
/* Pagination */
export const PaginatedRequestSchema = RequestSchema.extend({
params: z.optional(z.object({
/**
* An opaque token representing the current pagination position.
* If provided, the server should return results starting after this cursor.
*/
cursor: z.optional(CursorSchema),
})),
});
export const PaginatedResultSchema = ResultSchema.extend({
/**
* An opaque token representing the pagination position after the last returned result.
* If present, there may be more results available.
*/
nextCursor: z.optional(CursorSchema),
});
/* Resources */ /* Resources */
/** /**
* The contents of a specific resource or sub-resource. * The contents of a specific resource or sub-resource.
@@ -274,7 +313,7 @@ export const ResourceContentsSchema = z.object({
/** /**
* The URI of this resource. * The URI of this resource.
*/ */
uri: z.string().url(), uri: z.string().transform((s) => new URL(s)),
/** /**
* The MIME type of this resource, if known. * The MIME type of this resource, if known.
*/ */
@@ -299,7 +338,7 @@ export const ResourceSchema = z.object({
/** /**
* The URI of this resource. * The URI of this resource.
*/ */
uri: z.string().url(), uri: z.string().transform((s) => new URL(s)),
/** /**
* A human-readable name for this resource. * A human-readable name for this resource.
* *
@@ -345,15 +384,26 @@ export const ResourceTemplateSchema = z.object({
/** /**
* Sent from the client to request a list of resources the server has. * Sent from the client to request a list of resources the server has.
*/ */
export const ListResourcesRequestSchema = RequestSchema.extend({ export const ListResourcesRequestSchema = PaginatedRequestSchema.extend({
method: z.literal("resources/list"), method: z.literal("resources/list"),
}); });
/** /**
* The server's response to a resources/list request from the client. * The server's response to a resources/list request from the client.
*/ */
export const ListResourcesResultSchema = ResultSchema.extend({ export const ListResourcesResultSchema = PaginatedResultSchema.extend({
resourceTemplates: z.optional(z.array(ResourceTemplateSchema)), resources: z.array(ResourceSchema),
resources: z.optional(z.array(ResourceSchema)), });
/**
* Sent from the client to request a list of resource templates the server has.
*/
export const ListResourceTemplatesRequestSchema = PaginatedRequestSchema.extend({
method: z.literal("resources/templates/list"),
});
/**
* The server's response to a resources/templates/list request from the client.
*/
export const ListResourceTemplatesResultSchema = PaginatedResultSchema.extend({
resourceTemplates: z.array(ResourceTemplateSchema),
}); });
/** /**
* Sent from the client to the server, to read a specific resource URI. * Sent from the client to the server, to read a specific resource URI.
@@ -364,7 +414,7 @@ export const ReadResourceRequestSchema = RequestSchema.extend({
/** /**
* The URI of the resource to read. The URI can use any protocol; it is up to the server how to interpret it. * The URI of the resource to read. The URI can use any protocol; it is up to the server how to interpret it.
*/ */
uri: z.string().url(), uri: z.string().transform((s) => new URL(s)),
}), }),
}); });
/** /**
@@ -388,7 +438,7 @@ export const SubscribeRequestSchema = RequestSchema.extend({
/** /**
* The URI of the resource to subscribe to. The URI can use any protocol; it is up to the server how to interpret it. * The URI of the resource to subscribe to. The URI can use any protocol; it is up to the server how to interpret it.
*/ */
uri: z.string().url(), uri: z.string().transform((s) => new URL(s)),
}), }),
}); });
/** /**
@@ -400,7 +450,7 @@ export const UnsubscribeRequestSchema = RequestSchema.extend({
/** /**
* The URI of the resource to unsubscribe from. * The URI of the resource to unsubscribe from.
*/ */
uri: z.string().url(), uri: z.string().transform((s) => new URL(s)),
}), }),
}); });
/** /**
@@ -412,7 +462,7 @@ export const ResourceUpdatedNotificationSchema = NotificationSchema.extend({
/** /**
* The URI of the resource that has been updated. This might be a sub-resource of the one that the client actually subscribed to. * The URI of the resource that has been updated. This might be a sub-resource of the one that the client actually subscribed to.
*/ */
uri: z.string().url(), uri: z.string().transform((s) => new URL(s)),
}), }),
}); });
/* Prompts */ /* Prompts */
@@ -453,13 +503,13 @@ export const PromptSchema = z.object({
/** /**
* Sent from the client to request a list of prompts and prompt templates the server has. * Sent from the client to request a list of prompts and prompt templates the server has.
*/ */
export const ListPromptsRequestSchema = RequestSchema.extend({ export const ListPromptsRequestSchema = PaginatedRequestSchema.extend({
method: z.literal("prompts/list"), method: z.literal("prompts/list"),
}); });
/** /**
* The server's response to a prompts/list request from the client. * The server's response to a prompts/list request from the client.
*/ */
export const ListPromptsResultSchema = ResultSchema.extend({ export const ListPromptsResultSchema = PaginatedResultSchema.extend({
prompts: z.array(PromptSchema), prompts: z.array(PromptSchema),
}); });
/** /**
@@ -488,6 +538,12 @@ export const GetPromptResultSchema = ResultSchema.extend({
description: z.optional(z.string()), description: z.optional(z.string()),
messages: z.array(SamplingMessageSchema), messages: z.array(SamplingMessageSchema),
}); });
/**
* 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.
*/
export const PromptListChangedNotificationSchema = NotificationSchema.extend({
method: z.literal("notifications/prompts/list_changed"),
});
/* Tools */ /* Tools */
/** /**
* Definition for a tool the client can call. * Definition for a tool the client can call.
@@ -512,13 +568,13 @@ export const ToolSchema = z.object({
/** /**
* Sent from the client to request a list of tools the server has. * Sent from the client to request a list of tools the server has.
*/ */
export const ListToolsRequestSchema = RequestSchema.extend({ export const ListToolsRequestSchema = PaginatedRequestSchema.extend({
method: z.literal("tools/list"), method: z.literal("tools/list"),
}); });
/** /**
* The server's response to a tools/list request from the client. * The server's response to a tools/list request from the client.
*/ */
export const ListToolsResultSchema = ResultSchema.extend({ export const ListToolsResultSchema = PaginatedResultSchema.extend({
tools: z.array(ToolSchema), tools: z.array(ToolSchema),
}); });
/** /**
@@ -722,6 +778,7 @@ export const ServerNotificationSchema = z.union([
ResourceUpdatedNotificationSchema, ResourceUpdatedNotificationSchema,
ResourceListChangedNotificationSchema, ResourceListChangedNotificationSchema,
ToolListChangedNotificationSchema, ToolListChangedNotificationSchema,
PromptListChangedNotificationSchema,
]); ]);
export const ServerResultSchema = z.union([ export const ServerResultSchema = z.union([
EmptyResultSchema, EmptyResultSchema,

2
dist/types.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@@ -37,7 +37,7 @@ export class Client extends Protocol<
{ {
method: "initialize", method: "initialize",
params: { params: {
protocolVersion: 1, protocolVersion: PROTOCOL_VERSION,
capabilities: {}, capabilities: {},
clientInfo: this._clientInfo, clientInfo: this._clientInfo,
}, },

View File

@@ -1,5 +1,7 @@
import { z } from "zod"; import { z } from "zod";
export const PROTOCOL_VERSION = "2024-10-07";
/* JSON-RPC types */ /* JSON-RPC types */
export const JSONRPC_VERSION = "2.0"; export const JSONRPC_VERSION = "2.0";
@@ -8,6 +10,11 @@ export const JSONRPC_VERSION = "2.0";
*/ */
export const ProgressTokenSchema = z.union([z.string(), z.number().int()]); export const ProgressTokenSchema = z.union([z.string(), z.number().int()]);
/**
* An opaque token used to represent a cursor for pagination.
*/
export const CursorSchema = z.string();
export const RequestSchema = z.object({ export const RequestSchema = z.object({
method: z.string(), method: z.string(),
params: z.optional( params: z.optional(
@@ -141,8 +148,6 @@ export const JSONRPCMessageSchema = z.union([
export const EmptyResultSchema = ResultSchema.strict(); export const EmptyResultSchema = ResultSchema.strict();
/* Initialization */ /* Initialization */
export const PROTOCOL_VERSION = 1;
/** /**
* Text provided to or from an LLM. * Text provided to or from an LLM.
*/ */
@@ -208,7 +213,7 @@ export const InitializeRequestSchema = RequestSchema.extend({
/** /**
* The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well. * The latest version of the Model Context Protocol that the client supports. The client MAY decide to support older versions as well.
*/ */
protocolVersion: z.number().int(), protocolVersion: z.string().or(z.number().int()),
capabilities: ClientCapabilitiesSchema, capabilities: ClientCapabilitiesSchema,
clientInfo: ImplementationSchema, clientInfo: ImplementationSchema,
}), }),
@@ -229,7 +234,16 @@ export const ServerCapabilitiesSchema = z.object({
/** /**
* Present if the server offers any prompt templates. * Present if the server offers any prompt templates.
*/ */
prompts: z.optional(z.object({}).passthrough()), prompts: z.optional(
z
.object({
/**
* Whether this server supports notifications for changes to the prompt list.
*/
listChanged: z.optional(z.boolean()),
})
.passthrough(),
),
/** /**
* Present if the server offers any resources to read. * Present if the server offers any resources to read.
*/ */
@@ -240,13 +254,26 @@ export const ServerCapabilitiesSchema = z.object({
* Whether this server supports subscribing to resource updates. * Whether this server supports subscribing to resource updates.
*/ */
subscribe: z.optional(z.boolean()), subscribe: z.optional(z.boolean()),
/**
* Whether this server supports notifications for changes to the resource list.
*/
listChanged: z.optional(z.boolean()),
}) })
.passthrough(), .passthrough(),
), ),
/** /**
* Present if the server offers any tools to call. * Present if the server offers any tools to call.
*/ */
tools: z.optional(z.object({}).passthrough()), tools: z.optional(
z
.object({
/**
* Whether this server supports notifications for changes to the tool list.
*/
listChanged: z.optional(z.boolean()),
})
.passthrough(),
),
}); });
/** /**
@@ -256,7 +283,7 @@ export const InitializeResultSchema = ResultSchema.extend({
/** /**
* The version of the Model Context Protocol that the server wants to use. This may not match the version that the client requested. If the client cannot support this version, it MUST disconnect. * The version of the Model Context Protocol that the server wants to use. This may not match the version that the client requested. If the client cannot support this version, it MUST disconnect.
*/ */
protocolVersion: z.number().int(), protocolVersion: z.string().or(z.number().int()),
capabilities: ServerCapabilitiesSchema, capabilities: ServerCapabilitiesSchema,
serverInfo: ImplementationSchema, serverInfo: ImplementationSchema,
}); });
@@ -301,6 +328,27 @@ export const ProgressNotificationSchema = NotificationSchema.extend({
}), }),
}); });
/* Pagination */
export const PaginatedRequestSchema = RequestSchema.extend({
params: z.optional(
z.object({
/**
* An opaque token representing the current pagination position.
* If provided, the server should return results starting after this cursor.
*/
cursor: z.optional(CursorSchema),
}),
),
});
export const PaginatedResultSchema = ResultSchema.extend({
/**
* An opaque token representing the pagination position after the last returned result.
* If present, there may be more results available.
*/
nextCursor: z.optional(CursorSchema),
});
/* Resources */ /* Resources */
/** /**
* The contents of a specific resource or sub-resource. * The contents of a specific resource or sub-resource.
@@ -309,7 +357,7 @@ export const ResourceContentsSchema = z.object({
/** /**
* The URI of this resource. * The URI of this resource.
*/ */
uri: z.string().url(), uri: z.string().transform((s) => new URL(s)),
/** /**
* The MIME type of this resource, if known. * The MIME type of this resource, if known.
*/ */
@@ -337,7 +385,7 @@ export const ResourceSchema = z.object({
/** /**
* The URI of this resource. * The URI of this resource.
*/ */
uri: z.string().url(), uri: z.string().transform((s) => new URL(s)),
/** /**
* A human-readable name for this resource. * A human-readable name for this resource.
@@ -391,16 +439,31 @@ export const ResourceTemplateSchema = z.object({
/** /**
* Sent from the client to request a list of resources the server has. * Sent from the client to request a list of resources the server has.
*/ */
export const ListResourcesRequestSchema = RequestSchema.extend({ export const ListResourcesRequestSchema = PaginatedRequestSchema.extend({
method: z.literal("resources/list"), method: z.literal("resources/list"),
}); });
/** /**
* The server's response to a resources/list request from the client. * The server's response to a resources/list request from the client.
*/ */
export const ListResourcesResultSchema = ResultSchema.extend({ export const ListResourcesResultSchema = PaginatedResultSchema.extend({
resourceTemplates: z.optional(z.array(ResourceTemplateSchema)), resources: z.array(ResourceSchema),
resources: z.optional(z.array(ResourceSchema)), });
/**
* Sent from the client to request a list of resource templates the server has.
*/
export const ListResourceTemplatesRequestSchema = PaginatedRequestSchema.extend(
{
method: z.literal("resources/templates/list"),
},
);
/**
* The server's response to a resources/templates/list request from the client.
*/
export const ListResourceTemplatesResultSchema = PaginatedResultSchema.extend({
resourceTemplates: z.array(ResourceTemplateSchema),
}); });
/** /**
@@ -412,7 +475,7 @@ export const ReadResourceRequestSchema = RequestSchema.extend({
/** /**
* The URI of the resource to read. The URI can use any protocol; it is up to the server how to interpret it. * The URI of the resource to read. The URI can use any protocol; it is up to the server how to interpret it.
*/ */
uri: z.string().url(), uri: z.string().transform((s) => new URL(s)),
}), }),
}); });
@@ -441,7 +504,7 @@ export const SubscribeRequestSchema = RequestSchema.extend({
/** /**
* The URI of the resource to subscribe to. The URI can use any protocol; it is up to the server how to interpret it. * The URI of the resource to subscribe to. The URI can use any protocol; it is up to the server how to interpret it.
*/ */
uri: z.string().url(), uri: z.string().transform((s) => new URL(s)),
}), }),
}); });
@@ -454,7 +517,7 @@ export const UnsubscribeRequestSchema = RequestSchema.extend({
/** /**
* The URI of the resource to unsubscribe from. * The URI of the resource to unsubscribe from.
*/ */
uri: z.string().url(), uri: z.string().transform((s) => new URL(s)),
}), }),
}); });
@@ -467,7 +530,7 @@ export const ResourceUpdatedNotificationSchema = NotificationSchema.extend({
/** /**
* The URI of the resource that has been updated. This might be a sub-resource of the one that the client actually subscribed to. * The URI of the resource that has been updated. This might be a sub-resource of the one that the client actually subscribed to.
*/ */
uri: z.string().url(), uri: z.string().transform((s) => new URL(s)),
}), }),
}); });
@@ -511,14 +574,14 @@ export const PromptSchema = z.object({
/** /**
* Sent from the client to request a list of prompts and prompt templates the server has. * Sent from the client to request a list of prompts and prompt templates the server has.
*/ */
export const ListPromptsRequestSchema = RequestSchema.extend({ export const ListPromptsRequestSchema = PaginatedRequestSchema.extend({
method: z.literal("prompts/list"), method: z.literal("prompts/list"),
}); });
/** /**
* The server's response to a prompts/list request from the client. * The server's response to a prompts/list request from the client.
*/ */
export const ListPromptsResultSchema = ResultSchema.extend({ export const ListPromptsResultSchema = PaginatedResultSchema.extend({
prompts: z.array(PromptSchema), prompts: z.array(PromptSchema),
}); });
@@ -550,6 +613,13 @@ export const GetPromptResultSchema = ResultSchema.extend({
messages: z.array(SamplingMessageSchema), messages: z.array(SamplingMessageSchema),
}); });
/**
* 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.
*/
export const PromptListChangedNotificationSchema = NotificationSchema.extend({
method: z.literal("notifications/prompts/list_changed"),
});
/* Tools */ /* Tools */
/** /**
* Definition for a tool the client can call. * Definition for a tool the client can call.
@@ -575,14 +645,14 @@ export const ToolSchema = z.object({
/** /**
* Sent from the client to request a list of tools the server has. * Sent from the client to request a list of tools the server has.
*/ */
export const ListToolsRequestSchema = RequestSchema.extend({ export const ListToolsRequestSchema = PaginatedRequestSchema.extend({
method: z.literal("tools/list"), method: z.literal("tools/list"),
}); });
/** /**
* The server's response to a tools/list request from the client. * The server's response to a tools/list request from the client.
*/ */
export const ListToolsResultSchema = ResultSchema.extend({ export const ListToolsResultSchema = PaginatedResultSchema.extend({
tools: z.array(ToolSchema), tools: z.array(ToolSchema),
}); });
@@ -802,6 +872,7 @@ export const ServerNotificationSchema = z.union([
ResourceUpdatedNotificationSchema, ResourceUpdatedNotificationSchema,
ResourceListChangedNotificationSchema, ResourceListChangedNotificationSchema,
ToolListChangedNotificationSchema, ToolListChangedNotificationSchema,
PromptListChangedNotificationSchema,
]); ]);
export const ServerResultSchema = z.union([ export const ServerResultSchema = z.union([
@@ -828,6 +899,7 @@ export class McpError extends Error {
/* JSON-RPC types */ /* JSON-RPC types */
export type ProgressToken = z.infer<typeof ProgressTokenSchema>; export type ProgressToken = z.infer<typeof ProgressTokenSchema>;
export type Cursor = z.infer<typeof CursorSchema>;
export type Request = z.infer<typeof RequestSchema>; export type Request = z.infer<typeof RequestSchema>;
export type Notification = z.infer<typeof NotificationSchema>; export type Notification = z.infer<typeof NotificationSchema>;
export type Result = z.infer<typeof ResultSchema>; export type Result = z.infer<typeof ResultSchema>;
@@ -861,6 +933,10 @@ export type PingRequest = z.infer<typeof PingRequestSchema>;
export type Progress = z.infer<typeof ProgressSchema>; export type Progress = z.infer<typeof ProgressSchema>;
export type ProgressNotification = z.infer<typeof ProgressNotificationSchema>; export type ProgressNotification = z.infer<typeof ProgressNotificationSchema>;
/* Pagination */
export type PaginatedRequest = z.infer<typeof PaginatedRequestSchema>;
export type PaginatedResult = z.infer<typeof PaginatedResultSchema>;
/* Resources */ /* Resources */
export type ResourceContents = z.infer<typeof ResourceContentsSchema>; export type ResourceContents = z.infer<typeof ResourceContentsSchema>;
export type TextResourceContents = z.infer<typeof TextResourceContentsSchema>; export type TextResourceContents = z.infer<typeof TextResourceContentsSchema>;
@@ -869,6 +945,12 @@ export type Resource = z.infer<typeof ResourceSchema>;
export type ResourceTemplate = z.infer<typeof ResourceTemplateSchema>; export type ResourceTemplate = z.infer<typeof ResourceTemplateSchema>;
export type ListResourcesRequest = z.infer<typeof ListResourcesRequestSchema>; export type ListResourcesRequest = z.infer<typeof ListResourcesRequestSchema>;
export type ListResourcesResult = z.infer<typeof ListResourcesResultSchema>; export type ListResourcesResult = z.infer<typeof ListResourcesResultSchema>;
export type ListResourceTemplatesRequest = z.infer<
typeof ListResourceTemplatesRequestSchema
>;
export type ListResourceTemplatesResult = z.infer<
typeof ListResourceTemplatesResultSchema
>;
export type ReadResourceRequest = z.infer<typeof ReadResourceRequestSchema>; export type ReadResourceRequest = z.infer<typeof ReadResourceRequestSchema>;
export type ReadResourceResult = z.infer<typeof ReadResourceResultSchema>; export type ReadResourceResult = z.infer<typeof ReadResourceResultSchema>;
export type ResourceListChangedNotification = z.infer< export type ResourceListChangedNotification = z.infer<
@@ -887,6 +969,9 @@ export type ListPromptsRequest = z.infer<typeof ListPromptsRequestSchema>;
export type ListPromptsResult = z.infer<typeof ListPromptsResultSchema>; export type ListPromptsResult = z.infer<typeof ListPromptsResultSchema>;
export type GetPromptRequest = z.infer<typeof GetPromptRequestSchema>; export type GetPromptRequest = z.infer<typeof GetPromptRequestSchema>;
export type GetPromptResult = z.infer<typeof GetPromptResultSchema>; export type GetPromptResult = z.infer<typeof GetPromptResultSchema>;
export type PromptListChangedNotification = z.infer<
typeof PromptListChangedNotificationSchema
>;
/* Tools */ /* Tools */
export type Tool = z.infer<typeof ToolSchema>; export type Tool = z.infer<typeof ToolSchema>;