You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, has anyone a functioning py example running /mcp via streamable? No matter what I do, the py does not work. Tried similar approach with ts, and there it works well. I'd rather use py so asking. Even if I create as simple server with fastmcp as possible, it does not work. Thank you in an advance 🙏🏼
Thank you, but unfortunately, it is the same as with other approaches. It does not work with the clients I use due to the redirect issue, which still occurs in the Py SDK.
"""MCP Streamable HTTP Client"""
import argparse
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"""
parser = argparse.ArgumentParser()
# If the server returns a redirect for /mcp to /mcp/, then just specify /mcp/ in the URL
parser.add_argument(
"--server", type=str, default="http://localhost:8000/mcp", help="Server hostname"
)
args = parser.parse_args()
async with streamablehttp_client(args.server) 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("suggest_hotels", arguments={"location": "San Francisco", "check_in": "2023-10-01", "check_out": "2023-10-05"})
print("Tool result:", tool_result.content[0].text)
if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG)
asyncio.run(main())
Activity
mjunaidca commentedon Jun 11, 2025
Here's a one using streamable http stateless transport in python with a simple httpx client:
https://github.com/panaversity/learn-agentic-ai/tree/main/03_ai_protocols/02_model_context_protocol/01_server_development/01_hello_mcp_server
tampiss commentedon Jun 12, 2025
Thank you, but unfortunately, it is the same as with other approaches. It does not work with the clients I use due to the redirect issue, which still occurs in the Py SDK.
INFO: 10.78.80.197:53202 - "GET /mcp HTTP/1.1" 307 Temporary Redirect
INFO: 10.78.80.197:53202 - "GET /mcp/ HTTP/1.1" 200 OK
xuzexin-hz commentedon Jun 20, 2025
Yes, whether printing mcp logs or checking other tools calling mcp, the /mcp/ address is ok. Although I don't know why the underlying layer does this
pamelafox commentedon Jul 9, 2025
This one works for me:
felixweinberger commentedon Oct 7, 2025
See above example.