Please help fix my mcp client error!
I have a simple mcp server setup with streamable http.
mcp server:
mcp = FastMCP(
name="example server",
host="127.0.0.1",
port=8000
)
if __name__ == "__main__":
mcp.run(transport="streamable-http")
Also I have created a client to connect to the server.
client:
SERVER_URL = "http://127.0.0.1:8050"
async def connect_to_server(server_url: str):
async with streamablehttp_client(url=f"{server_url}") as streams:
async with ClientSession(*streams) as session:
await session.initialize()
tools = await session.list_tools()
Then I get the following error:
AttributeError("'function' object has no attribute 'total_seconds'") [single exception in ExceptionGroup]
Additional information: My pytest is setup to run the server as a sub process, then call the client like below, but I'm not convinced this is relevant.
@pytest.fixture(scope="module")
def start_mcp_server():
print("Starting mcp server as a separate process ...")
proc = subprocess.Popen(
["python", "apps/server/runtime/server.py"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
preexec_fn=os.setsid,
cwd=BASE_DIR,
env=env,
)
try:
wait_for_server(f"{SERVER_URL}", timeout=5)
yield proc
finally:
try:
os.killpg(os.getpgid(proc.pid), signal.SIGTERM)
except ProcessLookupError:
pass
@pytest.mark.asyncio
async def test_mcp_server_profile_and_tools(start_mcp_server):
tools, profile = await connect_to_server(SERVER_URL)