Skip to content

Python: MCPStreamableHTTPTool - ClosedResourceError when connecting to databricks genie MCP #2708

@vikash15k

Description

@vikash15k

When I try to call databricks genie MCP server using MCPStreamableHTTPTool , the first call is processed correctly and second call onwards I get below error , I tried to find the solution , some suggest that the streaming is getting closed after first call and so agent is not able to connect to mcp .

code Snippet below-

agent = client.create_agent(
name=_agent_name(),
description="Agent used for Chat With Data",
instructions=AGENT_INSTRUCTIONS,
allow_multiple_tool_calls=True,
tools=[
MCPStreamableHTTPTool(
name="Databricks Genie MCP Chat With Data",
description="Translate natural language to SQL & execute on Databricks",
url=f"https://{databricks_server}/api/2.0/mcp/genie/{genie_space_id}",
headers={"Authorization": f"Bearer {databricks_pat}"},
),
],
additional_chat_options={
"reasoning": {"effort": "low"},
"text": {"verbosity": "low"},
}
)

Traceback (most recent call last):
File "cwd\iac-aid-customer-service\chat-with-data\backend.venv\Lib\site-packages\agent_framework_mcp.py", line 644, in call_tool
return _mcp_call_tool_result_to_ai_contents(await self.session.call_tool(tool_name, arguments=kwargs))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "cwd\iac-aid-customer-service\chat-with-data\backend.venv\Lib\site-packages\mcp\client\session.py", line 334, in call_tool
result = await self.send_request(
^^^^^^^^^^^^^^^^^^^^^^^^
...<11 lines>...
)
^
File "cwd\iac-aid-customer-service\chat-with-data\backend.venv\Lib\site-packages\mcp\shared\session.py", line 261, in send_request
await self._write_stream.send(SessionMessage(message=JSONRPCMessage(jsonrpc_request), metadata=metadata))
File "cwd\iac-aid-customer-service\chat-with-data\backend.venv\Lib\site-packages\anyio\streams\memory.py", line 243, in send
self.send_nowait(item)
~~~~~~~~~~~~~~~~^^^^^^
File "\cwd\iac-aid-customer-service\chat-with-data\backend.venv\Lib\site-packages\anyio\streams\memory.py", line 212, in send_nowait
raise ClosedResourceError
anyio.ClosedResourceError

Metadata

Metadata

Assignees

Labels

model context protocolIssue related to Model Context Protocolpythonv1.0Features being tracked for the version 1.0 GA

Type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions