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
15 changes: 14 additions & 1 deletion docs/src/content/docs/guides/tools.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import toolsFunctionExample from '../../../../../examples/docs/tools/functionToo
import toolsHostedToolsExample from '../../../../../examples/docs/tools/hostedTools.ts?raw';
import nonStrictSchemaTools from '../../../../../examples/docs/tools/nonStrictSchemaTools.ts?raw';
import agentsAsToolsExample from '../../../../../examples/docs/tools/agentsAsTools.ts?raw';
import mcpLocalServer from '../../../../../examples/docs/tools/mcpLocalServer.ts?raw';

Tools let an Agent **take actions** – fetch data, call external APIs, execute code, or even use a
computer. The JavaScript/TypeScript SDK supports three categories:
computer. The JavaScript/TypeScript SDK supports four categories:

1. **Hosted tools** – run alongside the model on OpenAI servers. _(web search, file search, computer use, code interpreter, image generation)_
2. **Function tools** – wrap any local function with a JSON schema so the LLM can call it.
3. **Agents as tools** – expose an entire Agent as a callable tool.
4. **Local MCP servers** – attach a Model Context Protocol server running on your machine.

---

Expand Down Expand Up @@ -86,6 +88,17 @@ Under the hood the SDK:

---

## 4. Local MCP servers

You can expose tools via a local [Model Context Protocol](https://modelcontextprotocol.io/) server and attach them to an agent.
Use `MCPServerStdio` to spawn and connect to the server:

<Code lang="typescript" code={mcpLocalServer} title="Local MCP server" />

See [`filesystem-example.ts`](https://github.com/openai/openai-agents-js/tree/main/examples/mcp/filesystem-example.ts) for a complete example.

---

## Tool use behaviour

Refer to the [Agents guide](/openai-agents-js/guides/agents#forcing-tool-use) for controlling when and how a model
Expand Down
14 changes: 13 additions & 1 deletion docs/src/content/docs/ja/guides/tools.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import toolsFunctionExample from '../../../../../../examples/docs/tools/function
import toolsHostedToolsExample from '../../../../../../examples/docs/tools/hostedTools.ts?raw';
import nonStrictSchemaTools from '../../../../../../examples/docs/tools/nonStrictSchemaTools.ts?raw';
import agentsAsToolsExample from '../../../../../../examples/docs/tools/agentsAsTools.ts?raw';
import mcpLocalServer from '../../../../../../examples/docs/tools/mcpLocalServer.ts?raw';

ツールを使うことで、エージェントは **行動を実行** できます。たとえばデータの取得、外部 API の呼び出し、コードの実行、さらにはコンピュータ操作まで可能です。JavaScript / TypeScript SDK は次の 3 カテゴリーをサポートします:
ツールを使うことで、エージェントは **行動を実行** できます。たとえばデータの取得、外部 API の呼び出し、コードの実行、さらにはコンピュータ操作まで可能です。JavaScript / TypeScript SDK は次の 4 カテゴリーをサポートします:

1. **組み込みツール(Hosted)** – モデルと同じ OpenAI サーバー上で動作します。 _(Web 検索、ファイル検索、コンピュータ操作、Code Interpreter、画像生成)_
2. **関数ツール** – 任意のローカル関数を JSON スキーマでラップし、LLM から呼び出せるようにします。
3. **エージェントをツールとして使用** – エージェント全体を呼び出し可能なツールとして公開します。
4. **ローカル MCP サーバー** – ローカルで動作する Model Context Protocol サーバーをエージェントに追加します。

---

Expand Down Expand Up @@ -82,6 +84,16 @@ SDK は内部で次の処理を行います:

---

## 4. ローカル MCP サーバー

ローカルで動作する [Model Context Protocol](https://modelcontextprotocol.io/) サーバーからツールを公開し、エージェントに接続できます。`MCPServerStdio` を使用してサーバーを起動し接続します:

<Code lang="typescript" code={mcpLocalServer} title="Local MCP server" />

`filesystem-example.ts` の完全な例もご覧ください。

---

## ツール使用の挙動

ツールを **いつ・どのように** 使うかを制御する方法は、[エージェント](/openai-agents-js/ja/guides/agents#forcing-tool-use) を参照してください (`tool_choice`、`toolUseBehavior` など)。
Expand Down
12 changes: 12 additions & 0 deletions examples/docs/tools/mcpLocalServer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Agent, MCPServerStdio } from '@openai/agents';

const server = new MCPServerStdio({
fullCommand: 'npx -y @modelcontextprotocol/server-filesystem ./sample_files',
});

await server.connect();

const agent = new Agent({
name: 'Assistant',
mcpServers: [server],
});