Skip to content

Commit f2615a3

Browse files
authored
feat(mcp): allow MCP Server --tool_name filter to reference function groups (#1093)
`nat mcp serve --tool_names` only filtered based on function names. This should be expanded to support function group names as well. Closes ## By Submitting this PR I confirm: - I am familiar with the [Contributing Guidelines](https://github.com/NVIDIA/NeMo-Agent-Toolkit/blob/develop/docs/source/resources/contributing.md). - We require that all contributors "sign-off" on their commits. This certifies that the contribution is your original work, or you have rights to submit it under the same license, or a compatible license. - Any contribution which contains commits that are not Signed-Off will not be accepted. - When the PR is ready for review, new or existing tests cover these changes. - When the PR is ready for review, the documentation is up to date with these changes. ## Summary by CodeRabbit * **New Features** * Enhanced function registration now supports group prefix-based filtering alongside exact name matching, providing more flexible organization and selection of available functions. Authors: - Will Killian (https://github.com/willkill07) Approvers: - Eric Evans II (https://github.com/ericevans-nv) URL: #1093
1 parent 4648f7d commit f2615a3

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/nat/front_ends/mcp/mcp_front_end_config.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ class MCPFrontEndConfig(FrontEndBaseConfig, name="mcp"):
3737
port: int = Field(default=9901, description="Port to bind the server to (default: 9901)", ge=0, le=65535)
3838
debug: bool = Field(default=False, description="Enable debug mode (default: False)")
3939
log_level: str = Field(default="INFO", description="Log level for the MCP server (default: INFO)")
40-
tool_names: list[str] = Field(default_factory=list,
41-
description="The list of tools MCP server will expose (default: all tools)")
40+
tool_names: list[str] = Field(
41+
default_factory=list,
42+
description="The list of tools MCP server will expose (default: all tools)."
43+
"Tool names can be functions or function groups",
44+
)
4245
transport: Literal["sse", "streamable-http"] = Field(
4346
default="streamable-http",
4447
description="Transport type for the MCP server (default: streamable-http, backwards compatible with sse)")

src/nat/front_ends/mcp/mcp_front_end_plugin_worker.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ async def add_routes(self, mcp: FastMCP, builder: WorkflowBuilder):
234234
filtered_functions: dict[str, Function] = {}
235235
for function_name, function in functions.items():
236236
if function_name in self.front_end_config.tool_names:
237+
# Treat current tool_names as function names, so check if the function name is in the list
238+
filtered_functions[function_name] = function
239+
elif any(function_name.startswith(f"{group_name}.") for group_name in self.front_end_config.tool_names):
240+
# Treat tool_names as function group names, so check if the function name starts with the group name
237241
filtered_functions[function_name] = function
238242
else:
239243
logger.debug("Skipping function %s as it's not in tool_names", function_name)

0 commit comments

Comments
 (0)