You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .env.example
+6Lines changed: 6 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -32,6 +32,12 @@ BLOCKSCOUT_PRO_API_KEY=""
32
32
# When a client sends this header, its key takes precedence over BLOCKSCOUT_PRO_API_KEY for that request; absent it, the server key is used.
33
33
# A malformed client-supplied key fails any PRO API request that would use it, with no fallback; tools that don't use the PRO API are unaffected. Set to an empty string to disable client-supplied keys entirely.
│ ├── pro_api_key_context.py # Request-scoped client-supplied PRO API key state, resolver, and @pro_api_key_scope decorator
26
+
│ ├── pro_api_key_context.py # Request-scoped client-supplied PRO API key state, resolver, and @pro_api_key_scope decorator; per-invocation credit sink and @pro_api_credit_scope decorator
27
27
│ ├── cache.py # Simple in-memory cache for chain data
28
28
│ ├── web3_pool.py # Async Web3 connection pool manager
29
29
│ ├── models.py # Defines standardized Pydantic models for all tool responses
@@ -188,7 +188,8 @@ mcp-server/
188
188
│ ├── test_common.py # Unit tests for shared tool utilities
189
189
│ ├── test_common_truncate.py # Unit tests for truncation helpers
190
190
│ ├── test_common_post_request.py # Unit tests for POST request helper
191
-
│ └── test_decorators.py # Unit tests for logging decorators
191
+
│ ├── test_decorators.py # Unit tests for logging decorators
192
+
│ └── test_credit_tracking.py # Unit tests for PRO API credit capture and low-credits note
192
193
├── mcpb/ # MCP Bundle package for Claude Desktop
193
194
│ ├── README.md # MCPB documentation and build instructions
194
195
│ ├── manifest.json # Bundle manifest for development builds
@@ -388,6 +389,7 @@ mcp-server/
388
389
* Owns request-scoped resolution of a client-supplied Blockscout PRO API key, kept separate from logging/observability.
389
390
* Provides a `ContextVar` of the per-request client-key state, a normalization/validation helper, `extract_client_pro_api_key_from_ctx()`, `resolve_pro_api_key()` (precedence: valid client key → server key → not-configured error; malformed client key → terminal error, no fallback), and the `@pro_api_key_scope` decorator.
390
391
* Honored only for genuine MCP calls (ignored when `ctx.call_source == "rest"`); the key is never logged or placed in cache keys.
392
+
* Also defines the per-invocation credit-tracking symbols: `CreditSink`, the `_credit_sink``ContextVar`, and the `@pro_api_credit_scope` decorator (a sibling of `@pro_api_key_scope`).
391
393
***`cache.py`**:
392
394
* Encapsulates in-memory caching of chain data with TTL management.
Copy file name to clipboardExpand all lines: API.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,7 +65,7 @@ Tool endpoints under `/v1/` return a consistent JSON object that wraps the tool'
65
65
66
66
-`data`: The main data payload of the response. Its structure is specific to each endpoint.
67
67
-`data_description`: (Optional) A list of strings explaining the structure or fields of the `data` payload.
68
-
-`notes`: (Optional) A list of important warnings or contextual notes, such as data truncation alerts.
68
+
-`notes`: (Optional) A list of important warnings or contextual notes, such as data truncation alerts or a low-credits advisory emitted when the Blockscout PRO API credit balance drops below the configured threshold.
69
69
-`instructions`: (Optional) A list of suggested follow-up actions for an AI agent.
70
70
-`pagination`: (Optional) An object containing information to retrieve the next page of results.
**Client-supplied keys (HTTP MCP only).** When the server runs in HTTP mode, an MCP client can supply its own PRO API key in a request header — by default `Blockscout-MCP-Pro-Api-Key`, configurable via `BLOCKSCOUT_PRO_API_KEY_HEADER` (set it to an empty string to disable client-supplied keys entirely). A client-supplied key takes precedence over `BLOCKSCOUT_PRO_API_KEY` for that request; if the client sends no key, the server falls back to its own configured key; if neither is present, the request fails with the not-configured error. A client key that is present but malformed fails any request that needs the PRO API with no fallback (the server never silently uses its own key in place of a bad client key); tools that don't use the PRO API are unaffected. This makes it possible to run a shared HTTP server where each client authenticates with its own key. The client-key header is honored only for genuine MCP tool calls — the REST API ignores it and always authenticates with the server's configured key.
233
233
234
+
**Low-credit warning.** Access to the PRO API is metered in credits. When the remaining balance reported by the API drops below a configurable threshold, every data tool appends an advisory note to its response, prompting operators to top up so PRO API access stays ready for continued high-volume usage. The threshold is set via `BLOCKSCOUT_PRO_API_LOW_CREDITS_THRESHOLD` (default `5000` credits; set to `0` to disable the note). The note fires for any balance below the threshold, including zero and negative balances.
Copy file name to clipboardExpand all lines: SPEC.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -274,7 +274,7 @@ Credit-exhaustion responses on the PRO API *data path* are special-cased: the sh
274
274
275
275
-`data`: The main data payload of the tool's response. The schema of this field can be specific to each tool.
276
276
-`data_description`: An optional list of strings that explain the structure, fields, or conventions of the `data` payload (e.g., "The `method_call` field is actually the event signature...").
277
-
-`notes`: An optional list of important contextual notes, such as warnings about data truncation or data quality issues. This field includes guidance on how to retrieve full data if it has been truncated.
277
+
-`notes`: An optional list of important contextual notes, such as warnings about data truncation or data quality issues, or a low-credits advisory when the Blockscout PRO API credit balance falls below the configured threshold. This field includes guidance on how to retrieve full data if it has been truncated.
278
278
-`instructions`: An optional list of suggested follow-up actions for the LLM to plan its next steps. When pagination is available, the server automatically appends pagination instructions to motivate LLMs to fetch additional pages.
279
279
-`pagination`: An optional object that provides structured information for retrieving the next page of results.
280
280
@@ -601,6 +601,8 @@ Credit-exhaustion responses on the PRO API *data path* are special-cased: the sh
601
601
602
602
When changing the retry policy, account for both surfaces.
603
603
604
+
**Credit usage visibility (advisory low-credits note).** When the PRO API reports a low remaining credit balance, the server surfaces it as an advisory note in `ToolResponse.notes`. The signal is best-effort and HTTP-backed — captured opportunistically from PRO API responses and never affecting the request outcome — and is gated by an operator-configurable threshold that can tune or disable it (configured via environment variable; see README and `.env.example`). It is the plan-agnostic early-warning complement to the credit-exhaustion hard-stop documented in §8 ("Credit Exhaustion"). Implementation mechanics are documented in the relevant code docstrings and exercised by focused unit tests, not restated in this specification.
605
+
604
606
8. **HTTP Error Handling and Context Propagation**
605
607
606
608
To enable AI agents to self-correct when API requests fail (e.g., due to invalid parameters like unsupported sort fields), the server implements a robust error propagation strategy.
0 commit comments