fastmcp icon indicating copy to clipboard operation
fastmcp copied to clipboard

server disconnected without sending a response.

Open litaolaile opened this issue 7 months ago • 2 comments

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

Image

but when i execute client.py ,it happens error :

Image

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

litaolaile avatar May 08 '25 04:05 litaolaile

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

U1S1-GCNT avatar May 08 '25 07:05 U1S1-GCNT

Got event: http.disconnect. Stop streaming

what you mean ,what should i modify the client code

litaolaile avatar May 09 '25 01:05 litaolaile