Skip to content

MCP prompt string results are returned as JSON string literals #31

Description

@autocarl

Summary

Prompt handlers that return string currently surface as JSON string literals in MCP prompt text.

Reproduction

app.Map("ops troubleshoot {symptom}", static (string symptom) =>
        $"Investigate the checkout service for this symptom: '{symptom}'.")
    .WithDescription("Generate troubleshooting instructions for an agent.")
    .AsPrompt();

Call:

npx --yes @modelcontextprotocol/inspector --cli ./run-mcp.sh \
  --method prompts/get \
  --prompt-name ops_troubleshoot \
  --prompt-args symptom="queue depth rising"

Observed prompt content:

{
  "messages": [
    {
      "role": "user",
      "content": {
        "type": "text",
        "text": "\"Investigate the checkout service for this symptom: \\u0027queue depth rising\\u0027. Start with ops_status, inspect failed checks, then propose the smallest safe next step.\""
      }
    }
  ]
}

The text contains the serialized JSON string, including extra quotes and escapes.

Expected behavior

Prompt text should be plain text, e.g.:

Investigate the checkout service for this symptom: 'queue depth rising'. Start with ops_status, inspect failed checks, then propose the smallest safe next step.

Likely cause

McpToolAdapter forces --output:json for MCP command execution. When a Repl handler returns a string, the CLI output is a JSON string literal. ReplMcpServerPrompt.GetAsync() then forwards that text directly into TextContentBlock.

There is already a similar unwrapping pattern for MCP App UI resources (ReplMcpServerUiResource.UnwrapJsonString). Prompts may need equivalent handling, or prompt execution may need a prompt-specific output path.

Environment observed

  • Repl.Mcp: 0.11.0-dev.56
  • .NET SDK: 10.0.301
  • OS: Ubuntu 24.04 linux-x64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions