Skip to content

Python: Normalize MCP function names to allowed tool calling values. Add tests. #12420

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

Merged
merged 1 commit into from
Jun 9, 2025

Conversation

moonbox3
Copy link
Contributor

@moonbox3 moonbox3 commented Jun 9, 2025

Motivation and Context

When using some MCP plugins, the tool names or prompt names may contain invalid chars that cause function calling to throw a 400. The following is such a case:

async with MCPStdioPlugin(
        name="nasa",
        description="nasa Plugin",
        command="docker",
        args=["run","-i","--rm","ghcr.io/metorial/mcp-container--programcomputer--nasa-mcp-server--nasa-mcp-server","npm run start"]
    ) as nasa_plugin:
        agent = ChatCompletionAgent(
            service=AzureChatCompletion(),
            name="NasaAgent",
            instructions="Answer questions about Nasa.",
            plugins=[nasa_plugin],
        )

Some prompt tools with that MCP server contain / (forward slashes), which cause the OpenAI model to throw a 400 due to a failed regex.

prompt_list.prompts
Prompt(name='nasa/get-astronomy-picture', description="Fetch NASA's Astronomy Picture...nail for video content', required=False)]), 
Prompt(name='nasa/browse-near-earth-objects', description='Find near-Earth asteroids ...rch (YYYY-MM-DD format)', required=True)]),
...

We will introduce name normalization when we're loading the kernel functions, and replace any non-allowed values with a hyphen (-). This then allows to be called successfully.

Description

Contribution Checklist

@moonbox3 moonbox3 self-assigned this Jun 9, 2025
@moonbox3 moonbox3 requested a review from a team as a code owner June 9, 2025 07:35
@moonbox3 moonbox3 added the core plugin Anything related to core plugins label Jun 9, 2025
@markwallace-microsoft markwallace-microsoft added the python Pull requests for the Python Semantic Kernel label Jun 9, 2025
@markwallace-microsoft
Copy link
Member

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
connectors
   mcp.py38718751%74, 86, 94–97, 99–100, 105, 117–122, 130–134, 136–137, 139, 146–148, 235–237, 252–253, 256–257, 269–270, 274–275, 277, 279, 281–287, 291–293, 295–305, 309–310, 314–315, 319, 321, 325–326, 330, 344, 359–367, 373–374, 376–377, 380–381, 387–388, 408–409, 412–413, 416–421, 425–426, 429–430, 433–439, 448–450, 530, 532, 599, 601, 603, 605, 674, 676, 678, 680, 682, 740, 783–788, 790–793, 798, 851, 853, 856, 869, 889–891, 896–905, 907, 911–912, 914, 917–918, 927–928, 930–932, 946–947, 949–950, 952–954, 957, 964–967, 975, 980–985, 990, 992, 995–998
TOTAL27112462082% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3626 22 💤 0 ❌ 0 🔥 1m 56s ⏱️

@TaoChenOSU TaoChenOSU added this pull request to the merge queue Jun 9, 2025
Merged via the queue into microsoft:main with commit 32d7fa1 Jun 9, 2025
32 checks passed
@github-project-automation github-project-automation bot moved this to Sprint: Done in Semantic Kernel Jun 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core plugin Anything related to core plugins python Pull requests for the Python Semantic Kernel
Projects
Status: Sprint: Done
Development

Successfully merging this pull request may close these issues.

Python: Bug: MCP error calling Nasa MCP server
4 participants