Skip to content

mcp server raising misdirected request (421 HTTP code) in Linux/AIX on Power #1626

@KamathForAIX

Description

@KamathForAIX

Hi everyone,

We were experimenting with having MCP servers run on the Linux and AIX operating systems on the POWER platform.

Our MCP Server and MCP client will be remote and are different nodes for this experiment.

We used examples from the community.

Our server code

import contextlib

from starlette.applications import Starlette
from starlette.routing import Mount

from mcp.server.fastmcp import FastMCP

# Create the Echo server
echo_mcp = FastMCP(name="EchoServer", stateless_http=True, json_response=True)


@echo_mcp.tool()
def echo(message: str) -> str:
    """A simple echo tool"""
    return f"Echo: {message}"


# Create the Math server
math_mcp = FastMCP(name="MathServer", stateless_http=True, json_response=True)


@math_mcp.tool()
def add_two(n: int) -> int:
    """Tool to add two to the input"""
    return n + 2


# Create a combined lifespan to manage both session managers
@contextlib.asynccontextmanager
async def lifespan(app: Starlette):
    async with contextlib.AsyncExitStack() as stack:
        await stack.enter_async_context(echo_mcp.session_manager.run())
        await stack.enter_async_context(math_mcp.session_manager.run())
        yield


# Create the Starlette app and mount the MCP servers
app = Starlette(
    routes=[
        Mount("/echo", echo_mcp.streamable_http_app()),
        Mount("/math", math_mcp.streamable_http_app()),
    ],
    lifespan=lifespan,
)

Our client code:

import asyncio
import logging

from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client

async def main():
    """Main function to run the MCP client"""
    SERVER_URL = "http://server.com:8000/echo/mcp"
    async with streamablehttp_client(SERVER_URL) as (
        read_stream,
        write_stream,
        _,
    ):
        # Create a session using the client streams
        async with ClientSession(read_stream, write_stream) as session:
        #    # Initialize the connection
            await session.initialize()
            # List available tools
            tools_list = await session.list_tools()
            print("Available tools:", ", ".join(tool.name for tool in tools_list.tools))
            # Call a tool
            tool_result = await session.call_tool("echo", arguments={"message": "San Francisco"})
            print("Tool result:", tool_result.content[0].text)

if __name__ == "__main__":
    logging.basicConfig(level=logging.DEBUG)
    asyncio.run(main())

We ran the server using uvicorn server:app --host 0.0.0.0 --reload

And then client as python3.12 client.py

On running them, we get in the client

# python3.12 git-client.py
DEBUG:asyncio:Using selector: PollSelector
DEBUG:mcp.client.streamable_http:Connecting to StreamableHTTP endpoint: http://aixoss1-lp5.pok.stglabs.ibm.com:8000/echo/mcp
DEBUG:mcp.client.streamable_http:Sending client message: root=JSONRPCRequest(method='initialize', params={'protocolVersion': '2025-11-25', 'capabilities': {}, 'clientInfo': {'name': 'mcp', 'version': '0.1.0'}}, jsonrpc='2.0', id=0)
DEBUG:httpcore.connection:connect_tcp.started host='aixoss1-lp5.pok.stglabs.ibm.com' port=8000 local_address=None timeout=30 socket_options=None
DEBUG:httpcore.connection:connect_tcp.complete return_value=<httpcore._backends.anyio.AnyIOStream object at 0xa0000000196c230>
DEBUG:httpcore.http11:send_request_headers.started request=<Request [b'POST']>
DEBUG:httpcore.http11:send_request_headers.complete
DEBUG:httpcore.http11:send_request_body.started request=<Request [b'POST']>
DEBUG:httpcore.http11:send_request_body.complete
DEBUG:httpcore.http11:receive_response_headers.started request=<Request [b'POST']>
DEBUG:httpcore.http11:receive_response_headers.complete return_value=(b'HTTP/1.1', 421, b'Misdirected Request', [(b'date', b'Wed, 17 Dec 2025 05:47:13 GMT'), (b'server', b'uvicorn'), (b'content-length', b'19')])
INFO:httpx:HTTP Request: POST http://aixoss1-lp5.pok.stglabs.ibm.com:8000/echo/mcp "HTTP/1.1 421 Misdirected Request"
DEBUG:httpcore.http11:response_closed.started
DEBUG:httpcore.http11:response_closed.complete

And on server logs we see,

"POST /echo/mcp HTTP/1.1" 421 Misdirected Request
                    INFO     Terminating session: None                                                                                                                          streamable_http.py:750
                    ERROR    Error in message router   
                             ClosedResourceError     

Any ideas on why? Kindly let us know. We appreciate your help.

Affected version

Version: 1.23.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions