Gemini API Tool Output Is Not MCP Schema Compliant

Hi,

Gemini is returning invalid tool call output that does not follow the MCP schema.

Below is the example

Our MCP tool schema is

{
  "name": "support",
  "inputSchema": {
    "type": "object",
    "properties": {
      "action": {
        "type": "string",
        "enum": ["fill_form"]
      },
      "data": {
        "type": "object",
        "description": "Data to fill in Support form",
        "properties": {
          "Support": {
            "type": "object",
            "properties": {
              "What problem are you facing ?": {
                "type": "string"
              }
            },
            "required": []
          }
        },
        "required": []
      }
    },
    "required": ["action"]
  },
  "description": "Contact form. Fills Support form with the data you provide."
}

Tool call output is

"Support": {
  "What_problem_are_you_facing_": "in my website image is not loading"
}

The expected key is “What problem are you facing ?”, as defined in the schema, but we received “What_problem_are_you_facing_”.

Hi @Senthil_Kumar ,

I would suggest modifying the prompt till you get the required output or else you can use a custom piece of code that will replace underscores to spaces. Please refer below code.
import json

s = ‘{“Support”: {“What_problem_are_you_facing_”: “image not loading”}}’

data = json.loads(s)
data[“Support”] = {k.replace(“_”, " "): v for k, v in data[“Support”].items()}

Thank you

Hi Akash,
We already use a fuzzy match (str.replace(/[^\w\s_]/gi, ' ').trim().toLowerCase().replace(/\s+/g, '_')), but Gemini adds or removes other characters (not just underscores) unpredictably. More importantly, if I declare a field in the tool call as required, Gemini sometimes generates an incorrect field name, causing schema validation to fail.

We really like Gemini’s multimodality, but its schema adherence needs to match OpenAI’s for us to migrate easily.

Thanks,
Mani