From ba06c3ef90abf89fa4ddbec9f81c2c08d2af1273 Mon Sep 17 00:00:00 2001 From: Sid Murching Date: Wed, 7 May 2025 12:09:53 -0700 Subject: [PATCH 1/2] POC: deploy a streamable HTTP server on Databricks apps and connect to it from the client Signed-off-by: Sid Murching --- .../simple-streamablehttp/pyproject.toml | 5 ++++- src/mcp/shared/session.py | 2 +- tests/shared/test_streamable_http.py | 21 ++++++++++++------- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/examples/servers/simple-streamablehttp/pyproject.toml b/examples/servers/simple-streamablehttp/pyproject.toml index c35887d1fd..e8059dc5c3 100644 --- a/examples/servers/simple-streamablehttp/pyproject.toml +++ b/examples/servers/simple-streamablehttp/pyproject.toml @@ -1,3 +1,6 @@ +[tool.hatch.metadata] +allow-direct-references = true + [project] name = "mcp-simple-streamablehttp" version = "0.1.0" @@ -7,7 +10,7 @@ requires-python = ">=3.10" authors = [{ name = "Anthropic, PBC." }] keywords = ["mcp", "llm", "automation", "web", "fetch", "http", "streamable"] license = { text = "MIT" } -dependencies = ["anyio>=4.5", "click>=8.1.0", "httpx>=0.27", "mcp", "starlette", "uvicorn"] +dependencies = ["anyio>=4.5", "click>=8.1.0", "httpx>=0.27", "mcp @ git+https://github.com/modelcontextprotocol/python-sdk.git@main", "starlette", "uvicorn"] [project.scripts] mcp-simple-streamablehttp = "mcp_simple_streamablehttp.server:main" diff --git a/src/mcp/shared/session.py b/src/mcp/shared/session.py index cce8b1184e..2c582d44de 100644 --- a/src/mcp/shared/session.py +++ b/src/mcp/shared/session.py @@ -248,7 +248,7 @@ async def send_request( ) # request read timeout takes precedence over session read timeout - timeout = None + timeout = 10 if request_read_timeout_seconds is not None: timeout = request_read_timeout_seconds.total_seconds() elif self._session_read_timeout_seconds is not None: diff --git a/tests/shared/test_streamable_http.py b/tests/shared/test_streamable_http.py index b1dc7ea338..25b5b4861f 100644 --- a/tests/shared/test_streamable_http.py +++ b/tests/shared/test_streamable_http.py @@ -439,7 +439,10 @@ def json_response_server(json_server_port: int) -> Generator[None, None, None]: @pytest.fixture def basic_server_url(basic_server_port: int) -> str: """Get the URL for the basic test server.""" - return f"http://127.0.0.1:{basic_server_port}" + # TODO(smurching) update this to point to the Databricks apps URL + res = f"https://unity-catalog-mcp-1444828305810485.aws.databricksapps.com" + print("basic_server_url", res) + return res @pytest.fixture @@ -776,7 +779,8 @@ async def http_client(basic_server, basic_server_url): @pytest.fixture async def initialized_client_session(basic_server, basic_server_url): """Create initialized StreamableHTTP client session.""" - async with streamablehttp_client(f"{basic_server_url}/mcp") as ( + token = "TODO add token here" + async with streamablehttp_client(url=f"{basic_server_url}/mcp/", headers={'Authorization': f'Bearer {token}'}) as ( read_stream, write_stream, _, @@ -823,14 +827,15 @@ async def test_streamablehttp_client_tool_invocation(initialized_client_session) """Test client tool invocation.""" # First list tools tools = await initialized_client_session.list_tools() - assert len(tools.tools) == 3 - assert tools.tools[0].name == "test_tool" + assert len(tools.tools) == 1 + assert tools.tools[0].name == "start-notification-stream" # Call the tool - result = await initialized_client_session.call_tool("test_tool", {}) - assert len(result.content) == 1 - assert result.content[0].type == "text" - assert result.content[0].text == "Called test_tool" + result = await initialized_client_session.call_tool("start-notification-stream", {"interval": 1.0, "count": 5, "caller": "test-caller"}) + assert len(result.content) == 1, result.content + + # assert result.content[0].type == "text" + # assert result.content[0].text == "Called test_tool" @pytest.mark.anyio From 263aed9f409d964048a639014e4f7bb3ed67ca0e Mon Sep 17 00:00:00 2001 From: Sid Murching Date: Wed, 7 May 2025 12:13:19 -0700 Subject: [PATCH 2/2] Add untracked files Signed-off-by: Sid Murching --- examples/servers/simple-streamablehttp/app.yaml | 9 +++++++++ examples/servers/simple-streamablehttp/requirements.txt | 1 + 2 files changed, 10 insertions(+) create mode 100644 examples/servers/simple-streamablehttp/app.yaml create mode 100644 examples/servers/simple-streamablehttp/requirements.txt diff --git a/examples/servers/simple-streamablehttp/app.yaml b/examples/servers/simple-streamablehttp/app.yaml new file mode 100644 index 0000000000..53a07bfa92 --- /dev/null +++ b/examples/servers/simple-streamablehttp/app.yaml @@ -0,0 +1,9 @@ +command: [ + "uv", + "run", + "mcp-simple-streamablehttp", + "--port", + "8000", + "--log-level", + "DEBUG" +] diff --git a/examples/servers/simple-streamablehttp/requirements.txt b/examples/servers/simple-streamablehttp/requirements.txt new file mode 100644 index 0000000000..60cc5e6a1a --- /dev/null +++ b/examples/servers/simple-streamablehttp/requirements.txt @@ -0,0 +1 @@ +uv