-
Notifications
You must be signed in to change notification settings - Fork 597
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
I always see System.Text.Json.JsonException: The input does not contain any JSON tokens when I use MCP client (c#). Then it's restarted and result is returned, but it would be good to avoid initial failure.
To Reproduce
Steps to reproduce the behavior:
-
Create MCP client
var transport = new SseClientTransport( new SseClientTransportOptions { Endpoint = new Uri(_mcpConfig.Endpoint), Name = name }, loggerFactory: _loggerFactory, httpClient: _httpClient, ownsHttpClient: false); return await McpClientFactory.CreateAsync(transport, cancellationToken: cancellationToken);
where httpClient is created:
services
.AddHttpClient<McpHttpClient>()
.AddPolicyHandler(s => McpHttpClient.GetRetryPolicy());
public static IAsyncPolicy<HttpResponseMessage> GetRetryPolicy()
{
return HttpPolicyExtensions
.HandleTransientHttpError() // Handles 5xx and 408 (Request Timeout)
.OrResult(response => !response.IsSuccessStatusCode && (int)response.StatusCode >= 500)
.WaitAndRetryAsync(
retryCount: 2,
sleepDurationProvider: attempt => TimeSpan.FromMilliseconds(500 * attempt));
}
-
Initialize MCP tools in Semantic Kernel
kernel.Plugins.AddFromFunctions( pluginName: PluginName, description: serverInstructions, functions: tools.Select(t => t.AsKernelFunction())); -
Allow model to call MCP tool
Expected behavior
MCP tool is called without errors
Logs
[2026-01-07 22:00:52.350] The maximum limit of 0 auto invocations per user request has been reached. Auto invocation is now disabled., Exception:<no exception>
[2026-01-07 22:00:52.351] Initializing MCP client with endpoint: https://REMOTE_ADDRESS/mcp/, Exception:<no exception>
[2026-01-07 22:00:52.351] MCP_NAME attempting to connect using Streamable HTTP transport., Exception:<no exception>
[2026-01-07 22:00:52.351] Start processing HTTP request POST https://REMOTE_ADDRESS/mcp/, Exception:<no exception>
[2026-01-07 22:00:52.351] Sending HTTP request POST https://REMOTE_ADDRESS/mcp/, Exception:<no exception>
[2026-01-07 22:00:52.422] Received HTTP response headers after 71.2331ms - 200, Exception:<no exception>
[2026-01-07 22:00:52.422] End processing HTTP request after 71.4301ms - 200, Exception:<no exception>
[2026-01-07 22:00:52.422] MCP_NAME transport received message with ID '1'., Exception:<no exception>
[2026-01-07 22:00:52.423] Start processing HTTP request GET https://REMOTE_ADDRESS/mcp/, Exception:<no exception>
[2026-01-07 22:00:52.423] Sending HTTP request GET https://REMOTE_ADDRESS/mcp/, Exception:<no exception>
[2026-01-07 22:00:52.423] MCP_NAME using Streamable HTTP transport., Exception:<no exception>
[2026-01-07 22:00:52.423] Start processing HTTP request POST https://REMOTE_ADDRESS/mcp/, Exception:<no exception>
[2026-01-07 22:00:52.424] Sending HTTP request POST https://REMOTE_ADDRESS/mcp/, Exception:<no exception>
[2026-01-07 22:00:52.426] Received HTTP response headers after 3.023ms - 200, Exception:<no exception>
[2026-01-07 22:00:52.426] End processing HTTP request after 3.3766ms - 200, Exception:<no exception>
[2026-01-07 22:00:52.486] Received HTTP response headers after 62.7538ms - 202, Exception:<no exception>
[2026-01-07 22:00:52.486] End processing HTTP request after 62.931ms - 202, Exception:<no exception>
[2026-01-07 22:00:52.487] MCP_NAME transport message parsing failed., Exception:System.Text.Json.JsonException: The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0.
---> System.Text.Json.JsonReaderException: The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. LineNumber: 0 | BytePositionInLine: 0.
at System.Text.Json.ThrowHelper.ThrowJsonReaderException(Utf8JsonReader& json, ExceptionResource resource, Byte nextByte, ReadOnlySpan`1 bytes)
at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
--- End of inner exception stack trace ---
at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, JsonReaderException ex)
at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 json, JsonTypeInfo`1 jsonTypeInfo)
at ModelContextProtocol.Client.StreamableHttpClientSessionTransport.ProcessMessageAsync(String data, JsonRpcRequest relatedRpcRequest, CancellationToken cancellationToken)
[2026-01-07 22:00:52.487] Start processing HTTP request POST https://REMOTE_ADDRESS/mcp/, Exception:<no exception>
[2026-01-07 22:00:52.487] Sending HTTP request POST https://REMOTE_ADDRESS/mcp/, Exception:<no exception>
[2026-01-07 22:00:52.491] Received HTTP response headers after 3.454ms - 200, Exception:<no exception>
[2026-01-07 22:00:52.491] End processing HTTP request after 3.5049ms - 200, Exception:<no exception>
[2026-01-07 22:00:52.492] MCP_NAME transport received message with ID '2'., Exception:<no exception>
Additional context
nuget: ModelContextProtocol, v0.3.0-preview.4
UPDATE: just checked, the same behavior happens with versions:
- 0.4.1-preview.1
- 0.5.0-preview.1
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working