Skip to content

.Net: Bug: Converting MCP Tools to Kernel Function Throws System.ArgumentException #12879

@angsanley

Description

@angsanley

Describe the bug
I am adding tools to Semantic Kernel from MCP servers like this example:

IMcpClient mcpClient = await McpClientFactory.CreateAsync(
    new SseClientTransport(new SseClientTransportOptions()
    {
        Endpoint = new Uri("https://mcp.notion.com/mcp"),
        TransportMode = HttpTransportMode.StreamableHttp,
        AdditionalHeaders = new Dictionary<string, string>
        {
            { "Authorization", $"Bearer {token}" }
        }
    })
);

IList<McpClientTool> tools = await mcpClient.ListToolsAsync();

kernel.Plugins.AddFromFunctions(
    tool.Name,
    tools.Select(aiFunction => aiFunction.AsKernelFunction())
);

The MCP server has tools names using dash in it, eg: create-pages

And semantic kernel throws error:

Unhandled exception. System.ArgumentException: A plugin name can contain only ASCII letters, digits, and underscores: 'create-pages' is not a valid name. (Parameter 'name')

Is this a bug or how do I work around this?

To Reproduce
Steps to reproduce the behavior:
Run the snippet above

Expected behavior
Auto convert dash to underscores maybe?

Screenshots

Platform

  • Language: C#
  • Source: NuGet package version 1.61.0
  • AI model: GPT-4o-mini
  • IDE: VS Code
  • OS: Mac

Additional context
Add any other context about the problem here.

Metadata

Metadata

Labels

.NETIssue or Pull requests regarding .NET codebugSomething isn't working

Type

Projects

Status

Bug

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions