Skip to content

MCP: LLMs unable to properly escape JSON passed to MCP #2549

@henrikmcgee

Description

@henrikmcgee

App Version

3.11.14

API Provider

OpenRouter

Model Used

Claude 3.7 Sonnet and others

Actual vs. Expected Behavior

Background: I have a latex syntax checker MCP to prevent the LLM from outputting invalid code.
Whenever I try to pass python or latex or whatever code to the MCP, the LLM is unable to properly escape the input.
This causes a loop and after a few attempts, roo will give up. Roo should ALWAYS escape the string and never ask the LLM to do it. Even frontier LLMs fail with properly escaping long code strings.

example of a failing MCP-call:
{
"prompt": "<input_data>
39 | \stepcounter{fragenummer}
\arabic{fragenummer}. & \multicolumn{1}{|p{12cm}|}{\raggedright #1 } & \ifthenelse{#2=1}{{
\color{blue}{X}
}}{} & \ifthenelse{#2=1}{}{
\color{blue}{X}
etc...
}

Result: Roo tried to use verify_latex with an invalid JSON argument. Retrying...

To summarize: It NEVER works whenever I pass code of non-trivial length, even with frontier LLMs. Roo needs to escape this, the LLM should never be asked to escape. Alternatively use a different method to pass data to the mcp.

Detailed Steps to Reproduce

1.) Install MCP which requires large chunks of python or latex to be passed to it.
2.) Make the LLM execute it.
3.) Stuck in loop.

Relevant API Request Output

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue - Unassigned / ActionableClear and approved. Available for contributors to pick up.bugSomething isn't workingfeature requestFeature request, not a bug

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions