Skip to content

Commit 161965f

Browse files
committed
docs: update MCP guide, add tool-filter example, and remove unrelated changeset
1 parent 26a2746 commit 161965f

File tree

3 files changed

+32
-23
lines changed

3 files changed

+32
-23
lines changed

.changeset/heavy-yaks-mate.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

docs/src/content/docs/guides/mcp.mdx

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import hostedStreamExample from '../../../../../examples/docs/mcp/hostedStream.t
1010
import hostedHITLExample from '../../../../../examples/docs/mcp/hostedHITL.ts?raw';
1111
import streamableHttpExample from '../../../../../examples/docs/mcp/streamableHttp.ts?raw';
1212
import stdioExample from '../../../../../examples/docs/mcp/stdio.ts?raw';
13+
import toolFilterExample from '../../../../../examples/docs/mcp/tool-filter.ts?raw';
1314

1415
The [**Model Context Protocol (MCP)**](https://modelcontextprotocol.io) is an open protocol that standardizes how applications provide tools and context to LLMs. From the MCP docs:
1516

@@ -99,24 +100,13 @@ Only enable this if you're confident the tool list won't change. To invalidate t
99100

100101
### Tool filtering
101102

102-
You can restrict which tools are exposed from each server. Pass either a static filter
103-
using `createMCPToolStaticFilter` or a custom function:
104-
105-
```ts
106-
const server = new MCPServerStdio({
107-
fullCommand: 'my-server',
108-
toolFilter: createMCPToolStaticFilter({
109-
allowed: ['safe_tool'],
110-
blocked: ['danger_tool'],
111-
}),
112-
});
113-
114-
const dynamicServer = new MCPServerStreamableHttp({
115-
url: 'http://localhost:3000',
116-
toolFilter: ({ runContext }, tool) =>
117-
runContext.context.allowAll || tool.name !== 'admin',
118-
});
119-
```
103+
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:
104+
105+
<Code
106+
lang="typescript"
107+
code={toolFilterExample}
108+
title="Tool filtering"
109+
/>
120110

121111
## Further reading
122112

examples/docs/mcp/tool-filter.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {
2+
MCPServerStdio,
3+
MCPServerStreamableHttp,
4+
createMCPToolStaticFilter,
5+
MCPToolFilterContext,
6+
} from '@openai/agents';
7+
8+
interface ToolFilterContext {
9+
allowAll: boolean;
10+
}
11+
12+
const server = new MCPServerStdio({
13+
fullCommand: 'my-server',
14+
toolFilter: createMCPToolStaticFilter({
15+
allowed: ['safe_tool'],
16+
blocked: ['danger_tool'],
17+
}),
18+
});
19+
20+
const dynamicServer = new MCPServerStreamableHttp({
21+
url: 'http://localhost:3000',
22+
toolFilter: async ({ runContext }: MCPToolFilterContext, tool) =>
23+
(runContext.context as ToolFilterContext).allowAll || tool.name !== 'admin',
24+
});

0 commit comments

Comments
 (0)