You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
McpServerTool returns garbage BigInteger value #2052
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;
}
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.
Activity
aftabkh4n commentedon Nov 29, 2026
The root cause is that
System.Text.Jsonhas no built-inBigIntegersupport, even on .NET 10. It serializes the public properties, and it can't deserialize123into aBigInteger(JsonException).McpJsonUtilities.DefaultOptionsdoesn't add a converter for it, so the SDK inherits that behavior in three places:BigIntegerproduces{"isPowerOfTwo":false,"isZero":false,"isOne":false,"isEven":false,"sign":1}, as reported.outputSchema(withUseStructuredContent = true): advertised as{"type":"object","properties":{"isPowerOfTwo":{"type":"boolean"},...,"sign":{"type":"integer"}}}.BigIntegerparameter is advertised ininputSchemaas 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
mainwithMcpServerTool.Createon .NET 10.Workaround for now: pass your own
JsonSerializerOptionswith aBigIntegerconverter, or return/acceptstring.Would you accept a PR that adds a
BigIntegerconverter toMcpJsonUtilities.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.