Skip to content

McpServerTool returns garbage BigInteger value #2052

Backlog

Description

@khteh

Describe the bug
A clear and concise description of what the bug is.

To Reproduce

    [McpServerTool, Description("Return the nth Fibonacci number.")]
    public async Task<BigInteger> Fibonacci(McpServer server, RequestContext<CallToolRequestParams> context, int n)
    {
        _logger.LogInformation($"{nameof(Fibonacci)} called with input: {n}");
        if (n < 0)
            throw new ArgumentOutOfRangeException(nameof(n));
        if (n <= 1)
            return 1;
        BigInteger a = 0, b = 1;
        for (int i = 2; i <= n; i++)
        {
            BigInteger tmp = a + b;
            a = b;
            b = tmp;
        }
        return b;
    }

Seen on Postman:

{
    "_meta": {
        "io.modelcontextprotocol/serverInfo": {
            "name": "Web.Api",
            "version": "11.0.0.0"
        }
    },
    "content": [
        {
            "type": "text",
            "text": "{\"isPowerOfTwo\":false,\"isZero\":false,\"isOne\":false,\"isEven\":false,\"sign\":1}"
        }
    ]
}

Expected behavior
A clear and concise description of what you expected to happen.

Logs
If applicable, add logs to help explain your problem.

Additional context
Add any other context about the problem here.

Activity

  1. added
    bug
    on Nov 29, 2026
  2. aftabkh4n commented on Nov 29, 2026

    @aftabkh4n

    The root cause is that System.Text.Json has no built-in BigInteger support, even on .NET 10. It serializes the public properties, and it can't deserialize 123 into a BigInteger (JsonException). McpJsonUtilities.DefaultOptions doesn't add a converter for it, so the SDK inherits that behavior in three places:

    • Result: a tool returning BigInteger produces {"isPowerOfTwo":false,"isZero":false,"isOne":false,"isEven":false,"sign":1}, as reported.
    • outputSchema (with UseStructuredContent = true): advertised as {"type":"object","properties":{"isPowerOfTwo":{"type":"boolean"},...,"sign":{"type":"integer"}}}.
    • Parameters: a BigInteger parameter is advertised in inputSchema as that same object, so a client is told to send booleans that can never bind back to a number. The tool is effectively uncallable.

    I reproduced all three against main with McpServerTool.Create on .NET 10.

    Workaround for now: pass your own JsonSerializerOptions with a BigInteger converter, or return/accept string.

    Would you accept a PR that adds a BigInteger converter to McpJsonUtilities.DefaultOptions? It would write the value as a JSON number, accept numbers and numeric strings, and produce a matching schema. If you'd rather not special-case it, and instead wait for in-box support or document the workaround, that's fine too. I'm happy to do whichever you prefer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions