Treat URIs as 'URL' type
This commit is contained in:
parent
f3a8fb8685
commit
ec96ffc958
1 changed files with 133 additions and 116 deletions
79
src/types.ts
79
src/types.ts
|
|
@ -2,7 +2,6 @@ import { z } from "zod";
|
|||
|
||||
export const PROTOCOL_VERSION = "2024-10-07";
|
||||
|
||||
|
||||
/* JSON-RPC types */
|
||||
export const JSONRPC_VERSION = "2.0";
|
||||
|
||||
|
|
@ -236,38 +235,44 @@ export const ServerCapabilitiesSchema = z.object({
|
|||
* Present if the server offers any prompt templates.
|
||||
*/
|
||||
prompts: z.optional(
|
||||
z.object({
|
||||
/**
|
||||
* Whether this server supports notifications for changes to the prompt list.
|
||||
*/
|
||||
listChanged: z.optional(z.boolean()),
|
||||
}).passthrough(),
|
||||
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.
|
||||
*/
|
||||
resources: z.optional(
|
||||
z.object({
|
||||
/**
|
||||
* Whether this server supports subscribing to resource updates.
|
||||
*/
|
||||
subscribe: z.optional(z.boolean()),
|
||||
/**
|
||||
* Whether this server supports notifications for changes to the resource list.
|
||||
*/
|
||||
listChanged: z.optional(z.boolean()),
|
||||
}).passthrough(),
|
||||
z
|
||||
.object({
|
||||
/**
|
||||
* Whether this server supports subscribing to resource updates.
|
||||
*/
|
||||
subscribe: z.optional(z.boolean()),
|
||||
/**
|
||||
* Whether this server supports notifications for changes to the resource list.
|
||||
*/
|
||||
listChanged: z.optional(z.boolean()),
|
||||
})
|
||||
.passthrough(),
|
||||
),
|
||||
/**
|
||||
* Present if the server offers any tools to call.
|
||||
*/
|
||||
tools: z.optional(
|
||||
z.object({
|
||||
/**
|
||||
* Whether this server supports notifications for changes to the tool list.
|
||||
*/
|
||||
listChanged: z.optional(z.boolean()),
|
||||
}).passthrough(),
|
||||
z
|
||||
.object({
|
||||
/**
|
||||
* Whether this server supports notifications for changes to the tool list.
|
||||
*/
|
||||
listChanged: z.optional(z.boolean()),
|
||||
})
|
||||
.passthrough(),
|
||||
),
|
||||
});
|
||||
|
||||
|
|
@ -352,7 +357,7 @@ export const ResourceContentsSchema = z.object({
|
|||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
|
@ -380,7 +385,7 @@ export const ResourceSchema = z.object({
|
|||
/**
|
||||
* The URI of this resource.
|
||||
*/
|
||||
uri: z.string().url(),
|
||||
uri: z.string().transform((s) => new URL(s)),
|
||||
|
||||
/**
|
||||
* A human-readable name for this resource.
|
||||
|
|
@ -448,9 +453,11 @@ export const ListResourcesResultSchema = PaginatedResultSchema.extend({
|
|||
/**
|
||||
* 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"),
|
||||
});
|
||||
export const ListResourceTemplatesRequestSchema = PaginatedRequestSchema.extend(
|
||||
{
|
||||
method: z.literal("resources/templates/list"),
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* The server's response to a resources/templates/list request from the client.
|
||||
|
|
@ -468,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.
|
||||
*/
|
||||
uri: z.string().url(),
|
||||
uri: z.string().transform((s) => new URL(s)),
|
||||
}),
|
||||
});
|
||||
|
||||
|
|
@ -497,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.
|
||||
*/
|
||||
uri: z.string().url(),
|
||||
uri: z.string().transform((s) => new URL(s)),
|
||||
}),
|
||||
});
|
||||
|
||||
|
|
@ -510,7 +517,7 @@ export const UnsubscribeRequestSchema = RequestSchema.extend({
|
|||
/**
|
||||
* The URI of the resource to unsubscribe from.
|
||||
*/
|
||||
uri: z.string().url(),
|
||||
uri: z.string().transform((s) => new URL(s)),
|
||||
}),
|
||||
});
|
||||
|
||||
|
|
@ -523,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.
|
||||
*/
|
||||
uri: z.string().url(),
|
||||
uri: z.string().transform((s) => new URL(s)),
|
||||
}),
|
||||
});
|
||||
|
||||
|
|
@ -938,8 +945,12 @@ export type Resource = z.infer<typeof ResourceSchema>;
|
|||
export type ResourceTemplate = z.infer<typeof ResourceTemplateSchema>;
|
||||
export type ListResourcesRequest = z.infer<typeof ListResourcesRequestSchema>;
|
||||
export type ListResourcesResult = z.infer<typeof ListResourcesResultSchema>;
|
||||
export type ListResourceTemplatesRequest = z.infer<typeof ListResourceTemplatesRequestSchema>;
|
||||
export type ListResourceTemplatesResult = z.infer<typeof ListResourceTemplatesResultSchema>;
|
||||
export type ListResourceTemplatesRequest = z.infer<
|
||||
typeof ListResourceTemplatesRequestSchema
|
||||
>;
|
||||
export type ListResourceTemplatesResult = z.infer<
|
||||
typeof ListResourceTemplatesResultSchema
|
||||
>;
|
||||
export type ReadResourceRequest = z.infer<typeof ReadResourceRequestSchema>;
|
||||
export type ReadResourceResult = z.infer<typeof ReadResourceResultSchema>;
|
||||
export type ResourceListChangedNotification = z.infer<
|
||||
|
|
|
|||
Loading…
Reference in a new issue