Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/spec.types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};

Expand All @@ -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
];
Expand Down
16 changes: 11 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -790,14 +790,19 @@ 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.
*/
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).
Expand Down Expand Up @@ -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
});

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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).
*/
Expand Down Expand Up @@ -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".
*/
Expand Down Expand Up @@ -2349,6 +2354,7 @@ export type Icon = Infer<typeof IconSchema>;
export type Icons = Infer<typeof IconsSchema>;
export type BaseMetadata = Infer<typeof BaseMetadataSchema>;
export type Annotations = Infer<typeof AnnotationsSchema>;
export type Role = Infer<typeof RoleSchema>;

/* Initialization */
export type Implementation = Infer<typeof ImplementationSchema>;
Expand Down
Loading