python-sdk icon indicating copy to clipboard operation
python-sdk copied to clipboard

307 Temporary Redirect

Open 2495710777 opened this issue 7 months ago • 6 comments

INFO: 127.0.0.1:56991 - "POST /mcp HTTP/1.1" 307 Temporary Redirect INFO: 127.0.0.1:56991 - "POST /mcp/ HTTP/1.1" 200 OK

After using mcp.run(transport="streamable-http") to start the server, why does the client always redirect to '/mcp/' when requesting the server?

2495710777 avatar May 16 '25 09:05 2495710777

same issue.

ch-xhr avatar May 19 '25 14:05 ch-xhr

same

zhouguangming avatar May 20 '25 11:05 zhouguangming

http://localhost/mcp => http://localhost/mcp/

nightzjp avatar May 21 '25 01:05 nightzjp

set your streamable_http_path='/mcp/'

chi2liu avatar May 22 '25 08:05 chi2liu

#781

chi2liu avatar May 22 '25 09:05 chi2liu

hey, it took me a while to figure this out, I even raised an issue!

thanks everyone for your help!

jbovet avatar May 23 '25 15:05 jbovet

It is the issue of fastapi. May close in this project.

tobegit3hub avatar Jun 10 '25 07:06 tobegit3hub

Just to share code, the following results in those errors:

streamablehttp_client("http://myserver.com/mcp")

whereas this resolves them:

streamablehttp_client("http://myserver.com/mcp/")

It appears that the streamable_http_client cannot handle the redirect, and when we use Starlette/FastAPI, /mcp gets turned into /mcp/, so we need to give the direct route of /mcp.

Perhaps streamable_http_client could add redirect handling? But not all clients will handle it (see VS Code issue).

pamelafox avatar Jul 09 '25 18:07 pamelafox