Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions docs/src/content/docs/guides/mcp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import hostedAgentExample from '../../../../../examples/docs/mcp/hostedAgent.ts?
import hostedExample from '../../../../../examples/docs/mcp/hosted.ts?raw';
import hostedStreamExample from '../../../../../examples/docs/mcp/hostedStream.ts?raw';
import hostedHITLExample from '../../../../../examples/docs/mcp/hostedHITL.ts?raw';
import hostedConnectorExample from '../../../../../examples/docs/mcp/hostedConnector.ts?raw';
import streamableHttpExample from '../../../../../examples/docs/mcp/streamableHttp.ts?raw';
import stdioExample from '../../../../../examples/docs/mcp/stdio.ts?raw';
import toolFilterExample from '../../../../../examples/docs/mcp/tool-filter.ts?raw';
Expand Down Expand Up @@ -68,6 +69,18 @@ If you can programmatically determine whether a tool call is safe, you can use t
title="Human in the loop with hosted MCP tools"
/>

### Connector-backed hosted servers

Hosted MCP also supports OpenAI connectors. Instead of providing a `serverUrl`, pass the connector's `connectorId` and an `authorization` token. The Responses API then handles authentication and exposes the connector's tools through the hosted MCP interface.

<Code
lang="typescript"
code={hostedConnectorExample}
title="Connector-backed hosted MCP tool"
/>

In this example the `GOOGLE_CALENDAR_AUTHORIZATION` environment variable holds an OAuth token obtained from the Google OAuth Playground, which authorizes the connector-backed server to call the Calendar API. For a runnable sample that also demonstrates streaming, see [`examples/connectors`](https://github.com/openai/openai-agents-js/tree/main/examples/connectors).

Fully working samples (Hosted tools/Streamable HTTP/stdio + Streaming, HITL, onApproval) are [examples/mcp](https://github.com/openai/openai-agents-js/tree/main/examples/mcp) in our GitHub repository.

## 2. Streamable HTTP MCP servers
Expand Down Expand Up @@ -102,11 +115,7 @@ Only enable this if you're confident the tool list won't change. To invalidate t

You can restrict which tools are exposed from each server by passing either a static filter via `createMCPToolStaticFilter` or a custom function. Here’s a combined example showing both approaches:

<Code
lang="typescript"
code={toolFilterExample}
title="Tool filtering"
/>
<Code lang="typescript" code={toolFilterExample} title="Tool filtering" />

## Further reading

Expand Down
13 changes: 13 additions & 0 deletions docs/src/content/docs/ja/guides/mcp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import hostedAgentExample from '../../../../../../examples/docs/mcp/hostedAgent.
import hostedExample from '../../../../../../examples/docs/mcp/hosted.ts?raw';
import hostedStreamExample from '../../../../../../examples/docs/mcp/hostedStream.ts?raw';
import hostedHITLExample from '../../../../../../examples/docs/mcp/hostedHITL.ts?raw';
import hostedConnectorExample from '../../../../../../examples/docs/mcp/hostedConnector.ts?raw';
import streamableHttpExample from '../../../../../../examples/docs/mcp/streamableHttp.ts?raw';
import stdioExample from '../../../../../../examples/docs/mcp/stdio.ts?raw';
import toolFilterExample from '../../../../../../examples/docs/mcp/tool-filter.ts?raw';
Expand Down Expand Up @@ -68,6 +69,18 @@ Hosted ツールは、往復の処理全体をモデル側に任せます。あ
title="Human in the loop with hosted MCP tools"
/>

### コネクター対応の Hosted サーバー

Hosted MCP は OpenAI コネクターにも対応しています。`serverUrl` の代わりにコネクターの `connectorId` と `authorization` トークンを指定すると、Responses API が認証を処理し、コネクターが公開するツールを hosted MCP インターフェース経由で利用できます。

<Code
lang="typescript"
code={hostedConnectorExample}
title="Connector-backed hosted MCP tool"
/>

この例では、`GOOGLE_CALENDAR_AUTHORIZATION` 環境変数に Google OAuth Playground で取得した OAuth トークンを保存し、コネクター経由で Calendar API を呼び出しています。ストリーミングを含む実行可能なサンプルは [`examples/connectors`](https://github.com/openai/openai-agents-js/tree/main/examples/connectors) を参照してください。

完全に動作するサンプル(Hosted ツール/Streamable HTTP/stdio + Streaming、HITL、onApproval)は、GitHub リポジトリの [examples/mcp](https://github.com/openai/openai-agents-js/tree/main/examples/mcp) にあります。

## 2. Streamable HTTP MCP servers
Expand Down
17 changes: 17 additions & 0 deletions examples/docs/mcp/hostedConnector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Agent, hostedMcpTool } from '@openai/agents';

const authorization = process.env.GOOGLE_CALENDAR_AUTHORIZATION!;

export const connectorAgent = new Agent({
name: 'Calendar Assistant',
instructions:
"You are a helpful assistant that can answer questions about the user's calendar.",
tools: [
hostedMcpTool({
serverLabel: 'google_calendar',
connectorId: 'connector_googlecalendar',
authorization,
requireApproval: 'never',
}),
],
});