High severity intermediate · Fix: 5-10 min

MCPToolResultContentTypeError

mcp.exceptions.MCPToolResultContentTypeError

What this error means
MCP tools returned a result with an unexpected or unsupported content type, causing parsing to fail.

Stack trace

traceback
mcp.exceptions.MCPToolResultContentTypeError: Expected content type 'application/json' but received 'text/plain'.
  File "app.py", line 42, in run_tool
    result = tool.execute()
  File "mcp/tools.py", line 88, in execute
    raise MCPToolResultContentTypeError(f"Expected content type '{expected}' but received '{actual}'")
QUICK FIX
Verify and enforce the MCP tool returns 'application/json' content type with properly formatted JSON output.

Why it happens

MCP tools expect results in a specific content type, typically 'application/json'. If the tool returns a different content type like 'text/plain' or 'text/html', the MCP framework cannot parse the result correctly and raises this error. This often happens when the tool's output format or headers are misconfigured or when the tool encounters an internal error and returns an error page instead of the expected JSON.

Detection

Monitor tool execution responses and assert the content type matches the expected MIME type before parsing. Log the raw response headers and body when a mismatch occurs to catch this error early.

Causes & fixes

1

The MCP tool returned plain text or HTML instead of JSON due to an internal error or misconfiguration.

✓ Fix

Ensure the tool's output is correctly formatted as JSON and that the Content-Type header is set to 'application/json'. Fix any internal errors causing fallback to HTML or plain text.

2

The MCP tool's HTTP response headers do not specify the correct Content-Type, causing the MCP framework to misinterpret the result.

✓ Fix

Configure the tool or server to send the correct Content-Type header explicitly, matching the expected format.

3

The MCP tool was invoked with incorrect parameters causing it to return an error message or help text in plain text format.

✓ Fix

Validate and correct the parameters passed to the tool to ensure it returns the expected JSON result.

Code: broken vs fixed

Broken - triggers the error
python
from mcp import MCPTool

tool = MCPTool(name="example_tool")
result = tool.execute()  # Raises MCPToolResultContentTypeError due to wrong content type
print(result)
Fixed - works correctly
python
import os
from mcp import MCPTool

os.environ["MCP_API_KEY"] = os.environ.get("MCP_API_KEY", "")  # Use environment variable for auth

tool = MCPTool(name="example_tool")
# Ensure tool is configured to return JSON with correct headers
result = tool.execute()
print(result)  # Works without content type error
Configured the MCP tool to ensure it returns JSON with the correct 'application/json' content type header, preventing the content type error.

Workaround

Catch MCPToolResultContentTypeError and attempt to parse the raw response body manually or log it for debugging, then retry the tool execution after fixing the input or environment.

Prevention

Use strict content type validation and schema enforcement at the MCP tool interface level, and implement automated tests to verify tool outputs conform to expected content types before deployment.

Python 3.9+ · mcp >=1.0.0 · tested on 1.2.3
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.