Open
Description
Describe the bug
When attempting to return a GetPromptResult
from a GetPromptHandler
, the Role
field on the PromptMessage
type serializes with an uppercase enum value, while tools like Claude and the MCP Inspector expect a lowercase value only.
To Reproduce
Steps to reproduce the behavior:
- Use the following sample program:
using ModelContextProtocol;
using Microsoft.Extensions.Hosting;
using ModelContextProtocol.Protocol.Types;
var builder = Host.CreateApplicationBuilder(args);
builder.Services
.AddMcpServer()
.WithStdioServerTransport()
.WithListPromptsHandler((ctx, ctok) => Task.FromResult(new ListPromptsResult()
{
Prompts = [new() { Name = "prompt1", Description = "Prompt 1" }]
})
)
.WithGetPromptHandler((req, ctok) =>
{
if (req.Params!.Name == "prompt1")
{
return Task.FromResult(new GetPromptResult() { Messages = [new PromptMessage() { Content = new Content() { Text = "do the thing!", Type = "text" }, Role = Role.User }] });
}
throw new Exception("Prompt not found");
});
await builder.Build().RunAsync();
- build the app with
dotnet build
- Run the MCP Inspector:
npx @modelcontextprotocol/inspector .\bin\Debug\net9.0\yourapp
- list prompts
- select the
prompt1
prompt - See the following error:
[
{
"received": "User",
"code": "invalid_enum_value",
"options": [
"user",
"assistant"
],
"path": [
"messages",
0,
"role"
],
"message": "Invalid enum value. Expected 'user' | 'assistant', received 'User'"
}
]
Expected behavior
The prompt1 prompt should have been invoked in the MCP inspector.
Logs
See above
Additional context
Pretty sure this is a classic .NET-style enum serialization problem - we need to use lowecase enum serialization. I think we can do that with a naming policy on the Role type specifically?