@@ -1774,21 +1774,22 @@ async def health() -> Response:
17741774 @original_app .post ("/mcp" )
17751775 async def mcp_post (request : Request ) -> Response :
17761776 """
1777- Handles POST requests to the `/mcp` endpoint, forwarding JSON payloads to stdio
1777+ Handles POST requests to the `/mcp` endpoint, forwarding JSON payloads to stdio
17781778 and optionally waiting for a correlated response.
17791779
1780- The request body is expected to be a JSON object or newline-delimited JSON.
1781- If the JSON includes an "id" field, the function attempts to match it with
1780+ The request body is expected to be a JSON object or newline-delimited JSON.
1781+ If the JSON includes an "id" field, the function attempts to match it with
17821782 a response from stdio using a pubsub queue, within a timeout period.
17831783
17841784 Args:
17851785 request (Request): The incoming FastAPI request containing the JSON payload.
17861786
17871787 Returns:
1788- Response:
1789- - `200 OK` with matched JSON response if correlation succeeds.
1790- - `202 Accepted` if no matching response is received in time or for notifications.
1791- - `400 Bad Request` if the payload is not valid JSON.
1788+ Response: A FastAPI Response object.
1789+ - 200 OK with matched JSON response if correlation succeeds.
1790+ - 202 Accepted if no matching response is received in time or for notifications.
1791+ - 400 Bad Request if the payload is not valid JSON.
1792+
17921793 Example:
17931794 >>> import httpx
17941795 >>> response = httpx.post("http://localhost:8000/mcp", json={"id": 123, "method": "ping"})
0 commit comments