@@ -12,6 +12,8 @@ import {
12
12
Base64ImageSource ,
13
13
ContentBlock ,
14
14
ContentBlockParam ,
15
+ TextBlockParam ,
16
+ ImageBlockParam ,
15
17
Tool as ClaudeTool ,
16
18
ToolChoiceAuto ,
17
19
ToolChoiceAny ,
@@ -41,6 +43,9 @@ import {
41
43
JSONRPCNotification ,
42
44
AssistantMessageContent ,
43
45
UserMessageContent ,
46
+ ElicitResult ,
47
+ ElicitResultSchema ,
48
+ TextContent ,
44
49
} from "../../types.js" ;
45
50
import { Transport } from "../../shared/transport.js" ;
46
51
@@ -57,6 +62,9 @@ const isCallToolRequest: (value: unknown) => value is CallToolRequest =
57
62
const isElicitRequest : ( value : unknown ) => value is ElicitRequest =
58
63
( ( value : any ) => ElicitRequestSchema . safeParse ( value ) . success ) as any ;
59
64
65
+ const isElicitResult : ( value : unknown ) => value is ElicitResult =
66
+ ( ( value : any ) => ElicitResultSchema . safeParse ( value ) . success ) as any ;
67
+
60
68
const isCreateMessageRequest : ( value : unknown ) => value is CreateMessageRequest =
61
69
( ( value : any ) => CreateMessageRequestSchema . safeParse ( value ) . success ) as any ;
62
70
@@ -115,8 +123,10 @@ function stopReasonToMcp(reason: string | null): CreateMessageResult['stopReason
115
123
return 'toolUse' ;
116
124
case 'end_turn' :
117
125
return 'endTurn' ;
126
+ case null :
127
+ return undefined ;
118
128
default :
119
- return 'other' ;
129
+ throw new Error ( `[stopReasonToMcp] Unsupported stop reason: ${ reason } ` ) ;
120
130
}
121
131
}
122
132
@@ -138,7 +148,23 @@ function contentBlockFromMcp(content: AssistantMessageContent | UserMessageConte
138
148
return {
139
149
type : 'tool_result' ,
140
150
tool_use_id : content . toolUseId ,
141
- content : JSON . stringify ( content . content ) , // TODO
151
+ content : content . content . map ( c => {
152
+ if ( c . type === 'text' ) {
153
+ return { type : 'text' , text : c . text } ;
154
+ } else if ( c . type === 'image' ) {
155
+ return {
156
+ type : 'image' ,
157
+ source : {
158
+ type : 'base64' ,
159
+ data : c . data ,
160
+ media_type : c . mimeType as Base64ImageSource [ 'media_type' ] ,
161
+ } ,
162
+ } ;
163
+ } else {
164
+ throw new Error ( `[contentBlockFromMcp] Unsupported content type in tool_result: ${ c . type } ` ) ;
165
+ }
166
+ } ) ,
167
+ is_error : content . isError ,
142
168
} ;
143
169
case 'tool_use' :
144
170
return {
0 commit comments