@@ -1495,6 +1495,12 @@ export const ToolResultContentSchema = z
14951495 } )
14961496 . passthrough ( ) ;
14971497
1498+ /**
1499+ * Basic content types for sampling responses (without tool use).
1500+ * Used for backwards-compatible CreateMessageResult when tools are not used.
1501+ */
1502+ export const SamplingContentSchema = z . discriminatedUnion ( 'type' , [ TextContentSchema , ImageContentSchema , AudioContentSchema ] ) ;
1503+
14981504/**
14991505 * Content block types allowed in sampling messages.
15001506 * This includes text, image, audio, tool use requests, and tool results.
@@ -1576,9 +1582,38 @@ export const CreateMessageRequestSchema = RequestSchema.extend({
15761582} ) ;
15771583
15781584/**
1579- * The client's response to a sampling/create_message request from the server. The client should inform the user before returning the sampled message, to allow them to inspect the response (human in the loop) and decide whether to allow the server to see it.
1585+ * The client's response to a sampling/create_message request from the server.
1586+ * This is the backwards-compatible version that returns single content (no arrays).
1587+ * Used when the request does not include tools.
15801588 */
15811589export const CreateMessageResultSchema = ResultSchema . extend ( {
1590+ /**
1591+ * The name of the model that generated the message.
1592+ */
1593+ model : z . string ( ) ,
1594+ /**
1595+ * The reason why sampling stopped, if known.
1596+ *
1597+ * Standard values:
1598+ * - "endTurn": Natural end of the assistant's turn
1599+ * - "stopSequence": A stop sequence was encountered
1600+ * - "maxTokens": Maximum token limit was reached
1601+ *
1602+ * This field is an open string to allow for provider-specific stop reasons.
1603+ */
1604+ stopReason : z . optional ( z . enum ( [ 'endTurn' , 'stopSequence' , 'maxTokens' ] ) . or ( z . string ( ) ) ) ,
1605+ role : z . enum ( [ 'user' , 'assistant' ] ) ,
1606+ /**
1607+ * Response content. Single content block (text, image, or audio).
1608+ */
1609+ content : SamplingContentSchema
1610+ } ) ;
1611+
1612+ /**
1613+ * The client's response to a sampling/create_message request when tools were provided.
1614+ * This version supports array content for tool use flows.
1615+ */
1616+ export const CreateMessageResultWithToolsSchema = ResultSchema . extend ( {
15821617 /**
15831618 * The name of the model that generated the message.
15841619 */
@@ -1597,7 +1632,7 @@ export const CreateMessageResultSchema = ResultSchema.extend({
15971632 stopReason : z . optional ( z . enum ( [ 'endTurn' , 'stopSequence' , 'maxTokens' , 'toolUse' ] ) . or ( z . string ( ) ) ) ,
15981633 role : z . enum ( [ 'user' , 'assistant' ] ) ,
15991634 /**
1600- * Response content. May be ToolUseContent if stopReason is "toolUse".
1635+ * Response content. May be a single block or array. May include ToolUseContent if stopReason is "toolUse".
16011636 */
16021637 content : z . union ( [ SamplingMessageContentBlockSchema , z . array ( SamplingMessageContentBlockSchema ) ] )
16031638} ) ;
@@ -2010,6 +2045,7 @@ export const ClientNotificationSchema = z.union([
20102045export const ClientResultSchema = z . union ( [
20112046 EmptyResultSchema ,
20122047 CreateMessageResultSchema ,
2048+ CreateMessageResultWithToolsSchema ,
20132049 ElicitResultSchema ,
20142050 ListRootsResultSchema ,
20152051 GetTaskResultSchema ,
@@ -2285,11 +2321,26 @@ export type LoggingMessageNotification = Infer<typeof LoggingMessageNotification
22852321export type ToolChoice = Infer < typeof ToolChoiceSchema > ;
22862322export type ModelHint = Infer < typeof ModelHintSchema > ;
22872323export type ModelPreferences = Infer < typeof ModelPreferencesSchema > ;
2324+ export type SamplingContent = Infer < typeof SamplingContentSchema > ;
22882325export type SamplingMessageContentBlock = Infer < typeof SamplingMessageContentBlockSchema > ;
22892326export type SamplingMessage = Infer < typeof SamplingMessageSchema > ;
22902327export type CreateMessageRequestParams = Infer < typeof CreateMessageRequestParamsSchema > ;
22912328export type CreateMessageRequest = Infer < typeof CreateMessageRequestSchema > ;
22922329export type CreateMessageResult = Infer < typeof CreateMessageResultSchema > ;
2330+ export type CreateMessageResultWithTools = Infer < typeof CreateMessageResultWithToolsSchema > ;
2331+
2332+ /**
2333+ * CreateMessageRequestParams without tools - for backwards-compatible overload.
2334+ * Excludes tools/toolChoice to indicate they should not be provided.
2335+ */
2336+ export type CreateMessageRequestParamsBase = Omit < CreateMessageRequestParams , 'tools' | 'toolChoice' > ;
2337+
2338+ /**
2339+ * CreateMessageRequestParams with required tools - for tool-enabled overload.
2340+ */
2341+ export interface CreateMessageRequestParamsWithTools extends CreateMessageRequestParams {
2342+ tools : Tool [ ] ;
2343+ }
22932344
22942345/* Elicitation */
22952346export type BooleanSchema = Infer < typeof BooleanSchemaSchema > ;
0 commit comments