502 while using localhost sse #3483
-
|
** Please make sure you read the contribution guide and file the issues in the right place. ** Describe the bug Try to connect to localhost sse mcp server but got 502 To Reproduce
import datetime
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("real-fastmcp-server", port=9999)
@mcp.tool()
def echo(text: str) -> str:
"""
Echo back input text with timestamp
Args:
text: input text
Returns:
str: input text with timestamp
"""
timestamp = datetime.datetime.now().isoformat()
return f"[{timestamp}] Echo: {text}"
if __name__ == "__main__":
mcp.run(transport='sse')
import asyncio
from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset, SseConnectionParams
async def main():
connection_params = SseConnectionParams(url="http://localhost:9999/sse")
toolset = MCPToolset(connection_params=connection_params)
tools = await toolset.get_tools()
if __name__ == "__main__":
asyncio.run(main())
Expected behavior Screenshots Desktop (please complete the following information):
Model Information: Additional context |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
|
Please provide complete error trace to see which classes throws the error. |
Beta Was this translation helpful? Give feedback.
-
|
This should be fixed or it's not related to ADK. Moving to discussion to get some help from adk-bot. |
Beta Was this translation helpful? Give feedback.
-
|
Response from ADK Answering Agent (experimental, answer may be inaccurate) TLDR: The Hello! I'm an agent designed to help with ADK questions. I've analyzed your discussion, and it seems you've run into a platform-specific issue when running the A Your client-side code for connecting with Proposed SolutionInstead of using Please try modifying your server script as follows:
# ... (keep the rest of your server code the same: imports, mcp object, and @mcp.tool)
import uvicorn
if __name__ == "__main__":
# The mcp.run() method can sometimes have issues on certain platforms.
# Using uvicorn directly is a more standard and stable way to run an ASGI app.
# The 'mcp' object itself is the application to be run.
# We must, however, ensure the SSE transport is configured, which mcp.run() was doing.
# The FastMCP object takes a `transport` argument in its run() method to set up
# the correct routes (like '/sse'). By bypassing run(), these routes might not be created.
# The most robust way to both configure the transport and run the server is to do it explicitly.
# A reliable pattern is to run the server from the command line, which is a common practice shown
# in ADK and MCP documentation. This separates the app definition from the run command.
# Please try this code modification:
mcp.setup_sse()
uvicorn.run(mcp, host="127.0.0.1", port=9999)If the above does not work (e.g., if there is an error about
This command tells |
Beta Was this translation helpful? Give feedback.
Response from ADK Answering Agent (experimental, answer may be inaccurate)
TLDR: The
502 Bad Gatewayerror likely stems from an issue with how themcp.run()convenience method starts the server on your Windows environment. The recommended solution is to run the server directly using theuvicornlibrary, which is more robust.Hello! I'm an agent designed to help with ADK questions. I've analyzed your discussion, and it seems you've run into a platform-specific issue when running the
FastMCPserver.A
502 Bad Gatewayerror in this scenario—where there is no separate proxy—typically indicates that the server application itself failed to start up or handle the request correctly. This can som…