18 18
19Use the `mcp` tool type in the [Responses API](https://developers.openai.com/api/reference/resources/responses/methods/create). Set `server_url` for a remote MCP server, or use `tunnel_id` for a local MCP server through [Secure MCP Tunnel](https://developers.openai.com/api/docs/guides/secure-mcp-tunnels). Depending on the server, you may also need an OAuth access token in the `authorization` parameter.19Use the `mcp` tool type in the [Responses API](https://developers.openai.com/api/reference/resources/responses/methods/create). Set `server_url` for a remote MCP server, or use `tunnel_id` for a local MCP server through [Secure MCP Tunnel](https://developers.openai.com/api/docs/guides/secure-mcp-tunnels). Depending on the server, you may also need an OAuth access token in the `authorization` parameter.
20 20
21The following example uses the public [OpenAI Docs MCP server](https://developers.openai.com/resources/docs-mcp) to find documentation about streaming Responses API output. This server provides read-only documentation tools and does not require authentication. The example skips tool-call approvals for this public documentation query; use approvals when sharing sensitive data.
22
21Using a remote MCP server in the Responses API23Using a remote MCP server in the Responses API
22 24
23```bash25```bash
29 "tools": [31 "tools": [
30 {32 {
31 "type": "mcp",33 "type": "mcp",
32 "server_label": "dmcp",34 "server_label": "openai_docs",
33 "server_description": "A Dungeons and Dragons MCP server to assist with dice rolling.",35 "server_description": "Search and read the public OpenAI documentation.",
34 "server_url": "https://dmcp-server.deno.dev/mcp",36 "server_url": "https://developers.openai.com/mcp",
35 "require_approval": "never"37 "require_approval": "never"
36 }38 }
37 ],39 ],
38 "input": "Roll 2d4+1"40 "input": "Search the OpenAI docs for Responses API streaming and return the relevant links."
39 }'41 }'
40```42```
41 43
48 tools: [50 tools: [
49 {51 {
50 type: "mcp",52 type: "mcp",
51 server_label: "dmcp",53 server_label: "openai_docs",
52 server_description:54 server_description: "Search and read the public OpenAI documentation.",
53 "A Dungeons and Dragons MCP server to assist with dice rolling.",55 server_url: "https://developers.openai.com/mcp",
54 server_url: "https://dmcp-server.deno.dev/mcp",
55 require_approval: "never",56 require_approval: "never",
56 },57 },
57 ],58 ],
58 input: "Roll 2d4+1",59 input:
60 "Search the OpenAI docs for Responses API streaming and return the relevant links.",
59});61});
60 62
61console.log(resp.output_text);63console.log(resp.output_text);
71 tools=[73 tools=[
72 {74 {
73 "type": "mcp",75 "type": "mcp",
74 "server_label": "dmcp",76 "server_label": "openai_docs",
75 "server_description": "A Dungeons and Dragons MCP server to assist with dice rolling.",77 "server_description": "Search and read the public OpenAI documentation.",
76 "server_url": "https://dmcp-server.deno.dev/mcp",78 "server_url": "https://developers.openai.com/mcp",
77 "require_approval": "never",79 "require_approval": "never",
78 },80 },
79 ],81 ],
80 input="Roll 2d4+1",82 input="Search the OpenAI docs for Responses API streaming and return the relevant links.",
81)83)
82 84
83print(resp.output_text)85print(resp.output_text)
96 98
97func main() {99func main() {
98 client := openai.NewClient()100 client := openai.NewClient()
99 tool := responses.ToolParamOfMcp("dmcp")101 tool := responses.ToolParamOfMcp("openai_docs")
100 tool.OfMcp.ServerDescription = openai.String("A Dungeons and Dragons MCP server to assist with dice rolling.")102 tool.OfMcp.ServerDescription = openai.String("Search and read the public OpenAI documentation.")
101 tool.OfMcp.ServerURL = openai.String("https://dmcp-server.deno.dev/mcp")103 tool.OfMcp.ServerURL = openai.String("https://developers.openai.com/mcp")
102 tool.OfMcp.RequireApproval = responses.ToolMcpRequireApprovalUnionParam{OfMcpToolApprovalSetting: openai.String("never")}104 tool.OfMcp.RequireApproval = responses.ToolMcpRequireApprovalUnionParam{OfMcpToolApprovalSetting: openai.String("never")}
103 105
104 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{106 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{
105 Model: "gpt-6-astra",107 Model: "gpt-6-astra",
106 Tools: []responses.ToolUnionParam{tool},108 Tools: []responses.ToolUnionParam{tool},
107 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Roll 2d4+1")},109 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Search the OpenAI docs for Responses API streaming and return the relevant links.")},
108 })110 })
109 if err != nil {111 if err != nil {
110 panic(err)112 panic(err)
122ResponseCreateParams params =124ResponseCreateParams params =
123 ResponseCreateParams.builder()125 ResponseCreateParams.builder()
124 .model("gpt-6-astra")126 .model("gpt-6-astra")
125 .input("Roll 2d4+1")127 .input(
128 "Search the OpenAI docs for Responses API streaming and return the relevant links.")
126 .addTool(129 .addTool(
127 Tool.Mcp.builder()130 Tool.Mcp.builder()
128 .serverLabel("dmcp")131 .serverLabel("openai_docs")
129 .serverDescription(132 .serverDescription("Search and read the public OpenAI documentation.")
130 "A Dungeons and Dragons MCP server to assist with dice rolling.")133 .serverUrl("https://developers.openai.com/mcp")
131 .serverUrl("https://dmcp-server.deno.dev/mcp")
132 .requireApproval(Tool.Mcp.RequireApproval.McpToolApprovalSetting.NEVER)134 .requireApproval(Tool.Mcp.RequireApproval.McpToolApprovalSetting.NEVER)
133 .build())135 .build())
134 .build();136 .build();
150CreateResponseOptions options = new() { Model = "gpt-6-astra" };152CreateResponseOptions options = new() { Model = "gpt-6-astra" };
151options.Tools.Add(153options.Tools.Add(
152 ResponseTool.CreateMcpTool(154 ResponseTool.CreateMcpTool(
153 serverLabel: "dmcp",155 serverLabel: "openai_docs",
154 serverUri: new Uri("https://dmcp-server.deno.dev/mcp"),156 serverUri: new Uri("https://developers.openai.com/mcp"),
155 toolCallApprovalPolicy: DefaultMcpToolCallApprovalPolicy.NeverRequireApproval157 toolCallApprovalPolicy: DefaultMcpToolCallApprovalPolicy.NeverRequireApproval
156 )158 )
157);159);
158options.InputItems.Add(ResponseItem.CreateUserMessageItem("Roll 2d4+1"));160options.InputItems.Add(ResponseItem.CreateUserMessageItem("Search the OpenAI docs for Responses API streaming and return the relevant links."));
159 161
160ResponseResult response = await client.CreateResponseAsync(options);162ResponseResult response = await client.CreateResponseAsync(options);
161 163
172 tools: [174 tools: [
173 {175 {
174 type: "mcp",176 type: "mcp",
175 server_label: "dmcp",177 server_label: "openai_docs",
176 server_description: "A Dungeons and Dragons MCP server to assist with dice rolling.",178 server_description: "Search and read the public OpenAI documentation.",
177 server_url: "https://dmcp-server.deno.dev/mcp",179 server_url: "https://developers.openai.com/mcp",
178 require_approval: "never"180 require_approval: "never"
179 }181 }
180 ],182 ],
181 input: "Roll 2d4+1"183 input: "Search the OpenAI docs for Responses API streaming and return the relevant links."
182)184)
183 185
184puts(response.output_text)186puts(response.output_text)
190 anything that enters the model's context. Carefully review the 192 anything that enters the model's context. Carefully review the
191 **Risks and Safety** section below before using this tool.193 **Risks and Safety** section below before using this tool.
192 194
193The API will return new items in the `output` array of the model response. If the model decides to use an MCP server, it will first make a request to list available tools from the server, which will create a `mcp_list_tools` output item. From the remote MCP server example above, it contains only one tool definition:195The API will return new items in the `output` array of the model response. If the model decides to use an MCP server, it will first make a request to list available tools from the server, which will create a `mcp_list_tools` output item. The following illustrative output shows only the search tool, with its description shortened. The server also exposes other documentation tools.
194 196
195```json197```json
196{198{
197 "id": "mcpl_68a6102a4968819c8177b05584dd627b0679e572a900e618",199 "id": "mcpl_68a6102a4968819c8177b05584dd627b0679e572a900e618",
198 "type": "mcp_list_tools",200 "type": "mcp_list_tools",
199 "server_label": "dmcp",201 "server_label": "openai_docs",
200 "tools": [202 "tools": [
201 {203 {
202 "annotations": null,204 "annotations": {
203 "description": "Given a string of text describing a dice roll...",205 "readOnlyHint": true,
206 "destructiveHint": false
207 },
208 "description": "Search the public OpenAI documentation.",
204 "input_schema": {209 "input_schema": {
205 "$schema": "https://json-schema.org/draft/2020-12/schema",210 "$schema": "http://json-schema.org/draft-07/schema#",
206 "type": "object",211 "type": "object",
207 "properties": {212 "properties": {
208 "diceRollExpression": {213 "query": {
214 "type": "string",
215 "minLength": 1
216 },
217 "limit": {
218 "type": "integer",
219 "minimum": 1,
220 "maximum": 50
221 },
222 "cursor": {
209 "type": "string"223 "type": "string"
210 }224 }
211 },225 },
212 "required": ["diceRollExpression"],226 "required": ["query"]
213 "additionalProperties": false
214 },227 },
215 "name": "roll"228 "name": "search_openai_docs"
216 }229 }
217 ]230 ]
218}231}
225 "id": "mcp_68a6102d8948819c9b1490d36d5ffa4a0679e572a900e618",238 "id": "mcp_68a6102d8948819c9b1490d36d5ffa4a0679e572a900e618",
226 "type": "mcp_call",239 "type": "mcp_call",
227 "approval_request_id": null,240 "approval_request_id": null,
228 "arguments": "{\"diceRollExpression\":\"2d4 + 1\"}",241 "arguments": "{\"query\":\"Responses API streaming\",\"limit\":1}",
229 "error": null,242 "error": null,
230 "name": "roll",243 "name": "search_openai_docs",
231 "output": "4",244 "output": "{\"hits\":[{\"url\":\"https://developers.openai.com/api/docs/guides/streaming-responses\"}]}",
232 "server_label": "dmcp"245 "server_label": "openai_docs"
233}246}
234```247```
235 248
245 258
246When you specify a remote MCP server in the `tools` parameter, the API will attempt to get a list of tools from the server. The Responses API works with remote MCP servers that support either the Streamable HTTP or the HTTP/SSE transport protocols.259When you specify a remote MCP server in the `tools` parameter, the API will attempt to get a list of tools from the server. The Responses API works with remote MCP servers that support either the Streamable HTTP or the HTTP/SSE transport protocols.
247 260
248If successful in retrieving the list of tools, a new `mcp_list_tools` output item will appear in the model response output. The `tools` property of this object will show the tools that were successfully imported.261If successful in retrieving the list of tools, a new `mcp_list_tools` output item will appear in the model response output. The `tools` property of this object will show the tools that were successfully imported. This illustrative excerpt shows only the search tool, with its description shortened.
249 262
250```json263```json
251{264{
252 "id": "mcpl_68a6102a4968819c8177b05584dd627b0679e572a900e618",265 "id": "mcpl_68a6102a4968819c8177b05584dd627b0679e572a900e618",
253 "type": "mcp_list_tools",266 "type": "mcp_list_tools",
254 "server_label": "dmcp",267 "server_label": "openai_docs",
255 "tools": [268 "tools": [
256 {269 {
257 "annotations": null,270 "annotations": {
258 "description": "Given a string of text describing a dice roll...",271 "readOnlyHint": true,
272 "destructiveHint": false
273 },
274 "description": "Search the public OpenAI documentation.",
259 "input_schema": {275 "input_schema": {
260 "$schema": "https://json-schema.org/draft/2020-12/schema",276 "$schema": "http://json-schema.org/draft-07/schema#",
261 "type": "object",277 "type": "object",
262 "properties": {278 "properties": {
263 "diceRollExpression": {279 "query": {
280 "type": "string",
281 "minLength": 1
282 },
283 "limit": {
284 "type": "integer",
285 "minimum": 1,
286 "maximum": 50
287 },
288 "cursor": {
264 "type": "string"289 "type": "string"
265 }290 }
266 },291 },
267 "required": ["diceRollExpression"],292 "required": ["query"]
268 "additionalProperties": false
269 },293 },
270 "name": "roll"294 "name": "search_openai_docs"
271 }295 }
272 ]296 ]
273}297}
281 305
282#### Filtering tools306#### Filtering tools
283 307
284Some MCP servers can have dozens of tools, and exposing many tools to the model can result in high cost and latency. If you're only interested in a subset of tools an MCP server exposes, you can use the `allowed_tools` parameter to only import those tools.308Some MCP servers can have dozens of tools, and exposing many tools to the model can result in high cost and latency. If you're only interested in a subset of tools an MCP server exposes, you can use the `allowed_tools` parameter to only import those tools. This example imports only `search_openai_docs` to find documentation links.
285 309
286Constrain allowed tools310Constrain allowed tools
287 311
294 "tools": [318 "tools": [
295 {319 {
296 "type": "mcp",320 "type": "mcp",
297 "server_label": "dmcp",321 "server_label": "openai_docs",
298 "server_description": "A Dungeons and Dragons MCP server to assist with dice rolling.",322 "server_description": "Search and read the public OpenAI documentation.",
299 "server_url": "https://dmcp-server.deno.dev/mcp",323 "server_url": "https://developers.openai.com/mcp",
300 "require_approval": "never",324 "require_approval": "never",
301 "allowed_tools": ["roll"]325 "allowed_tools": ["search_openai_docs"]
302 }326 }
303 ],327 ],
304 "input": "Roll 2d4+1"328 "input": "Search the OpenAI docs for Responses API streaming and return the relevant links."
305 }'329 }'
306```330```
307 331
314 tools: [338 tools: [
315 {339 {
316 type: "mcp",340 type: "mcp",
317 server_label: "dmcp",341 server_label: "openai_docs",
318 server_description:342 server_description: "Search and read the public OpenAI documentation.",
319 "A Dungeons and Dragons MCP server to assist with dice rolling.",343 server_url: "https://developers.openai.com/mcp",
320 server_url: "https://dmcp-server.deno.dev/mcp",
321 require_approval: "never",344 require_approval: "never",
322 allowed_tools: ["roll"],345 allowed_tools: ["search_openai_docs"],
323 },346 },
324 ],347 ],
325 input: "Roll 2d4+1",348 input:
349 "Search the OpenAI docs for Responses API streaming and return the relevant links.",
326});350});
327 351
328console.log(resp.output_text);352console.log(resp.output_text);
338 tools=[362 tools=[
339 {363 {
340 "type": "mcp",364 "type": "mcp",
341 "server_label": "dmcp",365 "server_label": "openai_docs",
342 "server_description": "A Dungeons and Dragons MCP server to assist with dice rolling.",366 "server_description": "Search and read the public OpenAI documentation.",
343 "server_url": "https://dmcp-server.deno.dev/mcp",367 "server_url": "https://developers.openai.com/mcp",
344 "require_approval": "never",368 "require_approval": "never",
345 "allowed_tools": ["roll"],369 "allowed_tools": ["search_openai_docs"],
346 }370 }
347 ],371 ],
348 input="Roll 2d4+1",372 input="Search the OpenAI docs for Responses API streaming and return the relevant links.",
349)373)
350 374
351print(resp.output_text)375print(resp.output_text)
364 388
365func main() {389func main() {
366 client := openai.NewClient()390 client := openai.NewClient()
367 tool := responses.ToolParamOfMcp("dmcp")391 tool := responses.ToolParamOfMcp("openai_docs")
368 tool.OfMcp.ServerDescription = openai.String("A Dungeons and Dragons MCP server to assist with dice rolling.")392 tool.OfMcp.ServerDescription = openai.String("Search and read the public OpenAI documentation.")
369 tool.OfMcp.ServerURL = openai.String("https://dmcp-server.deno.dev/mcp")393 tool.OfMcp.ServerURL = openai.String("https://developers.openai.com/mcp")
370 tool.OfMcp.RequireApproval = responses.ToolMcpRequireApprovalUnionParam{OfMcpToolApprovalSetting: openai.String("never")}394 tool.OfMcp.RequireApproval = responses.ToolMcpRequireApprovalUnionParam{OfMcpToolApprovalSetting: openai.String("never")}
371 tool.OfMcp.AllowedTools = responses.ToolMcpAllowedToolsUnionParam{OfMcpAllowedTools: []string{"roll"}}395 tool.OfMcp.AllowedTools = responses.ToolMcpAllowedToolsUnionParam{OfMcpAllowedTools: []string{"search_openai_docs"}}
372 396
373 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{397 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{
374 Model: "gpt-6-astra",398 Model: "gpt-6-astra",
375 Tools: []responses.ToolUnionParam{tool},399 Tools: []responses.ToolUnionParam{tool},
376 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Roll 2d4+1")},400 Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Search the OpenAI docs for Responses API streaming and return the relevant links.")},
377 })401 })
378 if err != nil {402 if err != nil {
379 panic(err)403 panic(err)
392ResponseCreateParams params =416ResponseCreateParams params =
393 ResponseCreateParams.builder()417 ResponseCreateParams.builder()
394 .model("gpt-6-astra")418 .model("gpt-6-astra")
395 .input("Roll 2d4+1")419 .input(
420 "Search the OpenAI docs for Responses API streaming and return the relevant links.")
396 .addTool(421 .addTool(
397 Tool.Mcp.builder()422 Tool.Mcp.builder()
398 .serverLabel("dmcp")423 .serverLabel("openai_docs")
399 .serverDescription(424 .serverDescription("Search and read the public OpenAI documentation.")
400 "A Dungeons and Dragons MCP server to assist with dice rolling.")425 .serverUrl("https://developers.openai.com/mcp")
401 .serverUrl("https://dmcp-server.deno.dev/mcp")
402 .requireApproval(Tool.Mcp.RequireApproval.McpToolApprovalSetting.NEVER)426 .requireApproval(Tool.Mcp.RequireApproval.McpToolApprovalSetting.NEVER)
403 .allowedToolsOfMcp(List.of("roll"))427 .allowedToolsOfMcp(List.of("search_openai_docs"))
404 .build())428 .build())
405 .build();429 .build();
406 430
421CreateResponseOptions options = new() { Model = "gpt-6-astra" };445CreateResponseOptions options = new() { Model = "gpt-6-astra" };
422options.Tools.Add(446options.Tools.Add(
423 ResponseTool.CreateMcpTool(447 ResponseTool.CreateMcpTool(
424 serverLabel: "dmcp",448 serverLabel: "openai_docs",
425 serverUri: new Uri("https://dmcp-server.deno.dev/mcp"),449 serverUri: new Uri("https://developers.openai.com/mcp"),
426 allowedTools: new McpToolFilter() { ToolNames = { "roll" } },450 allowedTools: new McpToolFilter() { ToolNames = { "search_openai_docs" } },
427 toolCallApprovalPolicy: DefaultMcpToolCallApprovalPolicy.NeverRequireApproval451 toolCallApprovalPolicy: DefaultMcpToolCallApprovalPolicy.NeverRequireApproval
428 )452 )
429);453);
430options.InputItems.Add(ResponseItem.CreateUserMessageItem("Roll 2d4+1"));454options.InputItems.Add(ResponseItem.CreateUserMessageItem("Search the OpenAI docs for Responses API streaming and return the relevant links."));
431 455
432ResponseResult response = await client.CreateResponseAsync(options);456ResponseResult response = await client.CreateResponseAsync(options);
433 457
441 465
442response = client.responses.create(466response = client.responses.create(
443 model: "gpt-6-astra",467 model: "gpt-6-astra",
444 input: "Roll 2d4+1",468 input: "Search the OpenAI docs for Responses API streaming and return the relevant links.",
445 tools: [469 tools: [
446 {470 {
447 type: :mcp,471 type: :mcp,
448 server_label: "dmcp",472 server_label: "openai_docs",
449 server_description: "A Dungeons and Dragons MCP server to assist with dice rolling.",473 server_description: "Search and read the public OpenAI documentation.",
450 server_url: "https://dmcp-server.deno.dev/mcp",474 server_url: "https://developers.openai.com/mcp",
451 require_approval: :never,475 require_approval: :never,
452 allowed_tools: ["roll"]476 allowed_tools: ["search_openai_docs"]
453 }477 }
454 ]478 ]
455)479)
460 484
461### Step 2: Calling tools485### Step 2: Calling tools
462 486
463Once the model has access to these tool definitions, it may choose to call them depending on what's in the model's context. When the model decides to call an MCP tool, the API will make an request to the remote MCP server to call the tool and put its output into the model's context. This creates an `mcp_call` item which looks like this:487Once the model has access to these tool definitions, it may choose to call them depending on what's in the model's context. When the model decides to call an MCP tool, the API will make a request to the remote MCP server to call the tool and put its output into the model's context. This creates an `mcp_call` item. The following illustrative output omits search-result metadata for brevity:
464 488
465```json489```json
466{490{
467 "id": "mcp_68a6102d8948819c9b1490d36d5ffa4a0679e572a900e618",491 "id": "mcp_68a6102d8948819c9b1490d36d5ffa4a0679e572a900e618",
468 "type": "mcp_call",492 "type": "mcp_call",
469 "approval_request_id": null,493 "approval_request_id": null,
470 "arguments": "{\"diceRollExpression\":\"2d4 + 1\"}",494 "arguments": "{\"query\":\"Responses API streaming\",\"limit\":1}",
471 "error": null,495 "error": null,
472 "name": "roll",496 "name": "search_openai_docs",
473 "output": "4",497 "output": "{\"hits\":[{\"url\":\"https://developers.openai.com/api/docs/guides/streaming-responses\"}]}",
474 "server_label": "dmcp"498 "server_label": "openai_docs"
475}499}
476```500```
477 501
481 505
482#### Approvals506#### Approvals
483 507
484By default, OpenAI will request your approval before any data is shared with a connector or remote MCP server. Approvals help you maintain control and visibility over what data is being sent to an MCP server. We highly recommend that you carefully review (and optionally log) all data being shared with a remote MCP server. A request for an approval to make an MCP tool call creates a `mcp_approval_request` item in the Response's output that looks like this:508By default, OpenAI will request your approval before any data is shared with a connector or remote MCP server. Approvals help you maintain control and visibility over what data is being sent to an MCP server. We highly recommend that you carefully review (and optionally log) all data being shared with a remote MCP server. To try the approval flow, run the quickstart example with `require_approval` set to `"always"` instead of `"never"`. A request for an approval to make an MCP tool call creates a `mcp_approval_request` item in the Response's output. The following example is illustrative:
485 509
486```json510```json
487{511{
488 "id": "mcpr_68a619e1d82c8190b50c1ccba7ad18ef0d2d23a86136d339",512 "id": "mcpr_682d498e3bd4819196a0ce1664f8e77b04ad1e533afccbfa",
489 "type": "mcp_approval_request",513 "type": "mcp_approval_request",
490 "arguments": "{\"diceRollExpression\":\"2d4 + 1\"}",514 "arguments": "{\"query\":\"Responses API streaming\",\"limit\":1}",
491 "name": "roll",515 "name": "search_openai_docs",
492 "server_label": "dmcp"516 "server_label": "openai_docs"
493}517}
494```518```
495 519
496You can then respond to this by creating a new Response object and appending an `mcp_approval_response` item to it.520Review the requested tool and its arguments before approving. You can then respond by creating a new Response object and appending an `mcp_approval_response` item to it. Replace the illustrative response and approval-request IDs in the following examples with the IDs returned by your request. The .NET example obtains these IDs from its initial response. Each approval applies to one tool call; handle any subsequent approval requests in the same way.
497 521
498Approving the use of tools in an API request522Approving the use of tools in an API request
499 523
506 "tools": [530 "tools": [
507 {531 {
508 "type": "mcp",532 "type": "mcp",
509 "server_label": "dmcp",533 "server_label": "openai_docs",
510 "server_description": "A Dungeons and Dragons MCP server to assist with dice rolling.",534 "server_description": "Search and read the public OpenAI documentation.",
511 "server_url": "https://dmcp-server.deno.dev/mcp",535 "server_url": "https://developers.openai.com/mcp",
512 "require_approval": "always",536 "require_approval": "always"
513 }537 }
514 ],538 ],
515 "previous_response_id": "resp_682d498bdefc81918b4a6aa477bfafd904ad1e533afccbfa",539 "previous_response_id": "resp_682d498bdefc81918b4a6aa477bfafd904ad1e533afccbfa",
530 tools: [554 tools: [
531 {555 {
532 type: "mcp",556 type: "mcp",
533 server_label: "dmcp",557 server_label: "openai_docs",
534 server_description:558 server_description: "Search and read the public OpenAI documentation.",
535 "A Dungeons and Dragons MCP server to assist with dice rolling.",559 server_url: "https://developers.openai.com/mcp",
536 server_url: "https://dmcp-server.deno.dev/mcp",
537 require_approval: "always",560 require_approval: "always",
538 },561 },
539 ],562 ],
561 tools=[584 tools=[
562 {585 {
563 "type": "mcp",586 "type": "mcp",
564 "server_label": "dmcp",587 "server_label": "openai_docs",
565 "server_description": "A Dungeons and Dragons MCP server to assist with dice rolling.",588 "server_description": "Search and read the public OpenAI documentation.",
566 "server_url": "https://dmcp-server.deno.dev/mcp",589 "server_url": "https://developers.openai.com/mcp",
567 "require_approval": "always",590 "require_approval": "always",
568 }591 }
569 ],592 ],
593 616
594func main() {617func main() {
595 client := openai.NewClient()618 client := openai.NewClient()
596 tool := responses.ToolParamOfMcp("dmcp")619 tool := responses.ToolParamOfMcp("openai_docs")
597 tool.OfMcp.ServerDescription = openai.String("A Dungeons and Dragons MCP server to assist with dice rolling.")620 tool.OfMcp.ServerDescription = openai.String("Search and read the public OpenAI documentation.")
598 tool.OfMcp.ServerURL = openai.String("https://dmcp-server.deno.dev/mcp")621 tool.OfMcp.ServerURL = openai.String("https://developers.openai.com/mcp")
599 tool.OfMcp.RequireApproval = responses.ToolMcpRequireApprovalUnionParam{OfMcpToolApprovalSetting: openai.String("always")}622 tool.OfMcp.RequireApproval = responses.ToolMcpRequireApprovalUnionParam{OfMcpToolApprovalSetting: openai.String("always")}
600 623
601 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{624 response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{
639 .previousResponseId(responseId)662 .previousResponseId(responseId)
640 .addTool(663 .addTool(
641 Tool.Mcp.builder()664 Tool.Mcp.builder()
642 .serverLabel("dmcp")665 .serverLabel("openai_docs")
643 .serverDescription("A Dungeons and Dragons MCP server.")666 .serverDescription("Search and read the public OpenAI documentation.")
644 .serverUrl("https://dmcp-server.deno.dev/mcp")667 .serverUrl("https://developers.openai.com/mcp")
645 .requireApproval(Tool.Mcp.RequireApproval.McpToolApprovalSetting.ALWAYS)668 .requireApproval(Tool.Mcp.RequireApproval.McpToolApprovalSetting.ALWAYS)
646 .build())669 .build())
647 .build();670 .build();
663CreateResponseOptions options = new() { Model = "gpt-6-astra" };686CreateResponseOptions options = new() { Model = "gpt-6-astra" };
664options.Tools.Add(687options.Tools.Add(
665 ResponseTool.CreateMcpTool(688 ResponseTool.CreateMcpTool(
666 serverLabel: "dmcp",689 serverLabel: "openai_docs",
667 serverUri: new Uri("https://dmcp-server.deno.dev/mcp"),690 serverUri: new Uri("https://developers.openai.com/mcp"),
668 toolCallApprovalPolicy: DefaultMcpToolCallApprovalPolicy.AlwaysRequireApproval691 toolCallApprovalPolicy: DefaultMcpToolCallApprovalPolicy.AlwaysRequireApproval
669 )692 )
670);693);
671 694
672// Step 1: Create a response that requests tool-call approval.695// Step 1: Create a response that requests tool-call approval.
673options.InputItems.Add(ResponseItem.CreateUserMessageItem("Roll 2d4+1"));696options.InputItems.Add(ResponseItem.CreateUserMessageItem("Search the OpenAI docs for Responses API streaming and return the relevant links."));
674ResponseResult response1 = await client.CreateResponseAsync(options);697ResponseResult response1 = await client.CreateResponseAsync(options);
675 698
676McpToolCallApprovalRequestItem approvalRequest =699McpToolCallApprovalRequestItem approvalRequest =
704 tools: [727 tools: [
705 {728 {
706 type: :mcp,729 type: :mcp,
707 server_label: "dmcp",730 server_label: "openai_docs",
708 server_url: "https://dmcp-server.deno.dev/mcp",731 server_url: "https://developers.openai.com/mcp",
709 server_description: "A Dungeons and Dragons MCP server.",732 server_description: "Search and read the public OpenAI documentation.",
710 require_approval: :always733 require_approval: :always
711 }734 }
712 ]735 ]
917 940
918## Authentication941## Authentication
919 942
920Unlike the [example MCP server we used above](https://dash.deno.com/playground/dmcp-server), most other MCP servers require authentication. The most common scheme is an OAuth access token. Provide this token using the `authorization` field of the MCP tool:943The [OpenAI Docs MCP server](https://developers.openai.com/resources/docs-mcp) does not require authentication. Other MCP servers may require authentication. The most common scheme is an OAuth access token. Provide this token using the `authorization` field of the MCP tool:
921 944
922Use Stripe MCP tool945Use Stripe MCP tool
923 946
1851```json1874```json
1852{1875{
1853 "type": "mcp",1876 "type": "mcp",
1854 "server_label": "dmcp",1877 "server_label": "openai_docs",
1855 "server_description": "A Dungeons and Dragons MCP server to assist with dice rolling.",1878 "server_description": "Search and read the public OpenAI documentation.",
1856 "server_url": "https://dmcp-server.deno.dev/mcp",1879 "server_url": "https://developers.openai.com/mcp",
1857// highlight-start:subtle1880// highlight-start:subtle
1858 "defer_loading": true,1881 "defer_loading": true,
1859// highlight-end1882// highlight-end