Skip to content

Add request timeouts + error handling, and the first tests#1

Open
mkzung wants to merge 1 commit into
AnChainAI:mainfrom
mkzung:request-timeouts-and-tests
Open

Add request timeouts + error handling, and the first tests#1
mkzung wants to merge 1 commit into
AnChainAI:mainfrom
mkzung:request-timeouts-and-tests

Conversation

@mkzung

@mkzung mkzung commented Jul 4, 2026

Copy link
Copy Markdown

Problem

Every one of the 20 API calls in mcp_server.py uses requests.get/post(...) with no timeout and returns res.json() with no status or JSON check, and check_apikey() raises a non-ToolError exception. In a stdio MCP server this means:

  • a slow or dead upstream hangs the process forever (worst case auto_trace_address, whose own docstring says it may take up to 5 minutes); and
  • a non-2xx or non-JSON response, or a missing API key, reaches the model as a masked generic "internal error" (FastMCP hides non-ToolError exceptions), so it never learns it was a bad key, a rate limit, or a bad address.

Fix

  • Add a small _request() helper (with _get/_post wrappers) that always sets a timeout and raises ToolError with an actionable message on timeout, transport error, non-JSON body, or an error status (the HTTP code, or the API's {"status": ..., "err_msg": ...} envelope). All 20 tools route through it; auto_trace_address gets a longer read timeout.
  • check_apikey() now raises ToolError too, naming how to supply the key.
  • Fix a docstring that listed hash (a parameter name) as a blockchain protocol, and drop the now-unused exception imports.
  • Add the repo's first test suite (9 offline unit tests, no API key or network) and a minimal CI workflow to run them.

No API or behavior change on the success path; pytest is green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant