Skip to content

.Net: Bug: Function calling using MCP not using JsonSerializerOptions #12529

Open
@carlos-ferreira

Description

@carlos-ferreira

Describe the bug
Function calling using MCP is not using the specified JsonSerializerOptions, and it's breaking the json being sent to MCP servers.

To Reproduce
Steps to reproduce the behavior:

  1. Clone https://github.com/carlos-ferreira/SemanticKernel.MCP.BrokenJson and open the project in Visual Studio
  2. Set your API key for OpenAI.
  3. Run the console app.
  4. Look at the immediate window
  5. You'll notice json being sent via when the edit_tool is called that is not a valid json, something like this:
{
    "Id": "vvyRL797xP5bUSNd5zWIEEmZlZhPHFfG",
    "PluginName": "Files",
    "FunctionName": "edit_file",
    "Arguments": {
        "path": "D:\\AI\\Instructions\\Journals\\tasklist.md",
        "edits": [{\u0022oldText\u0022:\u0022- Go to the bank \u0022,\u0022newText\u0022:\u0022- [ ] Go to the bank \\n\u0022},{\u0022oldText\u0022:\u0022 Send daily standup email\u0022,\u0022newText\u0022:\u0022 - [ ] Send daily standup email\\n\u0022}],
        "dryRun": false
    }
}

Expected behavior
The edit_tool tool calls should produce json, similar to this one:

{
    "Id": "vvyRL797xP5bUSNd5zWIEEmZlZhPHFfG",
    "PluginName": "Files",
    "FunctionName": "edit_file",
    "Arguments": {
        "path": "D:\\AI\\Instructions\\Journals\\tasklist.md",
        "edits": [{"oldText":"- Go to the bank ","newText":"- [ ] Go to the bank \\n"},{"oldText":" Send daily standup email","newText":" - [ ] Send daily standup email\\n"}],
        "dryRun": false
    }
}

Screenshots

Image

Platform

  • Language: C#
  • Source: NuGet package version 1.57.0, ModelContextProtocol 0.0.1-preview-17
  • AI model: gpt-4o-mini
  • IDE: Visual Studio 2022
  • OS: Windows 11 Pro fully updated.

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