Function Calling でモデルに提供するツールに加えて、リモート MCP サーバー や Secure MCP Tunnel を使うと、モデルでできることが広がります。モデルは、ユーザーのプロンプトに応答するために必要に応じて外部サービスに接続し、そのサービスを操作できます。これらのツール呼び出しを自動的に許可することも、開発者による明示的な承認を必須にすることもできます。
このガイドでは、Responses API で MCP ツールを使う方法を説明します。既存のモデルでは、引き続き組み込みコネクタを利用できます。非推奨化の方針と対応モデルでの使用例は、従来のコネクタ を参照してください。Agents API のセッションについては、MCP 接続 を参照してください。マネージドサービスまたはサンドボックスから接続する方法を説明しています。
MCP サーバーが非公開の場合や、オンプレミス環境またはファイアウォールの内側にある場合は、Secure MCP Tunnel を使うと、サーバーをインターネットに公開せずに対応する OpenAI 製品に接続できます。最新の公開リリースは openai/tunnel-client からダウンロードしてください。
ツールのタイプを mcp に設定して、Responses API で使用します。リモート MCP サーバーには server_url を設定します。ローカル MCP サーバーには tunnel_id を指定し、Secure MCP Tunnel 経由で接続します。サーバーによっては、OAuth アクセストークンを authorization パラメーターに指定する必要があります。
次の例では、一般公開されている OpenAI Docs MCP サーバー を使って、Responses 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-6-astra",
"tools": [
{
"type": "mcp",
"server_label": "openai_docs",
"server_description": "Search and read the public OpenAI documentation.",
"server_url": "https://developers.openai.com/mcp",
"require_approval": "never"
}
],
"input": "Search the OpenAI docs for Responses API streaming and return the relevant links."
}' 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: "openai_docs",
server_description: "Search and read the public OpenAI documentation.",
server_url: "https://developers.openai.com/mcp",
require_approval: "never",
},
],
input:
"Search the OpenAI docs for Responses API streaming and return the relevant links.",
});
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": "openai_docs",
"server_description": "Search and read the public OpenAI documentation.",
"server_url": "https://developers.openai.com/mcp",
"require_approval": "never",
},
],
input="Search the OpenAI docs for Responses API streaming and return the relevant links.",
)
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("openai_docs")
tool.OfMcp.ServerDescription = openai.String("Search and read the public OpenAI documentation.")
tool.OfMcp.ServerURL = openai.String("https://developers.openai.com/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("Search the OpenAI docs for Responses API streaming and return the relevant links.")},
})
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(
"Search the OpenAI docs for Responses API streaming and return the relevant links.")
.addTool(
Tool.Mcp.builder()
.serverLabel("openai_docs")
.serverDescription("Search and read the public OpenAI documentation.")
.serverUrl("https://developers.openai.com/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: "openai_docs",
serverUri: new Uri("https://developers.openai.com/mcp"),
toolCallApprovalPolicy: DefaultMcpToolCallApprovalPolicy.NeverRequireApproval
)
);
options.InputItems.Add(ResponseItem.CreateUserMessageItem("Search the OpenAI docs for Responses API streaming and return the relevant links."));
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: "openai_docs",
server_description: "Search and read the public OpenAI documentation.",
server_url: "https://developers.openai.com/mcp",
require_approval: "never"
}
],
input: "Search the OpenAI docs for Responses API streaming and return the relevant links."
)
puts(response.output_text)
Responses API では、信頼できるリモート MCP サーバーだけを使用してください。悪意のあるサーバーは、モデルのコンテキストに入るあらゆる情報から機密データを抜き取る可能性があります。このツールを使用する前に、以下の「リスクと安全対策 」をよくお読みください。
API は、モデルのレスポンスの output 配列に新しい項目を追加して返します。モデルが MCP サーバーの使用を選択すると、まずサーバーに利用可能なツールの一覧をリクエストします。これにより、出力に mcp_list_tools 項目が生成されます。以下の出力例では検索ツールのみを示し、その説明を短くしています。サーバーはほかのドキュメントツールも提供しています。
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 {
"id" : "mcpl_68a6102a4968819c8177b05584dd627b0679e572a900e618" ,
"type" : "mcp_list_tools" ,
"server_label" : "openai_docs" ,
"tools" : [
{
"annotations" : {
"readOnlyHint" : true ,
"destructiveHint" : false
},
"description" : "Search the public OpenAI documentation." ,
"input_schema" : {
"$schema" : "http://json-schema.org/draft-07/schema#" ,
"type" : "object" ,
"properties" : {
"query" : {
"type" : "string" ,
"minLength" : 1
},
"limit" : {
"type" : "integer" ,
"minimum" : 1 ,
"maximum" : 50
},
"cursor" : {
"type" : "string"
}
},
"required" : [ "query" ]
},
"name" : "search_openai_docs"
}
]
}
モデルが MCP サーバーのツールのいずれかを呼び出すと、出力に mcp_call 項目も追加されます。この項目で、モデルが MCP ツールに送信した内容と、ツールが返した出力を確認できます。
1 2 3 4 5 6 7 8 9 10 {
"id" : "mcp_68a6102d8948819c9b1490d36d5ffa4a0679e572a900e618" ,
"type" : "mcp_call" ,
"approval_request_id" : null ,
"arguments" : "{ \" query \" : \" Responses API streaming \" , \" limit \" :1}" ,
"error" : null ,
"name" : "search_openai_docs" ,
"output" : "{ \" hits \" :[{ \" url \" : \" https://developers.openai.com/api/docs/guides/streaming-responses \" }]}" ,
"server_label" : "openai_docs"
}
以下では、MCP ツールの仕組み、利用可能なツールの絞り込み、ツール呼び出しの承認リクエストへの対応について詳しく説明します。
最近のモデルの多くは、Responses API で MCP ツールを利用できます。使用するモデルが MCP ツールに対応しているかどうかは、モデル一覧 で確認してください。MCP ツールの利用料金は、ツール定義のインポートやツール呼び出しで使用したトークン に対してのみ発生します。呼び出しごとの追加料金はありません。
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 24 25 26 27 28 29 30 31 32 33 34 {
"id" : "mcpl_68a6102a4968819c8177b05584dd627b0679e572a900e618" ,
"type" : "mcp_list_tools" ,
"server_label" : "openai_docs" ,
"tools" : [
{
"annotations" : {
"readOnlyHint" : true ,
"destructiveHint" : false
},
"description" : "Search the public OpenAI documentation." ,
"input_schema" : {
"$schema" : "http://json-schema.org/draft-07/schema#" ,
"type" : "object" ,
"properties" : {
"query" : {
"type" : "string" ,
"minLength" : 1
},
"limit" : {
"type" : "integer" ,
"minimum" : 1 ,
"maximum" : 50
},
"cursor" : {
"type" : "string"
}
},
"required" : [ "query" ]
},
"name" : "search_openai_docs"
}
]
}
API リクエストのコンテキストに mcp_list_tools 項目が含まれている限り、API が会話 のターンごとに MCP サーバーからツールの一覧を再取得することはありません。レイテンシを抑えるため、どの会話でも、またワークフローを実行するたびに、この項目をモデルのコンテキストに保持することをおすすめします。
MCP サーバーによっては数十個のツールがあり、多くのツールをモデルに提供すると、コストやレイテンシが増大する場合があります。必要なツールが一部だけなら、allowed_tools パラメーターを使ってインポート対象を絞り込めます。次の例では、ドキュメントへのリンクを検索するために search_openai_docs だけをインポートします。
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": "openai_docs",
"server_description": "Search and read the public OpenAI documentation.",
"server_url": "https://developers.openai.com/mcp",
"require_approval": "never",
"allowed_tools": ["search_openai_docs"]
}
],
"input": "Search the OpenAI docs for Responses API streaming and return the relevant links."
}' 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: "openai_docs",
server_description: "Search and read the public OpenAI documentation.",
server_url: "https://developers.openai.com/mcp",
require_approval: "never",
allowed_tools: ["search_openai_docs"],
},
],
input:
"Search the OpenAI docs for Responses API streaming and return the relevant links.",
});
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": "openai_docs",
"server_description": "Search and read the public OpenAI documentation.",
"server_url": "https://developers.openai.com/mcp",
"require_approval": "never",
"allowed_tools": ["search_openai_docs"],
}
],
input="Search the OpenAI docs for Responses API streaming and return the relevant links.",
)
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("openai_docs")
tool.OfMcp.ServerDescription = openai.String("Search and read the public OpenAI documentation.")
tool.OfMcp.ServerURL = openai.String("https://developers.openai.com/mcp")
tool.OfMcp.RequireApproval = responses.ToolMcpRequireApprovalUnionParam{OfMcpToolApprovalSetting: openai.String("never")}
tool.OfMcp.AllowedTools = responses.ToolMcpAllowedToolsUnionParam{OfMcpAllowedTools: []string{"search_openai_docs"}}
response, err := client.Responses.New(context.Background(), responses.ResponseNewParams{
Model: "gpt-6-astra",
Tools: []responses.ToolUnionParam{tool},
Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Search the OpenAI docs for Responses API streaming and return the relevant links.")},
})
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(
"Search the OpenAI docs for Responses API streaming and return the relevant links.")
.addTool(
Tool.Mcp.builder()
.serverLabel("openai_docs")
.serverDescription("Search and read the public OpenAI documentation.")
.serverUrl("https://developers.openai.com/mcp")
.requireApproval(Tool.Mcp.RequireApproval.McpToolApprovalSetting.NEVER)
.allowedToolsOfMcp(List.of("search_openai_docs"))
.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: "openai_docs",
serverUri: new Uri("https://developers.openai.com/mcp"),
allowedTools: new McpToolFilter() { ToolNames = { "search_openai_docs" } },
toolCallApprovalPolicy: DefaultMcpToolCallApprovalPolicy.NeverRequireApproval
)
);
options.InputItems.Add(ResponseItem.CreateUserMessageItem("Search the OpenAI docs for Responses API streaming and return the relevant links."));
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: "Search the OpenAI docs for Responses API streaming and return the relevant links.",
tools: [
{
type: :mcp,
server_label: "openai_docs",
server_description: "Search and read the public OpenAI documentation.",
server_url: "https://developers.openai.com/mcp",
require_approval: :never,
allowed_tools: ["search_openai_docs"]
}
]
)
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" : "{ \" query \" : \" Responses API streaming \" , \" limit \" :1}" ,
"error" : null ,
"name" : "search_openai_docs" ,
"output" : "{ \" hits \" :[{ \" url \" : \" https://developers.openai.com/api/docs/guides/streaming-responses \" }]}" ,
"server_label" : "openai_docs"
}
この項目には、モデルがツール呼び出しに指定した引数と、リモート MCP サーバーが返した output の両方が含まれます。どのモデルも MCP ツールを複数回呼び出せるため、1 回の API リクエストでこの項目が複数生成されることがあります。
ツール呼び出しが失敗すると、この項目の error フィールドに、MCP プロトコルのエラー、MCP ツールの実行エラー、または一般的な接続エラーが格納されます。MCP のエラーについては、MCP 仕様のエラー処理の項 を参照してください。
デフォルトでは、OpenAI はコネクタやリモート MCP サーバーとデータを共有する前に開発者に承認を求めます。承認を通じて、MCP サーバーに送信するデータを確認し、送信の可否を判断できます。リモート MCP サーバーと共有するすべてのデータを慎重に確認し、必要に応じてログに記録することを強くおすすめします。承認フローを試すには、クイックスタートの例で require_approval を "always" に設定して実行してください。元の設定は "never" です。MCP ツール呼び出しの承認が求められると、Response の出力に mcp_approval_request 項目が生成されます。以下はその例です。
1 2 3 4 5 6 7 {
"id" : "mcpr_682d498e3bd4819196a0ce1664f8e77b04ad1e533afccbfa" ,
"type" : "mcp_approval_request" ,
"arguments" : "{ \" query \" : \" Responses API streaming \" , \" limit \" :1}" ,
"name" : "search_openai_docs" ,
"server_label" : "openai_docs"
}
承認する前に、呼び出し対象のツールとその引数を確認してください。そのうえで、新しい Response オブジェクトを作成し、mcp_approval_response 項目を追加して応答できます。以下の例にあるレスポンス ID と承認リクエスト ID は、自分のリクエストで返された ID に置き換えてください。.NET の例では、最初のレスポンスからこれらの ID を取得します。承認はツール呼び出し 1 回にのみ適用されます。以降の承認リクエストにも同じ手順で対応してください。
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": "openai_docs",
"server_description": "Search and read the public OpenAI documentation.",
"server_url": "https://developers.openai.com/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 import OpenAI from "openai";
const client = new OpenAI();
const resp = await client.responses.create({
model: "gpt-6-astra",
tools: [
{
type: "mcp",
server_label: "openai_docs",
server_description: "Search and read the public OpenAI documentation.",
server_url: "https://developers.openai.com/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": "openai_docs",
"server_description": "Search and read the public OpenAI documentation.",
"server_url": "https://developers.openai.com/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("openai_docs")
tool.OfMcp.ServerDescription = openai.String("Search and read the public OpenAI documentation.")
tool.OfMcp.ServerURL = openai.String("https://developers.openai.com/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("openai_docs")
.serverDescription("Search and read the public OpenAI documentation.")
.serverUrl("https://developers.openai.com/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
32
33
34
35
36
37
38 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",
ToolChoice = ResponseToolChoice.CreateRequiredChoice(),
ParallelToolCallsEnabled = false
};
options.Tools.Add(
ResponseTool.CreateMcpTool(
serverLabel: "openai_docs",
serverUri: new Uri("https://developers.openai.com/mcp"),
allowedTools: new McpToolFilter { ToolNames = { "search_openai_docs" } },
toolCallApprovalPolicy: DefaultMcpToolCallApprovalPolicy.AlwaysRequireApproval
)
);
// Step 1: Create a response that requests tool-call approval.
options.InputItems.Add(ResponseItem.CreateUserMessageItem("Search the OpenAI docs for Responses API streaming and return the relevant links."));
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.ToolChoice = ResponseToolChoice.CreateNoneChoice();
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: "openai_docs",
server_url: "https://developers.openai.com/mcp",
server_description: "Search and read the public OpenAI documentation.",
require_approval: :always
}
]
)
puts(response.output_text)
ここでは previous_response_id パラメーターを使い、承認リクエストを生成した直前の Response に新しい Response をつなげています。モデルのコンテキストに含める内容を細かく制御したい場合は、あるレスポンスの出力を別のレスポンスの入力として渡す こともできます。
リモート MCP サーバーを十分に信頼できると判断した場合は、承認を省略してレイテンシを抑えられます。特定のツールだけ承認を省略するには、以下の例のように、MCP ツールの require_approval パラメーターに対象のツールだけを列挙したオブジェクトを指定します。そのリモート MCP サーバーの全ツールで承認を省略するには、値を 'never' に設定します。
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)
OpenAI Docs MCP サーバー では認証は不要です。ほかの MCP サーバーでは認証が必要な場合があります。最も一般的なのは OAuth アクセストークンを使う方式です。MCP ツールの authorization フィールドにトークンを指定します。
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)
機密情報であるトークンの漏えいを防ぐため、Responses API は authorization フィールドに指定された値を保存しません。作成された Response オブジェクトにもこの値は表示されません。そのため、Responses API でレスポンスを作成するリクエストには、毎回 authorization の値を含める必要があります。
connector_id は、2026 年 9 月 1 日より後にリリースされたモデルでは非推奨です。リモート MCP サーバーに接続するには server_url を指定してください。ローカル MCP サーバーに接続するには
tunnel_id を指定し、 Secure MCP Tunnel を使用してください。既存のモデルでは引き続きコネクタを利用できます。このセクションの例では、上記の日付より前にリリースされた gpt-5.2 を使用します。
Responses API には、一部のサードパーティサービス向けのコネクタが組み込まれています。これらのコネクタを使うと、Dropbox や Gmail などの広く使われているアプリケーションからコンテキストを取得し、モデルからサービスを利用できます。
コネクタはリモート MCP サーバーと同じように使用できます。どちらを使っても、OpenAI のモデルが API リクエスト内でサードパーティのツールにアクセスできます。リモート MCP サーバーの呼び出しでは server_url を渡しますが、コネクタには connector_id を渡します。この ID は、API で利用可能なコネクタを一意に識別します。
コネクタを使うには、アプリケーションから authorization パラメーターに OAuth アクセストークンを渡す必要があります。
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 カレンダー:connector_googlecalendar
Google ドライブ:connector_googledrive
Microsoft Teams:connector_microsoftteams
Outlook 予定表:connector_outlookcalendar
Outlook メール:connector_outlookemail
SharePoint:connector_sharepoint
コネクタの提供では、公式のリモート MCP サーバーがないサービスを優先しています。たとえば GitHub には公式の MCP サーバーがあり、https://api.githubcopilot.com/mcp/ を MCP ツールの server_url フィールドに指定すると接続できます。
authorization フィールドに OAuth アクセストークンを渡してください。OAuth クライアントの登録と認可は、アプリケーション側で別途行う必要があります。
テスト用には、Google の OAuth 2.0 Playground を使って、API リクエストに使用できる一時的なアクセストークンを生成できます。
Playground で API のコネクタ機能をテストするには、まず次のスコープを入力します。
https://www.googleapis.com/auth/calendar.events
Step 1: Select and authorize APIs にこのスコープを入力して、API が Google カレンダーの予定を読み取れるようにします。
Google アカウントでアプリケーションを認可したら、Step 2: Exchange authorization code for tokens に進み、認可コードをトークンに交換します。ここで生成したアクセストークンを使って、API リクエストで Google カレンダーコネクタを利用できます。
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_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_filesDropbox のファイルを検索し、結果を返します。 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_emailsGmail で直近に受信したメールを返します。 gmail.modify read_emailGmail のメールを本文も含めて 1 件取得します。 gmail.modify batch_read_email1 回の呼び出しで Gmail のメールを複数読み取ります。 gmail.modify
Google カレンダー ツール 説明 スコープ get_profile現在のカレンダーユーザーのプロフィールを返します。 userinfo.email, userinfo.profile searchカレンダーの予定を検索します。対象期間も指定できます。 calendar.events fetchカレンダーの予定 1 件の詳細を取得します。 calendar.events search_eventsフィルターを使ってカレンダーの予定を検索します。 calendar.events read_eventID を指定して Google カレンダーの予定を読み取ります。 calendar.events
Google ドライブ ツール 説明 スコープ get_profile現在のドライブユーザーのプロフィールを返します。 userinfo.email, userinfo.profile list_drivesユーザーがアクセスできる共有ドライブの一覧を取得します。 drive.readonly searchクエリを指定してドライブ内のファイルを検索します。 drive.readonly recent_documents直近に更新されたドキュメントを返します。 drive.readonly fetchドライブ内のファイルの内容をダウンロードします。 drive.readonly
Microsoft Teams ツール 説明 スコープ searchMicrosoft Teams のチャットとチャネルのメッセージを検索します。 Chat.Read, ChannelMessage.Read.All fetchパスを指定して Teams のメッセージを取得します。 Chat.Read, ChannelMessage.Read.All get_chat_membersTeams のチャットのメンバー一覧を取得します。 Chat.Read get_profile認証済みの Teams ユーザーのプロフィールを返します。 User.Read
Outlook 予定表 ツール 説明 スコープ search_events日付フィルターを使って Outlook 予定表の予定を検索します。 Calendars.Read fetch_event予定 1 件の詳細を取得します。 Calendars.Read fetch_events_batch1 回の呼び出しで複数の予定を取得します。 Calendars.Read list_events指定した日付範囲の予定を一覧で取得します。 Calendars.Read get_profile現在のユーザーのプロフィールを取得します。 User.Read
Outlook メール ツール 説明 スコープ get_profileOutlook アカウントのプロフィール情報を返します。 User.Read list_messagesフォルダーから Outlook のメールを取得します。 Mail.Read search_messagesOutlook のメールを検索します。フィルターも指定できます。 Mail.Read get_recent_emails直近に受信したメールを返します。 Mail.Read fetch_messageID を指定してメールを 1 件取得します。 Mail.Read fetch_messages_batch1 回のリクエストで複数のメールを取得します。 Mail.Read
SharePoint ツール 説明 スコープ get_siteホスト名とパスから SharePoint サイトを特定します。 Sites.Read.All searchキーワードで SharePoint と OneDrive のドキュメントを検索します。 Sites.Read.All, Files.Read.All list_recent_documents最近アクセスしたドキュメントを返します。 Files.Read.All fetchGraph のファイルダウンロード URL から内容を取得します。 Files.Read.All get_profile現在のユーザーのプロフィールを取得します。 User.Read
ツール検索 を使う場合、MCP サーバーが提供する関数の読み込みを、モデルが必要と判断するまで遅らせることができます。MCP サーバーのツール定義に defer_loading: true を設定してください。
遅延読み込みを設定しても、モデルは MCP サーバーのラベルと説明を参照し、そのサーバーでいつツールを検索するかを判断できます。個々の関数定義は必要なときだけ読み込まれます。これにより全体のトークン使用量を抑えられるため、多数の関数を提供する MCP サーバーで特に有効です。
1
2
3
4
5
6
7
8 {
"type" : "mcp" ,
"server_label" : "openai_docs" ,
"server_description" : "Search and read the public OpenAI documentation." ,
"server_url" : "https://developers.openai.com/mcp" ,
"defer_loading" : true ,
"require_approval" : "never"
}
MCP ツールを使うと、OpenAI のモデルを外部サービスに接続できます。この強力な機能にはリスクも伴います。
コネクタを使うと、機密データを OpenAI に送信したり、接続先のサービスにある機密情報をモデルが読み取れるようにしたりするおそれがあります。
リモート MCP サーバーにも同じリスクがあり、さらに OpenAI による検証を受けていません。これらのサーバーを介して、モデルは接続先のサービスのデータにアクセスし、データを送受信したり、操作を実行したりできます。MCP サーバーはいずれもサードパーティのサービスであり、それぞれの利用規約が適用されます。
悪意のある MCP サーバーを見つけた場合は、security@openai.com に報告してください。
コネクタやリモート MCP サーバーを組み込む際は、以下の対策を検討してください。
プロンプトインジェクション は、どの LLM アプリケーションでも考慮すべき重要なセキュリティリスクです。機密データへのアクセスや操作の実行が可能な MCP サーバーやコネクタをモデルに提供する場合は、特に注意が必要です。モデルに渡すプロンプトにユーザーが提供したコンテンツが含まれる場合は、適切な保護対策を講じたうえで慎重にこれらのツールを使用してください。
たとえば、ウェブページに、社内の CRM で顧客を検索し、その顧客のメールアドレスを URL に含めるようモデルに指示する文が書かれている場合があります。CRM ツールが読み取り専用でも、その URL にアクセスすると、顧客のメールアドレスがアクセス先に伝わります。
企業が公表した内容と非公開の CRM レコードを比較する場合は、まずウェブ検索だけを有効にしたリクエストで公開情報を収集します。そのうち比較に必要な情報を 2 回目のリクエストに渡し、そのリクエストで使えるツールを社内の CRM 検索ツールだけに限定してください。こうすれば、顧客レコードの内容がウェブ検索のクエリや URL に含まれるのを防げます。
require_approval と allowed_tools パラメーターを設定し、機密性の高い操作には必ず承認フローを適用してください。
コネクタやリモート MCP サーバーのツール呼び出しの出力に含まれる URL にリクエストを送ったり、出力に含まれる画像 URL を埋め込んだりすることには危険が伴います。アプリケーションのコードに URL を埋め込む場合や、ほかの方法で使用する場合は、事前にその URL の提供元のドメインとサービスが信頼できることを確認してください。
サービス提供元自身がホストする公式サーバーを選んでください。たとえば Stripe に接続する場合は、サードパーティがホストする Stripe MCP サーバーよりも、Stripe 自身が mcp.stripe.com でホストするサーバーをおすすめします。現時点では公式のリモート MCP サーバーが少ないため、サービスの運営元とは別の組織がホストし、利用者の API を介してサービスへのリクエストを中継する MCP サーバーを検討することもあるでしょう。やむを得ずこうした「アグリゲーター」を利用する場合は、その運営元を十分に調査し、データの扱い方を慎重に確認してください。
MCP サーバーはそれぞれ独自にツールを定義しているため、そのサーバーの運営元とは共有したくないデータを要求する場合があります。このため、Responses API の MCP ツールでは、デフォルトで MCP ツールの呼び出しごとに承認を求めます。アプリケーションの開発時には、接続先の MCP サーバーとどのようなデータを共有するのか、漏れのないよう慎重に確認してください。サーバーを十分に信頼できると判断したら、承認を省略して実行時のレイテンシを抑えることもできます。
MCP サーバーに送信するすべてのデータをログに記録することもおすすめします。Responses API を store=true で使用している場合、組織でゼロデータ保持が有効になっていない限り、これらのデータは API のログに 30 日間保持されます。自社のシステムにもログを記録し、想定どおりにデータが共有されているか定期的に確認することも検討してください。
悪意のある MCP サーバーには、OpenAI のモデルに予期しない動作をさせるための隠れた指示(プロンプトインジェクション)が含まれている場合があります。OpenAI はこうした脅威の検出とブロックを支援する保護機能を組み込んでいますが、入力と出力を慎重に確認し、接続先を信頼できるサーバーのみに限定することが不可欠です。
MCP サーバー側でツールの動作が予期せず変更され、意図しない動作や悪意のある動作につながる可能性もあります。
MCP ツールはゼロデータ保持とデータレジデンシーに対応しています。ただし、MCP サーバーはサードパーティのサービスであり、サーバーに送信されたデータには、接続先のデータ保持ポリシーとデータレジデンシーポリシーが適用されます。
たとえば、組織がデータレジデンシーの対象地域を欧州に設定している場合、MCP サーバーへの通信またはデータ送信が行われるまでは、OpenAI は顧客コンテンツを使った推論とそのコンテンツの保存を欧州内に限定します。MCP サーバーも組織のゼロデータ保持やデータレジデンシーの要件を満たしているかどうかは、利用する組織の責任で確認してください。ゼロデータ保持とデータレジデンシーの詳細は、データの取り扱いに関するガイド を参照してください。