Skip to content

[BUG] [MCPClient] AIFunction arguments of complex types are passed as string representation of #558

Open
@SGStino

Description

@SGStino

Describe the bug
For an MCP function with complex arguments, the json serialization doesn't match the required jsonschema of the server when called through a KernelFunction of SemanticKernel.

To Reproduce
Steps to reproduce the behavior:

  1. create an MCP function:
(TodoListItems values, string scope) => "success"
public record TodoListItems(string[] Items);
  1. Use that function in semantic kernel like in the sample:
    https://github.com/microsoft/semantic-kernel/blob/fac316e7dc2cd7dabbaab0ee899c04187c301093/dotnet/samples/Demos/ModelContextProtocolClientServer/MCPClient/Samples/MCPToolsSample.cs#L42

  2. Let the model call the KernelFunction, which calls the AIFunction, which forwards it to the MCP client and passes the following along to the MCP server

"{\"items\":[\"todo1\", \"todo2\"]}"

And that obviously doesn't end well.

Expected behavior
It should pass:

{"items":["todo1", "todo2"]}

Logs
N/A

Additional context
AIFunction itself also presents the same issue: dotnet/extensions#6544

I'm honestly not sure if it goes wrong in SemanticKernel that should already deserialize it (since the Ollama client sends even a JsonElement along to the KernelFunction argument instead of a string like in the OpenAI client)

Or if it's something wrong in AIFunction, or in the MCP Client.

What's the design requirement around the AIFunction/KernelFunction? Since both seem to be implemented differently and packed around themselves.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions