fastmcp
fastmcp copied to clipboard
server disconnected without sending a response.
Description
i use the demo in sdk,but when execute client.py,it happens error, the server i confirm it runs normally,and i check it in chrome like this
but when i execute client.py ,it happens error :
Example Code
client code below:
import asyncio
from fastmcp import Client
sse_url = "http://localhost:4200/sse"
client_inferred = Client(sse_url)
async def use_sse_client(client):
async with client:
tools = await client.list_tools()
print(f"Connected via SSE, found tools: {tools}")
asyncio.run(use_sse_client(client_inferred))
server code below:
from fastmcp import FastMCP
import asyncio
# 创建 MCP 服务器实例
mcp = FastMCP("DemoServer", dependencies=["fastmcp"])
# 定义一个简单的工具
@mcp.tool()
def add_numbers(a: int, b: int) -> int:
"""Add two numbers and return the result."""
return a + b
# 定义一个异步工具
@mcp.tool()
async def get_time() -> str:
"""Return the current server time."""
from datetime import datetime
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
if __name__ == "__main__":
# 运行服务器,使用 SSE 协议,监听在 4200 端口
mcp.run(transport="sse", port=4200)
Version Information
2.2.10
Additional Context
No response
2025-05-08 15:43:46,474 - DEBUG - ping: b': ping - 2025-05-08 07:43:46.474307+00:00\r\n\r\n' 2025-05-08 15:43:51,961 - DEBUG - Got event: http.disconnect. Stop streaming.
You should need to return heartbeat information in the client, but I won't return it in the client
Got event: http.disconnect. Stop streaming
what you mean ,what should i modify the client code