Skip to content

ClosedResourceError when using FastMCP(..., stateless_http=True, json_response=True) with MCP Inspector #1658

@yabramow

Description

@yabramow

Initial Checks

Description

Summary

Running the example MCP server fastmcp_quickstart.py with:
FastMCP("Demo", stateless_http=True, json_response=True)
and connecting to it using MCP Inspector triggers an exception inside the server’s message router:
ClosedResourceError

This occurs immediately after the Inspector connects.

Steps to Reproduce

  1. Use the example server from the Python MCP SDK:
    uv run --with mcp examples/snippets/servers/fastmcp_quickstart.py
  2. Ensure the server instance is initialized as:
    FastMCP("Demo", stateless_http=True, json_response=True)
  3. Open MCP Inspector and connect to this server.
  4. Observe the server error.

Environment

  • MCP Python SDK version: latest
  • Python version: 3.13
  • OS: macOS (Apple Silicon)
  • MCP Inspector version: latest

Example Code

"""
FastMCP quickstart example.

Run from the repository root:
    uv run examples/snippets/servers/fastmcp_quickstart.py
"""

from mcp.server.fastmcp import FastMCP

# Create an MCP server
mcp = FastMCP("Demo", stateless_http=True, json_response=True)


# Add an addition tool
@mcp.tool()
def add(a: int, b: int) -> int:
    """Add two numbers"""
    return a + b


# Add a dynamic greeting resource
@mcp.resource("greeting://{name}")
def get_greeting(name: str) -> str:
    """Get a personalized greeting"""
    return f"Hello, {name}!"


# Add a prompt
@mcp.prompt()
def greet_user(name: str, style: str = "friendly") -> str:
    """Generate a greeting prompt"""
    styles = {
        "friendly": "Please write a warm, friendly greeting",
        "formal": "Please write a formal, professional greeting",
        "casual": "Please write a casual, relaxed greeting",
    }

    return f"{styles.get(style, styles['friendly'])} for someone named {name}."


# Run with streamable HTTP transport
if __name__ == "__main__":
    mcp.run(transport="streamable-http")

Python & MCP Python SDK

Python: 3.13
MCP Python SDK: 1.22.1.dev4+b19fa6f

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions