Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
65 changes: 31 additions & 34 deletions rustchain_mcp/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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")
Expand Down Expand Up @@ -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),
Expand All @@ -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:
Expand Down Expand Up @@ -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"))
Expand Down
43 changes: 43 additions & 0 deletions tests/test_mcp_streaming.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from unittest.mock import patch, MagicMock
from httpx import Response
import time

from rustchain_mcp.server import mcp, get_client

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"

Loading