diff --git a/src/spec.types.test.ts b/src/spec.types.test.ts index 539ea38ff..688694473 100644 --- a/src/spec.types.test.ts +++ b/src/spec.types.test.ts @@ -660,6 +660,10 @@ const sdkTypeChecks = { Annotations: (sdk: SDKTypes.Annotations, spec: SpecTypes.Annotations) => { sdk = spec; spec = sdk; + }, + Role: (sdk: SDKTypes.Role, spec: SpecTypes.Role) => { + sdk = spec; + spec = sdk; } }; @@ -669,7 +673,6 @@ const SDK_TYPES_FILE = 'src/types.ts'; const MISSING_SDK_TYPES = [ // These are inlined in the SDK: - 'Role', 'Error', // The inner error object of a JSONRPCError 'URLElicitationRequiredError' // In the SDK, but with a custom definition ]; diff --git a/src/types.ts b/src/types.ts index 67e072742..49a1c4b6d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -790,6 +790,11 @@ export const BlobResourceContentsSchema = ResourceContentsSchema.extend({ blob: Base64Schema }); +/** + * The sender or recipient of messages and data in a conversation. + */ +export const RoleSchema = z.enum(['user', 'assistant']); + /** * Optional annotations providing clients additional context about a resource. */ @@ -797,7 +802,7 @@ export const AnnotationsSchema = z.object({ /** * Intended audience(s) for the resource. */ - audience: z.array(z.enum(['user', 'assistant'])).optional(), + audience: z.array(RoleSchema).optional(), /** * Importance hint for the resource, from 0 (least) to 1 (most). @@ -1200,7 +1205,7 @@ export const ContentBlockSchema = z.union([ * Describes a message returned as part of a prompt. */ export const PromptMessageSchema = z.object({ - role: z.enum(['user', 'assistant']), + role: RoleSchema, content: ContentBlockSchema }); @@ -1647,7 +1652,7 @@ export const SamplingMessageContentBlockSchema = z.discriminatedUnion('type', [ */ export const SamplingMessageSchema = z .object({ - role: z.enum(['user', 'assistant']), + role: RoleSchema, content: z.union([SamplingMessageContentBlockSchema, z.array(SamplingMessageContentBlockSchema)]), /** * See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) @@ -1731,7 +1736,7 @@ export const CreateMessageResultSchema = ResultSchema.extend({ * This field is an open string to allow for provider-specific stop reasons. */ stopReason: z.optional(z.enum(['endTurn', 'stopSequence', 'maxTokens']).or(z.string())), - role: z.enum(['user', 'assistant']), + role: RoleSchema, /** * Response content. Single content block (text, image, or audio). */ @@ -1759,7 +1764,7 @@ export const CreateMessageResultWithToolsSchema = ResultSchema.extend({ * This field is an open string to allow for provider-specific stop reasons. */ stopReason: z.optional(z.enum(['endTurn', 'stopSequence', 'maxTokens', 'toolUse']).or(z.string())), - role: z.enum(['user', 'assistant']), + role: RoleSchema, /** * Response content. May be a single block or array. May include ToolUseContent if stopReason is "toolUse". */ @@ -2349,6 +2354,7 @@ export type Icon = Infer; export type Icons = Infer; export type BaseMetadata = Infer; export type Annotations = Infer; +export type Role = Infer; /* Initialization */ export type Implementation = Infer;