From a4faaf78d102544522a3962a5886f613c7b99de8 Mon Sep 17 00:00:00 2001 From: Siddharth U Date: Tue, 29 Sep 2026 21:39:47 +0530 Subject: [PATCH 1/2] docs: Update streaming behavior capabilities and add test --- README.md | 10 ++++++++- tests/test_mcp_streaming.py | 44 +++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 tests/test_mcp_streaming.py diff --git a/README.md b/README.md index 533da3f..5ad5b33 100644 --- a/README.md +++ b/README.md @@ -465,7 +465,15 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file **Start earning RTC today!** Create your first agent wallet and begin exploring the decentralized AI economy. -## Streaming and long-running tool behavior +## Streaming & long-running tools + +The MCP server advertises the following capabilities: +- `tools`: `ToolsCapability(list_changed=False)` +- `resources`: `ResourcesCapability(subscribe=False, list_changed=False)` +- `prompts`: `PromptsCapability(list_changed=False)` +- `logging`: `LoggingCapability()` + +There are no streaming or progress capability flags advertised. **Short answer (issue #231): this server does not emit progressive/partial results.** Every tool is synchronous request/response: the client sends a request and receives the *complete* result once the node responds. There is no SSE, no incremental chunks, and no per-tool `progress` callback. diff --git a/tests/test_mcp_streaming.py b/tests/test_mcp_streaming.py new file mode 100644 index 0000000..d5afd10 --- /dev/null +++ b/tests/test_mcp_streaming.py @@ -0,0 +1,44 @@ +import pytest +from unittest.mock import patch, MagicMock +from httpx import Response +import time + +from rustchain_mcp.server import mcp, get_client, RUSTCHAIN_NODE + +def test_server_capabilities(): + """Check the exact MCP capabilities the server advertises.""" + caps = mcp._mcp_server.get_capabilities() + assert caps.tools is not None + assert caps.tools.list_changed is False + assert caps.resources is not None + assert caps.resources.subscribe is False + assert caps.resources.list_changed is False + assert caps.prompts is not None + assert caps.prompts.list_changed is False + assert caps.logging is not None + +def test_slow_tool_call_is_blocking_without_progress(): + """Verify that a slow tool call behaves as a single blocking call and does not stream progress.""" + client = get_client() + + # Mock a slow HTTP request + mock_resp = MagicMock(spec=Response) + mock_resp.status_code = 200 + mock_resp.json.return_value = {"miners": [{"wallet": "slow_miner", "hw": "x86"}]} + + def slow_get(*args, **kwargs): + time.sleep(0.1) + return mock_resp + + with patch.object(client, "get", side_effect=slow_get): + # We invoke the tool directly as a python function, which is what FastMCP does + # It should block and then return the complete dict, no progress yielded. + start = time.time() + from rustchain_mcp.server import rustchain_miners + result = rustchain_miners() + duration = time.time() - start + + assert duration >= 0.1 + assert "miners" in result + assert result["miners"][0]["wallet"] == "slow_miner" + From dab7c95f5ab6841d0f579ac7fdcad3582cb9da78 Mon Sep 17 00:00:00 2001 From: Siddharth U Date: Fri, 2 Oct 2026 12:03:18 +0530 Subject: [PATCH 2/2] fix(lint): fix TRY203 and unneeded exceptions Signed-off-by: Siddharth U --- rustchain_mcp/events.py | 65 ++++++++++++++++++------------------- tests/test_mcp_streaming.py | 3 +- 2 files changed, 32 insertions(+), 36 deletions(-) diff --git a/rustchain_mcp/events.py b/rustchain_mcp/events.py index 0a7567a..f8c6928 100644 --- a/rustchain_mcp/events.py +++ b/rustchain_mcp/events.py @@ -98,7 +98,7 @@ class EventRelayConfig: miners_limit: int = 100 @classmethod - def from_env(cls) -> "EventRelayConfig": + def from_env(cls) -> EventRelayConfig: config = cls( node_url=os.environ.get("RUSTCHAIN_NODE", cls.node_url), poll_interval=_env_float( @@ -123,7 +123,7 @@ def from_env(cls) -> "EventRelayConfig": ) return config.validated() - def validated(self) -> "EventRelayConfig": + def validated(self) -> EventRelayConfig: node_url = _validate_node_url(self.node_url) if not 0.05 <= self.poll_interval <= 3600: raise RelayInputError("poll_interval must be between 0.05 and 3600 seconds") @@ -167,7 +167,7 @@ class SSEConfig: allow_remote: bool = False @classmethod - def from_env(cls) -> "SSEConfig": + def from_env(cls) -> SSEConfig: return cls( host=os.environ.get("RUSTCHAIN_EVENT_SSE_HOST", cls.host), port=_env_int("RUSTCHAIN_EVENT_SSE_PORT", cls.port), @@ -183,7 +183,7 @@ def from_env(cls) -> "SSEConfig": in ("true", "1", "yes"), ).validated() - def validated(self) -> "SSEConfig": + def validated(self) -> SSEConfig: if not 0 <= self.port <= 65535: raise RelayInputError("port must be between 0 and 65535") if not 1 <= self.max_clients <= 1000: @@ -633,39 +633,36 @@ def _fetch_source( *, params: dict[str, int] | None = None, ) -> Any: - try: - with self._client.stream( - "GET", - f"{self.config.node_url}{path}", - headers={"Accept": "application/json"}, - params=params, - timeout=self.config.request_timeout, - ) as response: - if response.status_code >= 400: - code = ( - "RATE_LIMITED" - if response.status_code == 429 - else "UPSTREAM_REJECTED" - ) - retryable = ( - response.status_code == 429 or response.status_code >= 500 + with self._client.stream( + "GET", + f"{self.config.node_url}{path}", + headers={"Accept": "application/json"}, + params=params, + timeout=self.config.request_timeout, + ) as response: + if response.status_code >= 400: + code = ( + "RATE_LIMITED" + if response.status_code == 429 + else "UPSTREAM_REJECTED" + ) + retryable = ( + response.status_code == 429 or response.status_code >= 500 + ) + if response.status_code >= 500: + code = "NODE_UNAVAILABLE" + raise _PollFailure( + _error_data( + code, retryable=retryable, status_code=response.status_code ) - if response.status_code >= 500: - code = "NODE_UNAVAILABLE" + ) + body = bytearray() + for chunk in response.iter_bytes(): + body.extend(chunk) + if len(body) > self.config.max_response_bytes: raise _PollFailure( - _error_data( - code, retryable=retryable, status_code=response.status_code - ) + _error_data("RESPONSE_TOO_LARGE", retryable=False) ) - body = bytearray() - for chunk in response.iter_bytes(): - body.extend(chunk) - if len(body) > self.config.max_response_bytes: - raise _PollFailure( - _error_data("RESPONSE_TOO_LARGE", retryable=False) - ) - except _PollFailure: - raise try: return json.loads(body.decode("utf-8")) diff --git a/tests/test_mcp_streaming.py b/tests/test_mcp_streaming.py index d5afd10..49be2fb 100644 --- a/tests/test_mcp_streaming.py +++ b/tests/test_mcp_streaming.py @@ -1,9 +1,8 @@ -import pytest from unittest.mock import patch, MagicMock from httpx import Response import time -from rustchain_mcp.server import mcp, get_client, RUSTCHAIN_NODE +from rustchain_mcp.server import mcp, get_client def test_server_capabilities(): """Check the exact MCP capabilities the server advertises."""