Skip to content

add tool name filtering to mcp server implementation #1220

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JohnUiterwyk
Copy link
Contributor

adds the ability to set a list of allowed tools when creating an MCPServer instance, such that list_tools and call_tool will be checked against the list of allowed tools if its set.
#1219

@@ -139,6 +145,9 @@ async def main():
If you want to inherit the environment variables from the parent process, use `env=os.environ`.
"""

allowed_tools: list[str] | None = None

Choose a reason for hiding this comment

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

No need to repeat this attribute definition on the subclasses

@timesler
Copy link
Contributor

timesler commented Apr 10, 2025

Would be fantastic to see this merged. Currently overriding the MCPServerStdio class to do this. @JohnUiterwyk are you working on it or would you like any help?

@Kludex
Copy link
Member

Kludex commented Apr 11, 2025

No further action needed here. I'll get to it at some point.

@DouweM
Copy link
Contributor

DouweM commented Apr 30, 2025

@JohnUiterwyk Looks reasonable, can you please rebase on top of main?

@DouweM DouweM marked this pull request as draft April 30, 2025 19:03
@DouweM DouweM self-assigned this Apr 30, 2025
@DouweM
Copy link
Contributor

DouweM commented Apr 30, 2025

@JohnUiterwyk Looking at this and similar suggestions to modify MCP tool definitions like #1437, I'm thinking it would be better to implement this similar to the prepare function that already exists on Tools: https://ai.pydantic.dev/tools/#tool-prepare. That can return None to skip the tool, and set extra properties like strict.

There's also #1474 which considers adding an agent-wide prepare_tools function that can modify all the tools including skipping some. I think it would make sense to have something similar on MCP servers: a function that gets all the tools and can filter and modify them. Would you be up for implementing that here?

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

Successfully merging this pull request may close these issues.

5 participants