除了通过函数调用 向模型提供工具外,您还可以使用 远程 MCP 服务器 或 安全 MCP 隧道 为模型扩展能力。这些工具使模型能够在响应用户提示时,根据需要连接和控制外部服务。您可以自动允许这些工具调用,也可以加以限制,要求经过您作为开发者的明确审批。
本指南介绍如何在 Responses API 中使用 MCP 工具。现有模型仍支持内置连接器;有关弃用政策和兼容性示例,请参阅旧版连接器 。有关智能体 API 会话,请参阅 MCP 连接 ,其中介绍了如何从托管服务或您的沙盒建立连接。
如果您的 MCP 服务器是私有服务器、部署在本地,或位于防火墙后方,请使用安全 MCP 隧道 将其连接到受支持的 OpenAI 产品,而无需将服务器暴露在公共互联网上。请从 openai/tunnel-client 下载最新的公开发布版本。
在 Responses API 中使用 mcp 工具类型。对于远程 MCP 服务器,请设置 server_url;对于通过安全 MCP 隧道 连接的本地 MCP 服务器,请使用 tunnel_id。根据服务器的要求,您可能还需要在 authorization 参数中提供 OAuth 访问 Token。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 curl https://api.openai.com/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY " \
-d '{
"model": "gpt-6-astra",
"tools": [
{
"type": "mcp",
"server_label": "dmcp",
"server_description": "A Dungeons and Dragons MCP server to assist with dice rolling.",
"server_url": "https://dmcp-server.deno.dev/mcp",
"require_approval": "never"
}
],
"input": "Roll 2d4+1"
}' 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import OpenAI from "openai";
const client = new OpenAI();
const resp = await client.responses.create({
model: "gpt-6-astra",
tools: [
{
type: "mcp",
server_label: "dmcp",
server_description:
"A Dungeons and Dragons MCP server to assist with dice rolling.",
server_url: "https://dmcp-server.deno.dev/mcp",
require_approval: "never",
},
],
input: "Roll 2d4+1",
});
console.log(resp.output_text); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 from openai import OpenAI
client = OpenAI()
resp = client.responses.create(
model="gpt-6-astra",
tools=[
{
"type": "mcp",
"server_label": "dmcp",
"server_description": "A Dungeons and Dragons MCP server to assist with dice rolling.",
"server_url": "https://dmcp-server.deno.dev/mcp",
"require_approval": "never",
},
],
input="Roll 2d4+1",
)
print(resp.output_text) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package main
import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
"github.com/openai/openai-go/v3/responses"
)
func main() {
client := openai.NewClient()
tool := responses.ToolParamOfMcp("dmcp")
tool.OfMcp.ServerDescription = openai.String("A Dungeons and Dragons MCP server to assist with dice rolling.")
tool.OfMcp.ServerURL = openai.String("https://dmcp-server.deno.dev/mcp")
tool.OfMcp.RequireApproval = responses.ToolMcpRequireApprovalUnionParam{OfMcpToolApprovalSetting: openai.String("never")}
response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{
Model: "gpt-6-astra",
Tools: []responses.ToolUnionParam{tool},
Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Roll 2d4+1")},
})
if err != nil {
panic(err)
}
fmt.Println(response.OutputText())
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.responses.ResponseCreateParams;
import com.openai.models.responses.Tool;
ResponseCreateParams params =
ResponseCreateParams.builder()
.model("gpt-6-astra")
.input("Roll 2d4+1")
.addTool(
Tool.Mcp.builder()
.serverLabel("dmcp")
.serverDescription(
"A Dungeons and Dragons MCP server to assist with dice rolling.")
.serverUrl("https://dmcp-server.deno.dev/mcp")
.requireApproval(Tool.Mcp.RequireApproval.McpToolApprovalSetting.NEVER)
.build())
.build();
client.responses().create(params).output().stream()
.flatMap(item -> item.message().stream())
.flatMap(message -> message.content().stream())
.flatMap(content -> content.outputText().stream())
.forEach(text -> System.out.println(text.text())); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 using OpenAI.Responses;
#pragma warning disable OPENAI001
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
ResponsesClient client = new(key);
CreateResponseOptions options = new() { Model = "gpt-6-astra" };
options.Tools.Add(
ResponseTool.CreateMcpTool(
serverLabel: "dmcp",
serverUri: new Uri("https://dmcp-server.deno.dev/mcp"),
toolCallApprovalPolicy: DefaultMcpToolCallApprovalPolicy.NeverRequireApproval
)
);
options.InputItems.Add(ResponseItem.CreateUserMessageItem("Roll 2d4+1"));
ResponseResult response = await client.CreateResponseAsync(options);
Console.WriteLine(response.GetOutputText()); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 require "openai"
openai = OpenAI::Client.new
response = openai.responses.create(
model: "gpt-6-astra",
tools: [
{
type: "mcp",
server_label: "dmcp",
server_description: "A Dungeons and Dragons MCP server to assist with dice rolling.",
server_url: "https://dmcp-server.deno.dev/mcp",
require_approval: "never"
}
],
input: "Roll 2d4+1"
)
puts(response.output_text)
开发者务必只将可信的远程 MCP 服务器与
Responses API 配合使用。恶意服务器可能从
进入模型上下文的任何内容中窃取敏感数据。使用此工具前,请仔细阅读下文的
风险与安全 部分。
API 会在模型响应的 output 数组中返回新条目。如果模型决定使用 MCP 服务器,它会先发送请求,列出该服务器的可用工具,这会生成一个 mcp_list_tools 输出条目。在上面的远程 MCP 服务器示例中,该条目仅包含一个工具定义:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 {
"id" : "mcpl_68a6102a4968819c8177b05584dd627b0679e572a900e618" ,
"type" : "mcp_list_tools" ,
"server_label" : "dmcp" ,
"tools" : [
{
"annotations" : null ,
"description" : "Given a string of text describing a dice roll..." ,
"input_schema" : {
"$schema" : "https://json-schema.org/draft/2020-12/schema" ,
"type" : "object" ,
"properties" : {
"diceRollExpression" : {
"type" : "string"
}
},
"required" : [ "diceRollExpression" ],
"additionalProperties" : false
},
"name" : "roll"
}
]
}
如果模型决定调用 MCP 服务器提供的某个可用工具,您还会看到一个 mcp_call 输出,其中会显示模型发送给 MCP 工具的内容,以及 MCP 工具返回的输出。
1 2 3 4 5 6 7 8 9 10 {
"id" : "mcp_68a6102d8948819c9b1490d36d5ffa4a0679e572a900e618" ,
"type" : "mcp_call" ,
"approval_request_id" : null ,
"arguments" : "{ \" diceRollExpression \" : \" 2d4 + 1 \" }" ,
"error" : null ,
"name" : "roll" ,
"output" : "4" ,
"server_label" : "dmcp"
}
继续阅读下方指南,进一步了解 MCP 工具的工作原理、如何筛选可用工具,以及如何处理工具调用审批请求。
大多数近期推出的模型都可在 Responses API 中使用 MCP 工具。您可以在此处 查看您的模型是否兼容 MCP 工具。使用 MCP 工具时,您只需为导入工具定义或进行工具调用时使用的 Token 付费。每次工具调用不收取额外费用。
下面,我们将逐步介绍 API 调用 MCP 工具的流程。
当您在 tools 参数中指定远程 MCP 服务器时,API 会尝试从该服务器获取工具列表。Responses API 可与支持 Streamable HTTP 或 HTTP/SSE 传输协议的远程 MCP 服务器配合使用。
如果成功获取工具列表,模型响应的输出中就会出现一个新的 mcp_list_tools 输出条目。该对象的 tools 属性会显示成功导入的工具。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 {
"id" : "mcpl_68a6102a4968819c8177b05584dd627b0679e572a900e618" ,
"type" : "mcp_list_tools" ,
"server_label" : "dmcp" ,
"tools" : [
{
"annotations" : null ,
"description" : "Given a string of text describing a dice roll..." ,
"input_schema" : {
"$schema" : "https://json-schema.org/draft/2020-12/schema" ,
"type" : "object" ,
"properties" : {
"diceRollExpression" : {
"type" : "string"
}
},
"required" : [ "diceRollExpression" ],
"additionalProperties" : false
},
"name" : "roll"
}
]
}
只要 API 请求的上下文中包含 mcp_list_tools 条目,
API 就不会在
对话 的每一轮都重新从 MCP 服务器获取工具列表。
我们建议您在每次对话或工作流程执行期间,
都将此条目保留在模型上下文中,以降低延迟。
某些 MCP 服务器可能提供数十个工具,向模型开放大量工具可能导致成本和延迟升高。如果您只需要 MCP 服务器提供的部分工具,可以使用 allowed_tools 参数,仅导入这些工具。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 curl https://api.openai.com/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY " \
-d '{
"model": "gpt-6-astra",
"tools": [
{
"type": "mcp",
"server_label": "dmcp",
"server_description": "A Dungeons and Dragons MCP server to assist with dice rolling.",
"server_url": "https://dmcp-server.deno.dev/mcp",
"require_approval": "never",
"allowed_tools": ["roll"]
}
],
"input": "Roll 2d4+1"
}' 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import OpenAI from "openai";
const client = new OpenAI();
const resp = await client.responses.create({
model: "gpt-6-astra",
tools: [
{
type: "mcp",
server_label: "dmcp",
server_description:
"A Dungeons and Dragons MCP server to assist with dice rolling.",
server_url: "https://dmcp-server.deno.dev/mcp",
require_approval: "never",
allowed_tools: ["roll"],
},
],
input: "Roll 2d4+1",
});
console.log(resp.output_text); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 from openai import OpenAI
client = OpenAI()
resp = client.responses.create(
model="gpt-6-astra",
tools=[
{
"type": "mcp",
"server_label": "dmcp",
"server_description": "A Dungeons and Dragons MCP server to assist with dice rolling.",
"server_url": "https://dmcp-server.deno.dev/mcp",
"require_approval": "never",
"allowed_tools": ["roll"],
}
],
input="Roll 2d4+1",
)
print(resp.output_text) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package main
import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
"github.com/openai/openai-go/v3/responses"
)
func main() {
client := openai.NewClient()
tool := responses.ToolParamOfMcp("dmcp")
tool.OfMcp.ServerDescription = openai.String("A Dungeons and Dragons MCP server to assist with dice rolling.")
tool.OfMcp.ServerURL = openai.String("https://dmcp-server.deno.dev/mcp")
tool.OfMcp.RequireApproval = responses.ToolMcpRequireApprovalUnionParam{OfMcpToolApprovalSetting: openai.String("never")}
tool.OfMcp.AllowedTools = responses.ToolMcpAllowedToolsUnionParam{OfMcpAllowedTools: []string{"roll"}}
response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{
Model: "gpt-6-astra",
Tools: []responses.ToolUnionParam{tool},
Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Roll 2d4+1")},
})
if err != nil {
panic(err)
}
fmt.Println(response.OutputText())
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.responses.ResponseCreateParams;
import com.openai.models.responses.Tool;
import java.util.List;
ResponseCreateParams params =
ResponseCreateParams.builder()
.model("gpt-6-astra")
.input("Roll 2d4+1")
.addTool(
Tool.Mcp.builder()
.serverLabel("dmcp")
.serverDescription(
"A Dungeons and Dragons MCP server to assist with dice rolling.")
.serverUrl("https://dmcp-server.deno.dev/mcp")
.requireApproval(Tool.Mcp.RequireApproval.McpToolApprovalSetting.NEVER)
.allowedToolsOfMcp(List.of("roll"))
.build())
.build();
client.responses().create(params).output().stream()
.flatMap(item -> item.message().stream())
.flatMap(message -> message.content().stream())
.flatMap(content -> content.outputText().stream())
.forEach(text -> System.out.println(text.text())); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 using OpenAI.Responses;
#pragma warning disable OPENAI001
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
ResponsesClient client = new(key);
CreateResponseOptions options = new() { Model = "gpt-6-astra" };
options.Tools.Add(
ResponseTool.CreateMcpTool(
serverLabel: "dmcp",
serverUri: new Uri("https://dmcp-server.deno.dev/mcp"),
allowedTools: new McpToolFilter() { ToolNames = { "roll" } },
toolCallApprovalPolicy: DefaultMcpToolCallApprovalPolicy.NeverRequireApproval
)
);
options.InputItems.Add(ResponseItem.CreateUserMessageItem("Roll 2d4+1"));
ResponseResult response = await client.CreateResponseAsync(options);
Console.WriteLine(response.GetOutputText()); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 require "openai"
client = OpenAI::Client.new
response = client.responses.create(
model: "gpt-6-astra",
input: "Roll 2d4+1",
tools: [
{
type: :mcp,
server_label: "dmcp",
server_description: "A Dungeons and Dragons MCP server to assist with dice rolling.",
server_url: "https://dmcp-server.deno.dev/mcp",
require_approval: :never,
allowed_tools: ["roll"]
}
]
)
puts(response.output_text)
模型获得这些工具定义后,可能会根据上下文中的内容选择调用工具。当模型决定调用 MCP 工具时,API 会向远程 MCP 服务器发送请求以调用该工具,并将其输出放入模型上下文中。这会创建一个如下所示的 mcp_call 条目:
1 2 3 4 5 6 7 8 9 10 {
"id" : "mcp_68a6102d8948819c9b1490d36d5ffa4a0679e572a900e618" ,
"type" : "mcp_call" ,
"approval_request_id" : null ,
"arguments" : "{ \" diceRollExpression \" : \" 2d4 + 1 \" }" ,
"error" : null ,
"name" : "roll" ,
"output" : "4" ,
"server_label" : "dmcp"
}
此条目同时包含模型为此次工具调用选择的参数,以及远程 MCP 服务器返回的 output。所有模型都可以选择进行多次 MCP 工具调用,因此您可能会看到单个 API 请求生成多个此类条目。
工具调用失败时,此条目的 error 字段会填入 MCP 协议错误、MCP 工具执行错误或一般连接错误。有关 MCP 错误的说明,请参阅此处 的 MCP 规范。
默认情况下,OpenAI 会在向连接器或远程 MCP 服务器共享任何数据之前请求您的审批。审批让您能够了解并控制发送到 MCP 服务器的数据。我们强烈建议您仔细审查与远程 MCP 服务器共享的所有数据,并可选择将其记录到日志中。请求审批 MCP 工具调用时,Response 的输出中会创建一个如下所示的 mcp_approval_request 条目:
1 2 3 4 5 6 7 {
"id" : "mcpr_68a619e1d82c8190b50c1ccba7ad18ef0d2d23a86136d339" ,
"type" : "mcp_approval_request" ,
"arguments" : "{ \" diceRollExpression \" : \" 2d4 + 1 \" }" ,
"name" : "roll" ,
"server_label" : "dmcp"
}
随后,您可以创建一个新的 Response 对象,并向其中追加一个 mcp_approval_response 条目,以回应此审批请求。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 curl https://api.openai.com/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY " \
-d '{
"model": "gpt-6-astra",
"tools": [
{
"type": "mcp",
"server_label": "dmcp",
"server_description": "A Dungeons and Dragons MCP server to assist with dice rolling.",
"server_url": "https://dmcp-server.deno.dev/mcp",
"require_approval": "always",
}
],
"previous_response_id": "resp_682d498bdefc81918b4a6aa477bfafd904ad1e533afccbfa",
"input": [{
"type": "mcp_approval_response",
"approve": true,
"approval_request_id": "mcpr_682d498e3bd4819196a0ce1664f8e77b04ad1e533afccbfa"
}]
}' 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 import OpenAI from "openai";
const client = new OpenAI();
const resp = await client.responses.create({
model: "gpt-6-astra",
tools: [
{
type: "mcp",
server_label: "dmcp",
server_description:
"A Dungeons and Dragons MCP server to assist with dice rolling.",
server_url: "https://dmcp-server.deno.dev/mcp",
require_approval: "always",
},
],
previous_response_id: "resp_682d498bdefc81918b4a6aa477bfafd904ad1e533afccbfa",
input: [
{
type: "mcp_approval_response",
approve: true,
approval_request_id:
"mcpr_682d498e3bd4819196a0ce1664f8e77b04ad1e533afccbfa",
},
],
});
console.log(resp.output_text); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 from openai import OpenAI
client = OpenAI()
resp = client.responses.create(
model="gpt-6-astra",
tools=[
{
"type": "mcp",
"server_label": "dmcp",
"server_description": "A Dungeons and Dragons MCP server to assist with dice rolling.",
"server_url": "https://dmcp-server.deno.dev/mcp",
"require_approval": "always",
}
],
previous_response_id="resp_682d498bdefc81918b4a6aa477bfafd904ad1e533afccbfa",
input=[
{
"type": "mcp_approval_response",
"approve": True,
"approval_request_id": "mcpr_682d498e3bd4819196a0ce1664f8e77b04ad1e533afccbfa",
}
],
)
print(resp.output_text) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 package main
import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
"github.com/openai/openai-go/v3/responses"
)
func main() {
client := openai.NewClient()
tool := responses.ToolParamOfMcp("dmcp")
tool.OfMcp.ServerDescription = openai.String("A Dungeons and Dragons MCP server to assist with dice rolling.")
tool.OfMcp.ServerURL = openai.String("https://dmcp-server.deno.dev/mcp")
tool.OfMcp.RequireApproval = responses.ToolMcpRequireApprovalUnionParam{OfMcpToolApprovalSetting: openai.String("always")}
response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{
Model: "gpt-6-astra",
PreviousResponseID: openai.String("resp_682d498bdefc81918b4a6aa477bfafd904ad1e533afccbfa"),
Tools: []responses.ToolUnionParam{tool},
Input: responses.ResponseNewParamsInputUnion{OfInputItemList: responses.ResponseInputParam{
responses.ResponseInputItemParamOfMcpApprovalResponse("mcpr_682d498e3bd4819196a0ce1664f8e77b04ad1e533afccbfa", true),
}},
})
if err != nil {
panic(err)
}
fmt.Println(response.OutputText())
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.responses.ResponseCreateParams;
import com.openai.models.responses.ResponseInputItem;
import com.openai.models.responses.Tool;
import java.util.List;
String responseId = "resp_682d498bdefc81918b4a6aa477bfafd904ad1e533afccbfa";
String approvalRequestId = "mcpr_682d498e3bd4819196a0ce1664f8e77b04ad1e533afccbfa";
ResponseCreateParams params =
ResponseCreateParams.builder()
.model("gpt-6-astra")
.input(
ResponseCreateParams.Input.ofResponse(
List.of(
ResponseInputItem.ofMcpApprovalResponse(
ResponseInputItem.McpApprovalResponse.builder()
.approvalRequestId(approvalRequestId)
.approve(true)
.build()))))
.previousResponseId(responseId)
.addTool(
Tool.Mcp.builder()
.serverLabel("dmcp")
.serverDescription("A Dungeons and Dragons MCP server.")
.serverUrl("https://dmcp-server.deno.dev/mcp")
.requireApproval(Tool.Mcp.RequireApproval.McpToolApprovalSetting.ALWAYS)
.build())
.build();
client.responses().create(params).output().stream()
.flatMap(item -> item.message().stream())
.flatMap(message -> message.content().stream())
.flatMap(content -> content.outputText().stream())
.forEach(text -> System.out.println(text.text())); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 using OpenAI.Responses;
#pragma warning disable OPENAI001
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
ResponsesClient client = new(key);
CreateResponseOptions options = new() { Model = "gpt-6-astra" };
options.Tools.Add(
ResponseTool.CreateMcpTool(
serverLabel: "dmcp",
serverUri: new Uri("https://dmcp-server.deno.dev/mcp"),
toolCallApprovalPolicy: DefaultMcpToolCallApprovalPolicy.AlwaysRequireApproval
)
);
// Step 1: Create a response that requests tool-call approval.
options.InputItems.Add(ResponseItem.CreateUserMessageItem("Roll 2d4+1"));
ResponseResult response1 = await client.CreateResponseAsync(options);
McpToolCallApprovalRequestItem approvalRequest =
response1.OutputItems.OfType<McpToolCallApprovalRequestItem>().Single();
// Step 2: Approve the tool call and get the final response.
options.PreviousResponseId = response1.Id;
options.InputItems.Clear();
options.InputItems.Add(
ResponseItem.CreateMcpApprovalResponseItem(approvalRequest.Id, approved: true)
);
ResponseResult response2 = await client.CreateResponseAsync(options);
Console.WriteLine(response2.GetOutputText()); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 require "openai"
client = OpenAI::Client.new
response = client.responses.create(
model: "gpt-6-astra",
previous_response_id: "resp_682d498bdefc81918b4a6aa477bfafd904ad1e533afccbfa",
input: [
{
type: :mcp_approval_response,
approval_request_id: "mcpr_682d498e3bd4819196a0ce1664f8e77b04ad1e533afccbfa",
approve: true
}
],
tools: [
{
type: :mcp,
server_label: "dmcp",
server_url: "https://dmcp-server.deno.dev/mcp",
server_description: "A Dungeons and Dragons MCP server.",
require_approval: :always
}
]
)
puts(response.output_text)
这里,我们使用 previous_response_id 参数,将这个新响应与之前生成审批请求的响应串联起来。您也可以将一个响应的输出作为另一个响应的输入 传回,从而最大限度地控制哪些内容进入模型的上下文。
当您确信某个远程 MCP 服务器值得信任时,可以选择跳过审批以降低延迟。为此,您可以像下方示例一样,将 MCP 工具的 require_approval 参数设为一个对象,其中仅列出您希望跳过审批的工具;也可以将其设为 'never',以跳过该远程 MCP 服务器中所有工具的审批。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 curl https://api.openai.com/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY " \
-d '{
"model": "gpt-6-astra",
"tools": [
{
"type": "mcp",
"server_label": "deepwiki",
"server_url": "https://mcp.deepwiki.com/mcp",
"require_approval": {
"never": {
"tool_names": ["ask_question", "read_wiki_structure"]
}
}
}
],
"input": "What transport protocols does the 2025-03-26 version of the MCP spec (modelcontextprotocol/modelcontextprotocol) support?"
}' 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import OpenAI from "openai";
const client = new OpenAI();
const resp = await client.responses.create({
model: "gpt-6-astra",
tools: [
{
type: "mcp",
server_label: "deepwiki",
server_url: "https://mcp.deepwiki.com/mcp",
require_approval: {
never: {
tool_names: ["ask_question", "read_wiki_structure"],
},
},
},
],
input:
"What transport protocols does the 2025-03-26 version of the MCP spec (modelcontextprotocol/modelcontextprotocol) support?",
});
console.log(resp.output_text); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 from openai import OpenAI
client = OpenAI()
resp = client.responses.create(
model="gpt-6-astra",
tools=[
{
"type": "mcp",
"server_label": "deepwiki",
"server_url": "https://mcp.deepwiki.com/mcp",
"require_approval": {
"never": {"tool_names": ["ask_question", "read_wiki_structure"]}
},
},
],
input="What transport protocols does the 2025-03-26 version of the MCP spec (modelcontextprotocol/modelcontextprotocol) support?",
)
print(resp.output_text) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 package main
import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
"github.com/openai/openai-go/v3/responses"
)
func main() {
client := openai.NewClient()
tool := responses.ToolParamOfMcp("deepwiki")
tool.OfMcp.ServerURL = openai.String("https://mcp.deepwiki.com/mcp")
tool.OfMcp.RequireApproval = responses.ToolMcpRequireApprovalUnionParam{
OfMcpToolApprovalFilter: &responses.ToolMcpRequireApprovalMcpToolApprovalFilterParam{
Never: responses.ToolMcpRequireApprovalMcpToolApprovalFilterNeverParam{
ToolNames: []string{"ask_question", "read_wiki_structure"},
},
},
}
response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{
Model: "gpt-6-astra",
Tools: []responses.ToolUnionParam{tool},
Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("What transport protocols does the 2025-03-26 version of the MCP spec (modelcontextprotocol/modelcontextprotocol) support?")},
})
if err != nil {
panic(err)
}
fmt.Println(response.OutputText())
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.responses.ResponseCreateParams;
import com.openai.models.responses.Tool;
ResponseCreateParams params =
ResponseCreateParams.builder()
.model("gpt-6-astra")
.input("What transport protocols does the 2025-03-26 version of the MCP spec support?")
.addTool(
Tool.Mcp.builder()
.serverLabel("deepwiki")
.serverUrl("https://mcp.deepwiki.com/mcp")
.requireApproval(
Tool.Mcp.RequireApproval.McpToolApprovalFilter.builder()
.never(
Tool.Mcp.RequireApproval.McpToolApprovalFilter.Never.builder()
.addToolName("ask_question")
.addToolName("read_wiki_structure")
.build())
.build())
.build())
.build();
client.responses().create(params).output().stream()
.flatMap(item -> item.message().stream())
.flatMap(message -> message.content().stream())
.flatMap(content -> content.outputText().stream())
.forEach(text -> System.out.println(text.text())); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 using OpenAI.Responses;
#pragma warning disable OPENAI001
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
ResponsesClient client = new(key);
CreateResponseOptions options = new() { Model = "gpt-6-astra" };
options.Tools.Add(
ResponseTool.CreateMcpTool(
serverLabel: "deepwiki",
serverUri: new Uri("https://mcp.deepwiki.com/mcp"),
toolCallApprovalPolicy: new CustomMcpToolCallApprovalPolicy
{
ToolsNeverRequiringApproval = new McpToolFilter
{
ToolNames = { "ask_question", "read_wiki_structure" },
},
}
)
);
options.InputItems.Add(
ResponseItem.CreateUserMessageItem(
"What transport protocols does the 2025-03-26 version of the MCP spec (modelcontextprotocol/modelcontextprotocol) support?"
)
);
ResponseResult response = await client.CreateResponseAsync(options);
Console.WriteLine(response.GetOutputText()); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 require "openai"
client = OpenAI::Client.new
response = client.responses.create(
model: "gpt-6-astra",
input: "What transport protocols does the 2025-03-26 version of the MCP spec support?",
tools: [
{
type: :mcp,
server_label: "deepwiki",
server_url: "https://mcp.deepwiki.com/mcp",
require_approval: {
never: { tool_names: ["ask_question", "read_wiki_structure"] }
}
}
]
)
puts(response.output_text)
与上面使用的示例 MCP 服务器 不同,大多数其他 MCP 服务器都需要身份验证。最常见的方式是使用 OAuth 访问 Token。请通过 MCP 工具的 authorization 字段提供此 Token:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 curl https://api.openai.com/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY " \
-d '{
"model": "gpt-6-astra",
"input": "Create a payment link for $20",
"tools": [
{
"type": "mcp",
"server_label": "stripe",
"server_url": "https://mcp.stripe.com",
"authorization": "$STRIPE_OAUTH_ACCESS_TOKEN"
}
]
}' 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import OpenAI from "openai";
const client = new OpenAI();
const resp = await client.responses.create({
model: "gpt-6-astra",
input: "Create a payment link for $20",
tools: [
{
type: "mcp",
server_label: "stripe",
server_url: "https://mcp.stripe.com",
authorization: "$STRIPE_OAUTH_ACCESS_TOKEN",
},
],
});
console.log(resp.output_text); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import os
from openai import OpenAI
client = OpenAI()
authorization = os.environ["STRIPE_OAUTH_ACCESS_TOKEN"]
resp = client.responses.create(
model="gpt-6-astra",
input="Create a payment link for $20",
tools=[
{
"type": "mcp",
"server_label": "stripe",
"server_url": "https://mcp.stripe.com",
"authorization": authorization,
}
],
)
print(resp.output_text) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 package main
import (
"context"
"fmt"
"os"
"github.com/openai/openai-go/v3"
"github.com/openai/openai-go/v3/responses"
)
func main() {
authorization := os.Getenv("STRIPE_OAUTH_ACCESS_TOKEN")
if authorization == "" {
panic("STRIPE_OAUTH_ACCESS_TOKEN is required")
}
client := openai.NewClient()
tool := responses.ToolParamOfMcp("stripe")
tool.OfMcp.ServerURL = openai.String("https://mcp.stripe.com")
tool.OfMcp.Authorization = openai.String(authorization)
response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{
Model: "gpt-6-astra",
Tools: []responses.ToolUnionParam{tool},
Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Create a payment link for $20")},
})
if err != nil {
panic(err)
}
fmt.Println(response.OutputText())
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.responses.ResponseCreateParams;
import com.openai.models.responses.Tool;
String stripeAccessToken = System.getenv("STRIPE_OAUTH_ACCESS_TOKEN");
ResponseCreateParams params =
ResponseCreateParams.builder()
.model("gpt-6-astra")
.input("Create a payment link for $20.")
.addTool(
Tool.Mcp.builder()
.serverLabel("stripe")
.serverUrl("https://mcp.stripe.com")
.authorization(stripeAccessToken)
.build())
.build();
client.responses().create(params).output().stream()
.flatMap(item -> item.message().stream())
.flatMap(message -> message.content().stream())
.flatMap(content -> content.outputText().stream())
.forEach(text -> System.out.println(text.text())); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 using OpenAI.Responses;
#pragma warning disable OPENAI001
string authToken =
Environment.GetEnvironmentVariable("STRIPE_OAUTH_ACCESS_TOKEN")!;
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
ResponsesClient client = new(key);
CreateResponseOptions options = new() { Model = "gpt-6-astra" };
options.Tools.Add(
ResponseTool.CreateMcpTool(
serverLabel: "stripe",
serverUri: new Uri("https://mcp.stripe.com"),
authorizationToken: authToken
)
);
options.InputItems.Add(
ResponseItem.CreateUserMessageItem("Create a payment link for $20")
);
ResponseResult response = await client.CreateResponseAsync(options);
Console.WriteLine(response.GetOutputText()); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 require "openai"
client = OpenAI::Client.new
response = client.responses.create(
model: "gpt-6-astra",
input: "Create a payment link for $20.",
tools: [
{
type: :mcp,
server_label: "stripe",
server_url: "https://mcp.stripe.com",
authorization: ENV.fetch("STRIPE_OAUTH_ACCESS_TOKEN")
}
]
)
puts(response.output_text)
为防止敏感 Token 泄露,Responses API 不会存储您在 authorization 字段中提供的值。创建的 Response 对象中也不会显示此值。因此,您必须在每次 Responses API 创建请求中发送 authorization 的值。
connector_id 已在 2026 年 9 月 1 日之后发布的模型中弃用。
使用 server_url 连接远程 MCP 服务器,或使用
tunnel_id 通过
安全 MCP 隧道 连接本地 MCP 服务器。
现有模型仍支持连接器。本节示例使用
gpt-5.2,该模型在上述截止日期之前发布。
Responses API 内置支持一组数量有限的第三方服务连接器。这些连接器可让您从 Dropbox、Gmail 等常用应用中获取上下文,使模型能够与常用服务交互。
连接器的使用方式与远程 MCP 服务器相同。两者都能让 OpenAI 模型在 API 请求中访问更多第三方工具。不过,使用连接器时,您传入的是用于唯一标识 API 中某个可用连接器的 connector_id,而不是调用远程 MCP 服务器时使用的 server_url。
连接器要求您的应用在 authorization 参数中提供 OAuth 访问 Token。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 curl https://api.openai.com/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY " \
-d '{
"model": "gpt-5.2",
"tools": [
{
"type": "mcp",
"server_label": "Dropbox",
"connector_id": "connector_dropbox",
"authorization": "<oauth access token>",
"require_approval": "never"
}
],
"input": "Summarize the Q2 earnings report."
}' 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 import OpenAI from "openai";
const client = new OpenAI();
const resp = await client.responses.create({
model: "gpt-5.2",
tools: [
{
type: "mcp",
server_label: "Dropbox",
connector_id: "connector_dropbox",
authorization: "<oauth access token>",
require_approval: "never",
},
],
input: "Summarize the Q2 earnings report.",
});
console.log(resp.output_text); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import os
from openai import OpenAI
client = OpenAI()
connector_authorization = os.environ["OPENAI_CONNECTOR_AUTHORIZATION"]
resp = client.responses.create(
model="gpt-5.2",
tools=[
{
"type": "mcp",
"server_label": "Dropbox",
"connector_id": "connector_dropbox",
"authorization": connector_authorization,
"require_approval": "never",
},
],
input="Summarize the Q2 earnings report.",
)
print(resp.output_text) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package main
import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
"github.com/openai/openai-go/v3/responses"
)
func main() {
client := openai.NewClient()
tool := responses.ToolParamOfMcp("Dropbox")
tool.OfMcp.ConnectorID = "connector_dropbox"
tool.OfMcp.Authorization = openai.String("<oauth access token>")
tool.OfMcp.RequireApproval = responses.ToolMcpRequireApprovalUnionParam{OfMcpToolApprovalSetting: openai.String("never")}
response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{
Model: "gpt-5.2",
Tools: []responses.ToolUnionParam{tool},
Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Summarize the Q2 earnings report.")},
})
if err != nil {
panic(err)
}
fmt.Println(response.OutputText())
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.responses.ResponseCreateParams;
import com.openai.models.responses.Tool;
String oauthAccessToken = "<oauth access token>";
ResponseCreateParams params =
ResponseCreateParams.builder()
.model("gpt-5.2")
.input("Summarize the Q2 earnings report.")
.addTool(
Tool.Mcp.builder()
.serverLabel("Dropbox")
.connectorId(Tool.Mcp.ConnectorId.of("connector_dropbox"))
.authorization(oauthAccessToken)
.requireApproval(Tool.Mcp.RequireApproval.McpToolApprovalSetting.NEVER)
.build())
.build();
client.responses().create(params).output().stream()
.flatMap(item -> item.message().stream())
.flatMap(message -> message.content().stream())
.flatMap(content -> content.outputText().stream())
.forEach(text -> System.out.println(text.text())); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 using OpenAI.Responses;
#pragma warning disable OPENAI001
string dropboxToken =
Environment.GetEnvironmentVariable("DROPBOX_OAUTH_ACCESS_TOKEN")!;
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
ResponsesClient client = new(key);
CreateResponseOptions options = new() { Model = "gpt-5.2" };
options.Tools.Add(
ResponseTool.CreateMcpTool(
serverLabel: "Dropbox",
connectorId: McpToolConnectorId.Dropbox,
authorizationToken: dropboxToken,
toolCallApprovalPolicy: DefaultMcpToolCallApprovalPolicy.NeverRequireApproval
)
);
options.InputItems.Add(
ResponseItem.CreateUserMessageItem("Summarize the Q2 earnings report.")
);
ResponseResult response = await client.CreateResponseAsync(options);
Console.WriteLine(response.GetOutputText()); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 require "openai"
client = OpenAI::Client.new
response = client.responses.create(
model: "gpt-5.2",
input: "Summarize the Q2 earnings report.",
tools: [
{
type: :mcp,
server_label: "Dropbox",
connector_id: "connector_dropbox",
authorization: "<oauth access token>",
require_approval: :never
}
]
)
puts(response.output_text)
Dropbox:connector_dropbox
Gmail:connector_gmail
Google Calendar:connector_googlecalendar
Google Drive:connector_googledrive
Microsoft Teams:connector_microsoftteams
Outlook Calendar:connector_outlookcalendar
Outlook Email:connector_outlookemail
SharePoint:connector_sharepoint
我们优先支持尚未提供官方远程 MCP 服务器的服务。例如,GitHub 已提供官方 MCP 服务器,您可以在 MCP 工具的 server_url 字段中传入 https://api.githubcopilot.com/mcp/ 来连接该服务器。
在 authorization 字段中传入 OAuth 访问令牌。OAuth 客户端注册和授权必须由您的应用单独处理。
测试时,您可以使用 Google 的 OAuth 2.0 Playground 生成临时访问令牌,并在 API 请求中使用这些令牌。
要使用 Playground 测试连接器的 API 功能,请先输入:
https://www.googleapis.com/auth/calendar.events
此授权范围允许 API 读取 Google Calendar 活动。请在界面的“步骤 1:选择 API 并授权”下输入。
使用您的 Google 账户为应用授权后,您将进入 步骤 2:用授权码换取 Token 。这一步会生成一个访问 Token,您可以在使用 Google Calendar 连接器的 API 请求中使用它:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 curl https://api.openai.com/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY " \
-d '{
"model": "gpt-5.2",
"tools": [
{
"type": "mcp",
"server_label": "google_calendar",
"connector_id": "connector_googlecalendar",
"authorization": "ya29.A0AS3H6...",
"require_approval": "never"
}
],
"input": "What is on my Google Calendar for today?"
}' 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 import OpenAI from "openai";
const client = new OpenAI();
const resp = await client.responses.create({
model: "gpt-5.2",
tools: [
{
type: "mcp",
server_label: "google_calendar",
connector_id: "connector_googlecalendar",
authorization: "ya29.A0AS3H6...",
require_approval: "never",
},
],
input: "What's on my Google Calendar for today?",
});
console.log(resp.output_text); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import os
from openai import OpenAI
client = OpenAI()
authorization = os.environ["GOOGLE_CALENDAR_OAUTH_ACCESS_TOKEN"]
resp = client.responses.create(
model="gpt-5.2",
tools=[
{
"type": "mcp",
"server_label": "google_calendar",
"connector_id": "connector_googlecalendar",
"authorization": authorization,
"require_approval": "never",
},
],
input="What's on my Google Calendar for today?",
)
print(resp.output_text) 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package main
import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
"github.com/openai/openai-go/v3/responses"
)
func main() {
client := openai.NewClient()
tool := responses.ToolParamOfMcp("google_calendar")
tool.OfMcp.ConnectorID = "connector_googlecalendar"
tool.OfMcp.Authorization = openai.String("<oauth access token>")
tool.OfMcp.RequireApproval = responses.ToolMcpRequireApprovalUnionParam{OfMcpToolApprovalSetting: openai.String("never")}
response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{
Model: "gpt-5.2",
Tools: []responses.ToolUnionParam{tool},
Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("What's on my Google Calendar for today?")},
})
if err != nil {
panic(err)
}
fmt.Println(response.OutputText())
} 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.responses.ResponseCreateParams;
import com.openai.models.responses.Tool;
String oauthAccessToken = "<oauth access token>";
ResponseCreateParams params =
ResponseCreateParams.builder()
.model("gpt-5.2")
.input("What's on my Google Calendar for today?")
.addTool(
Tool.Mcp.builder()
.serverLabel("google_calendar")
.connectorId(Tool.Mcp.ConnectorId.of("connector_googlecalendar"))
.authorization(oauthAccessToken)
.requireApproval(Tool.Mcp.RequireApproval.McpToolApprovalSetting.NEVER)
.build())
.build();
client.responses().create(params).output().stream()
.flatMap(item -> item.message().stream())
.flatMap(message -> message.content().stream())
.flatMap(content -> content.outputText().stream())
.forEach(text -> System.out.println(text.text())); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 using OpenAI.Responses;
#pragma warning disable OPENAI001
string authToken =
Environment.GetEnvironmentVariable("GOOGLE_CALENDAR_OAUTH_ACCESS_TOKEN")!;
string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
ResponsesClient client = new(key);
CreateResponseOptions options = new() { Model = "gpt-5.2" };
options.Tools.Add(
ResponseTool.CreateMcpTool(
serverLabel: "google_calendar",
connectorId: McpToolConnectorId.GoogleCalendar,
authorizationToken: authToken,
toolCallApprovalPolicy: DefaultMcpToolCallApprovalPolicy.NeverRequireApproval
)
);
options.InputItems.Add(
ResponseItem.CreateUserMessageItem("What's on my Google Calendar for today?")
);
ResponseResult response = await client.CreateResponseAsync(options);
Console.WriteLine(response.GetOutputText()); 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 require "openai"
client = OpenAI::Client.new
response = client.responses.create(
model: "gpt-5.2",
input: "What's on my Google Calendar for today?",
tools: [
{
type: :mcp,
server_label: "google_calendar",
connector_id: "connector_googlecalendar",
authorization: "<oauth access token>",
require_approval: :never
}
]
)
puts(response.output_text)
连接器的 MCP 工具调用与远程 MCP 服务器的 MCP 工具调用格式相同,都使用 mcp_call 输出项类型。在本例中,传给连接器的参数和连接器返回的响应都是 JSON 字符串:
1 2 3 4 5 6 7 8 9 10 {
"id" : "mcp_68a62ae1c93c81a2b98c29340aa3ed8800e9b63986850588" ,
"type" : "mcp_call" ,
"approval_request_id" : null ,
"arguments" : "{ \" time_min \" : \" 2025-08-20T00:00:00 \" , \" time_max \" : \" 2025-08-21T00:00:00 \" , \" timezone_str \" :null, \" max_results \" :50, \" query \" :null, \" calendar_id \" :null, \" next_page_token \" :null}" ,
"error" : null ,
"name" : "search_events" ,
"output" : "{ \" events \" : [{ \" id \" : \" 2n8ni54ani58pc3ii6soelupcs_20250820 \" , \" summary \" : \" Home \" , \" location \" : null, \" start \" : \" 2025-08-20T00:00:00 \" , \" end \" : \" 2025-08-21T00:00:00 \" , \" url \" : \" https://www.google.com/calendar/event?eid=Mm44bmk1NGFuaTU4cGMzaWk2c29lbHVwY3NfMjAyNTA4MjAga3doaW5uZXJ5QG9wZW5haS5jb20&ctz=America/Los_Angeles \" , \" description \" : \"\\ n \\ n \" , \" transparency \" : \" transparent \" , \" display_url \" : \" https://www.google.com/calendar/event?eid=Mm44bmk1NGFuaTU4cGMzaWk2c29lbHVwY3NfMjAyNTA4MjAga3doaW5uZXJ5QG9wZW5haS5jb20&ctz=America/Los_Angeles \" , \" display_title \" : \" Home \" }], \" next_page_token \" : null}" ,
"server_label" : "Google_Calendar"
}
可用工具取决于您的 OAuth 令牌具有哪些授权范围。展开下方表格,查看连接到各个应用时可以使用的工具。
Dropbox 工具
说明
权限范围 search
在 Dropbox 中搜索与查询条件匹配的文件
files.metadata.read, account_info.read fetch
按路径获取文件,可选择下载原始文件
files.content.read search_files
搜索 Dropbox 文件并返回结果
files.metadata.read, account_info.read fetch_file
获取文件的文本或原始内容
files.content.read, account_info.read list_recent_files
返回用户可访问的最近修改的文件
files.metadata.read, account_info.read get_profile
获取当前用户的 Dropbox 个人资料
account_info.read
Gmail 工具
说明
权限范围 get_profile
返回当前 Gmail 用户的个人资料
userinfo.email, userinfo.profile search_emails
在 Gmail 中搜索与查询条件或标签匹配的邮件
gmail.modify search_email_ids
获取与搜索条件匹配的 Gmail 邮件 ID
gmail.modify get_recent_emails
返回最近收到的 Gmail 邮件
gmail.modify read_email
获取一封 Gmail 邮件,包含其正文
gmail.modify batch_read_email
在一次调用中读取多封 Gmail 邮件
gmail.modify
Google Calendar 工具
说明
权限范围 get_profile
返回当前 Calendar 用户的个人资料
userinfo.email, userinfo.profile search
搜索 Calendar 活动,可选择限定时间范围
calendar.events fetch
获取单个 Calendar 活动的详细信息
calendar.events search_events
使用筛选条件查找 Calendar 活动
calendar.events read_event
按 ID 读取 Google Calendar 活动
calendar.events
Google Drive 工具
说明
权限范围 get_profile
返回当前 Drive 用户的个人资料
userinfo.email, userinfo.profile list_drives
列出用户可访问的共享云端硬盘
drive.readonly search
使用查询条件搜索 Drive 文件
drive.readonly recent_documents
返回最近修改的文档
drive.readonly fetch
下载 Drive 文件的内容
drive.readonly
Microsoft Teams 工具
说明
权限范围 search
搜索 Microsoft Teams 聊天和频道消息
Chat.Read, ChannelMessage.Read.All fetch
按路径获取 Teams 消息
Chat.Read, ChannelMessage.Read.All get_chat_members
列出 Teams 聊天的成员
Chat.Read get_profile
返回已通过身份验证的 Teams 用户的个人资料
User.Read
Outlook Calendar 工具
说明
权限范围 search_events
使用日期筛选条件搜索 Outlook Calendar 活动
Calendars.Read fetch_event
获取单个活动的详细信息
Calendars.Read fetch_events_batch
在一次调用中获取多个活动
Calendars.Read list_events
列出指定日期范围内的日历活动
Calendars.Read get_profile
获取当前用户的个人资料
User.Read
Outlook 邮件 工具
说明
权限范围 get_profile
返回 Outlook 账户的个人资料信息
User.Read list_messages
从文件夹中获取 Outlook 邮件
Mail.Read search_messages
搜索 Outlook 邮件,可选择使用筛选条件
Mail.Read get_recent_emails
返回最近收到的邮件
Mail.Read fetch_message
根据 ID 获取一封邮件
Mail.Read fetch_messages_batch
在一次请求中获取多封邮件
Mail.Read
Sharepoint 工具
说明
权限范围 get_site
根据主机名和路径解析 SharePoint 站点
Sites.Read.All search
按关键词搜索 SharePoint/OneDrive 文档
Sites.Read.All, Files.Read.All list_recent_documents
返回最近访问过的文档
Files.Read.All fetch
从 Graph 文件下载 URL 获取内容
Files.Read.All get_profile
获取当前用户的个人资料
User.Read
如果您使用工具搜索 ,可以推迟加载 MCP 服务器提供的函数,直到模型判断需要使用它们时再加载。为此,请在 MCP 服务器的工具定义中设置 defer_loading: true。
延迟加载 MCP 服务器时,模型仍可根据该服务器的标签和说明来决定何时搜索它,但各个函数的定义只会在需要时加载。这有助于减少总体 Token 用量,对于提供大量函数的 MCP 服务器尤其有用。
1
2
3
4
5
6
7
8 {
"type" : "mcp" ,
"server_label" : "dmcp" ,
"server_description" : "A Dungeons and Dragons MCP server to assist with dice rolling." ,
"server_url" : "https://dmcp-server.deno.dev/mcp" ,
"defer_loading" : true ,
"require_approval" : "never"
}
MCP 工具可让您将 OpenAI 模型连接到外部服务。这项功能强大,但也存在一些风险。
使用连接器时,可能会将敏感数据发送给 OpenAI,或允许模型读取这些服务中可能包含敏感信息的数据。
远程 MCP 服务器存在同样的风险,而且未经 OpenAI 验证。这些服务器可以让模型访问、发送和接收数据,以及在这些服务中执行操作。所有 MCP 服务器都是第三方服务,受其各自的条款与条件约束。
如果您发现恶意 MCP 服务器,请向 security@openai.com 举报。
以下是集成连接器和远程 MCP 服务器时可参考的一些最佳实践。
提示注入 是任何 LLM 应用都需要重视的安全问题。当您允许模型访问能够读取敏感数据或执行操作的 MCP 服务器和连接器时,尤其需要注意这一点。如果提供给模型的提示包含用户提供的内容,请谨慎使用这些工具,并采取适当的防护措施。
使用 require_approval 和 allowed_tools 参数的可用配置,确保所有敏感操作都必须经过审批流程。
无论工具调用的输出来自连接器还是远程 MCP 服务器,请求其中提供的 URL 或嵌入其中的图片 URL 都可能存在危险。在应用代码中嵌入这些 URL 或以其他方式使用它们之前,请确保您信任提供这些 URL 的域名和服务。
请选择由服务提供商自行托管的官方服务器(例如,我们建议连接到 Stripe 在 mcp.stripe.com 托管的 Stripe 服务器,而不是第三方托管的 Stripe MCP 服务器)。目前,官方远程 MCP 服务器还不多,因此您可能会考虑使用其他组织托管的 MCP 服务器。这些组织并不运营该服务器,而是通过您的 API 将请求代理转发到相应服务。如果您必须这样做,请格外谨慎地对这些“聚合服务商”开展尽职调查,并仔细审查它们如何使用您的数据。
MCP 服务器会自行定义工具,因此可能会请求一些您不愿与该 MCP 服务器托管方共享的数据。正因如此,Responses API 中的 MCP 工具默认要求每次 MCP 工具调用都经过审批。开发应用时,请仔细、全面地审查与这些 MCP 服务器共享的数据类型。当您确信该 MCP 服务器值得信任时,可以跳过这些审批,以降低执行延迟。
我们还建议记录发送到 MCP 服务器的所有数据。如果您使用 Responses API 并设置了 store=true,API 已会记录这些数据并保留 30 天,除非您的组织启用了零数据保留。您也可以在自己的系统中记录这些数据,并定期审查,以确保数据共享符合您的预期。
恶意 MCP 服务器可能包含隐藏指令(提示注入),旨在让 OpenAI 模型出现意外行为。虽然 OpenAI 已内置防护措施来帮助检测和阻止这些威胁,但您仍必须仔细审查输入和输出,并确保只连接到可信服务器。
MCP 服务器可能会出乎意料地更新工具行为,从而可能导致非预期或恶意行为。
MCP 工具兼容零数据保留和数据驻留,但需要注意,MCP 服务器是第三方服务,发送到 MCP 服务器的数据受该服务的数据保留和数据驻留政策约束。
换句话说,如果您的组织选择在欧洲进行数据驻留,在通信或数据发送到 MCP 服务器之前,OpenAI 会将客户内容的推理和存储限制在欧洲进行。您有责任确保 MCP 服务器也遵守您的零数据保留或数据驻留要求。请在此处 进一步了解零数据保留和数据驻留。
API 可用性
速率限制
备注 层级 1
200 RPM
层级 2 和 3
1000 RPM
层级 4 和 5
2000 RPM
定价
ZDR 和数据驻留