modelcontextprotocol / modelcontextprotocol/csharp-sdk

Passing a malformed body throws a 500 error instead of 400. Very hard to figure out what is incorrect in the request being issued by the caller

Open
#788 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug help wanted needs confirmation P3
Dominant language
C#
Stars
4.5k
Forks
814
Avg merge
9d 19h
Merged PRs (30d)
4

Description

Description
When sending an InitializeRequest to the MCP C# SDK server with a malformed or incomplete request body (e.g., missing required fields like clientInfo.Version, the server responds with a 500 Internal Server Error.
This behavior is problematic because:

  • A 500 error implies a server-side failure, not a client-side input issue.
  • According to MCP protocol expectations, the server should return a 400 Bad Request or a structured JSON-RPC error response indicating what was wrong with the request.

Steps to reproduce the behavior:

  1. Issue a POST mcp call with this request body:

{ "jsonrpc": "2.0", "id": "7", "method": "initialize", "params": { "protocolVersion": "2025-06-18", "clientInfo": { "name": "Insomnia" } } }

Expected behavior
A 400 error should be returned telling the user that the ClientInfo.Version property is missing

Additional Context
Our controllers are mapped like this in our Startup.cs file:

app.UseEndpoints(endpoints => { endpoints.MapControllers(); endpoints.MapMcp("/mcp/environments/{environmentId}/servers/{serverName}"); });
and controller is defined like this:

[HttpGet] [HttpPost] [HttpDelete] [Route("mcp/environments/{environmentId}/servers/{serverName}")] public IActionResult Invoke() { return this.Ok(); }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the MapMcp("/mcp/environments/{environmentId}/servers/{serverName}") endpoint mapping shown in Startup.cs and the controller's Invoke action. Reproduce the POST with the incomplete InitializeRequest, then trace request validation and error handling to determine where the 500 is produced. Done means the missing ClientInfo.Version is reported through a 400 response or structured JSON-RPC error.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.