-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: Support adding a name prefix to MCPTool and MCPToolset #1226
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
Closed
calvingiles
wants to merge
4
commits into
google:main
from
calvingiles:feature/support-mcp-tool-prefix
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c055ecf
feat: Support adding a name prefix to MCPTool and MCPToolset
calvingiles 4ebcc0e
Merge branch 'main' into feature/support-mcp-tool-prefix
calvingiles 8b766fc
Merge branch 'main' into feature/support-mcp-tool-prefix
calvingiles ed01db7
Merge branch 'main' into feature/support-mcp-tool-prefix
calvingiles File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,6 +67,7 @@ def __init__( | |
| mcp_session_manager: MCPSessionManager, | ||
| auth_scheme: Optional[AuthScheme] = None, | ||
| auth_credential: Optional[AuthCredential] = None, | ||
| tool_name_prefix: str = "", | ||
| ): | ||
| """Initializes an MCPTool. | ||
|
|
||
|
|
@@ -78,12 +79,20 @@ def __init__( | |
| mcp_session_manager: The MCP session manager to use for communication. | ||
| auth_scheme: The authentication scheme to use. | ||
| auth_credential: The authentication credential to use. | ||
| tool_name_prefix: string to add to the start of the tool name. For example, | ||
| `prefix="ns_"` would name `my_tool` as `ns_my_tool`. | ||
|
|
||
| Raises: | ||
| ValueError: If mcp_tool or mcp_session_manager is None. | ||
| """ | ||
| if mcp_tool is None: | ||
| raise ValueError("mcp_tool cannot be None") | ||
| if mcp_session_manager is None: | ||
| raise ValueError("mcp_session_manager cannot be None") | ||
| raw_name = mcp_tool.name | ||
| name = tool_name_prefix + raw_name | ||
| super().__init__( | ||
| name=mcp_tool.name, | ||
| name=name, | ||
| description=mcp_tool.description if mcp_tool.description else "", | ||
| auth_config=AuthConfig( | ||
| auth_scheme=auth_scheme, raw_auth_credential=auth_credential | ||
|
|
@@ -93,6 +102,8 @@ def __init__( | |
| ) | ||
| self._mcp_tool = mcp_tool | ||
| self._mcp_session_manager = mcp_session_manager | ||
| self._tool_name_prefix = tool_name_prefix | ||
| self._raw_name = raw_name | ||
|
|
||
| @override | ||
| def _get_declaration(self) -> FunctionDeclaration: | ||
|
|
@@ -128,7 +139,7 @@ async def _run_async_impl( | |
| # Get the session from the session manager | ||
| session = await self._mcp_session_manager.create_session(headers=headers) | ||
|
|
||
| response = await session.call_tool(self.name, arguments=args) | ||
| response = await session.call_tool(self._mcp_tool.name, arguments=args) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. besides this line, I feel all the other changes in this file are not necessary and will cause problem as I mentioned in the comment of the whole file, would you please try and test it ? |
||
| return response | ||
|
|
||
| async def _get_headers( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel the changes in this file will cause the prefix to be added twice, given we already handled prefix prepending in base toolset, did you test it ?
I think the only changes needed in this file is
could you try and verify ?