1111string key = Environment . GetEnvironmentVariable ( "OPENAI_API_KEY" ) ! ;
1212OpenAIResponseClient client = new ( model : "gpt-5" , apiKey : key ) ;
1313
14- ResponseCreationOptions options1 = new ( ) ;
15- options1 . Tools . Add ( ResponseTool . CreateMcpTool (
16- serverLabel : "dmcp" ,
17- serverUri : new Uri ( "https://dmcp-server.deno.dev/sse" )
18- ) ) ;
19-
20- McpToolCallApprovalRequestItem request1 = ResponseItem . CreateMcpApprovalRequestItem (
21- serverLabel : "dmcp" ,
22- name : "roll" ,
23- arguments : BinaryData . FromObjectAsJson ( new { diceRollExpression = "2d4+1" } )
24- ) ;
25-
26- OpenAIResponse response1 = ( OpenAIResponse ) client . CreateResponse ( [
27- request1
28- ] , options1 ) ;
29-
30- ResponseCreationOptions options2 = new ( ) ;
31- options2 . Tools . Add ( ResponseTool . CreateMcpTool (
14+ ResponseCreationOptions options = new ( ) ;
15+ options . Tools . Add ( ResponseTool . CreateMcpTool (
3216 serverLabel : "dmcp" ,
3317 serverUri : new Uri ( "https://dmcp-server.deno.dev/sse" ) ,
3418 toolCallApprovalPolicy : new McpToolCallApprovalPolicy ( GlobalMcpToolCallApprovalPolicy . AlwaysRequireApproval )
3519) ) ;
3620
37- options2 . PreviousResponseId = response1 . Id ;
21+ // STEP 1: Create response that requests tool call approval
22+ OpenAIResponse response1 = ( OpenAIResponse ) client . CreateResponse ( [
23+ ResponseItem . CreateUserMessageItem ( [
24+ ResponseContentPart . CreateInputTextPart ( "Roll 2d4+1" )
25+ ] )
26+ ] , options ) ;
27+
28+ McpToolCallApprovalRequestItem ? approvalRequestItem = response1 . OutputItems . Last ( ) as McpToolCallApprovalRequestItem ;
3829
30+ // STEP 2: Approve the tool call request and get final response
31+ options . PreviousResponseId = response1 . Id ;
3932OpenAIResponse response2 = ( OpenAIResponse ) client . CreateResponse ( [
40- request1 ,
41- ResponseItem . CreateMcpApprovalResponseItem ( request1 . Id , approved : true ) ,
42- ] , options2 ) ;
33+ ResponseItem . CreateMcpApprovalResponseItem ( approvalRequestItem ! . Id , approved : true ) ,
34+ ] , options ) ;
4335
4436Console . WriteLine ( response2 . GetOutputText ( ) ) ;
0 commit comments