Skip to content

Add MCP server tool filtering support to agents-js #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

vrtnis
Copy link
Contributor

@vrtnis vrtnis commented Jul 1, 2025

Hey all - this PR brings a new tool filtering feature to our MCP integrations. This resolves #162 based on openai/openai-agents-python#861

You can now:

  1. Use createStaticToolFilter for quick allow/block lists

  2. Provide a custom filter function to make dynamic decisions based on runContext

  3. Updated core API so getAllTools now accepts your runContext, ensuring filters are applied correctly

  4. Documentation enhancements in docs/guides/mcp.mdx

  5. New example (examples/mcp/tool-filter-example.ts) to demonstrate both static and dynamic filtering

  6. Comprehensive tests covering static lists, callable filters, multi-server hierarchies, and cache interactions

All tests pass and you can try it out by pnpm -F mcp start:tool-filter

Copy link

changeset-bot bot commented Jul 1, 2025

🦋 Changeset detected

Latest commit: 713f8e0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@openai/agents-realtime Patch
@openai/agents-core Patch
@openai/agents Patch
@openai/agents-openai Patch
@openai/agents-extensions Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dkundel-openai
Copy link
Collaborator

@seratch can you review please?

Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sending this! I haven't verified the actual behavior yet but let me share a few quick comments

@vrtnis
Copy link
Contributor Author

vrtnis commented Jul 10, 2025

thanks for the comments, @seratch! esp. the point about moving filtering logic that makes sense for keeping the server implementation focused on transport.
i’ve pushed an update that moves filtering into the agent and runner layer, where it can be handled with proper context. look forward to your feedback!

vrtnis added 2 commits July 10, 2025 20:18
- Moved tool filtering logic to agent/runner layer
- Removed server-side filtering and context coupling
- Updated test suite to reflect new behavior
@vrtnis
Copy link
Contributor Author

vrtnis commented Jul 11, 2025

Thanks @seratch. That makes sense and i’ve removed the runContext and agent from the call to underlying.listTools(), so that now filtering happens entirely in getAllMcpFunctionTools() on the agent side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add tool filter to MCP support
3 participants