Python: Enforce excluded_functions on MCP tool invocation path#14124
Merged
SergeyMenshykh merged 3 commits intoJun 30, 2026
Merged
Conversation
Ensure functions excluded via excluded_functions are consistently handled on both the list_tools and call_tool paths of the MCP server, returning a method-not-found error for tools that are not exposed. Also removes a leftover debug print statement. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a security/consistency gap in the Python MCP server adapter by ensuring excluded_functions is enforced not only in tool listing (list_tools) but also at invocation time (call_tool), preventing hidden kernel functions from being callable via direct client requests.
Changes:
- Compute a single
exposed_namesset from the filtered function metadata and enforce it inside the MCPcall_toolhandler (returning METHOD_NOT_FOUND for non-exposed names). - Remove a leftover debug
printfrom_call_kernel_function. - Add a unit test verifying that an excluded tool cannot be invoked and its side effects do not execute.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| python/semantic_kernel/connectors/mcp.py | Enforces excluded_functions during tool invocation and removes debug output. |
| python/tests/unit/connectors/mcp/test_mcp.py | Adds a unit test ensuring excluded tools are rejected at call time. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
eavanvalkenburg
approved these changes
Jun 30, 2026
rogerbarreto
approved these changes
Jun 30, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation and Context
The MCP server created by
create_mcp_server_from_kernel(and theKernel.as_mcp_serverwrapper) accepts anexcluded_functionsargument to keep selected kernel functions off the server. Previously this list was applied only when building the tool set advertised by thelist_toolshandler; thecall_toolhandler did not consult it and forwarded the client-supplied name straight to the kernel. As a result the set of advertised tools and the set of callable tools could diverge.Description
exposed_namesset fromfunctions_to_exposeand check it in thecall_toolhandler, returning aMETHOD_NOT_FOUNDerror for any name that is not exposed.printdebug statement in_call_kernel_function.call_toolbehavior for a non-exposed function.Contribution Checklist