Skip to content

Exception raised when a nullable parameter is sent as an empty string in the Http request #601

Description

@aschabus

I have an MCP server that uses nullable types for its parameters. For example:

[McpServerTool(Name="get_data"),Description("Get data from the store")]publicasyncTask<IEnumerable<ResponseType>>GetData([Description("Number of records to return")]int?limit=null,[Description("Start date")]DateTime?from=null,

When I use streamable HTTP (for example, via MCP Inspector), the data is sent as an empty string, like this:

"arguments":{ "limit": null, "from":"2025-01-01"}

When I compile this with ModelContextProtocol and ModelContextProtocol.AspNetCore version "0.1.0-preview.12", everything works as expected. However, if I use version "0.2.0-preview.3", I get the following Exception:

System.Text.Json.JsonException: The JSON value could not be converted to System.Nullable`1[System.DateTime]

How can I get this working?

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions