clear_cache
Clear all cached cryptocurrency data to force a fresh fetch from sources. Use when market data appears stale or a user explicitly requests a refresh. Returns the number of cache entries removed.
Instructions
Drop every entry from the HTTP cache.
Reach for this when:
The user explicitly asks to refresh / invalidate cached data.
You suspect cached data is materially stale and a TTL has not yet expired (e.g. user reports a price that disagrees with their exchange).
Prefer letting TTLs expire naturally; this tool resets ALL endpoints, not just one. Counters (hits/misses/...) are preserved.
Returns: {"cleared": }
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- coin_mcp/cache.py:290-305 (handler)The clear_cache MCP tool handler function. Decorated with @mcp.tool(), it calls the clear() helper and returns {'cleared': <count of dropped entries>}.
@mcp.tool() async def clear_cache() -> dict[str, int]: """Drop every entry from the HTTP cache. Reach for this when: - The user explicitly asks to refresh / invalidate cached data. - You suspect cached data is materially stale and a TTL has not yet expired (e.g. user reports a price that disagrees with their exchange). Prefer letting TTLs expire naturally; this tool resets ALL endpoints, not just one. Counters (hits/misses/...) are preserved. Returns: {"cleared": <number of entries dropped>} """ return {"cleared": clear()} - coin_mcp/cache.py:262-265 (helper)The clear() helper function called by the clear_cache tool. Clears the internal _store OrderedDict and returns the number of entries that were removed.
def clear() -> int: n = len(_store) _store.clear() return n - coin_mcp/cache.py:290-291 (registration)The @mcp.tool() decorator on clear_cache registers this function as an MCP tool with the FastMCP server instance.
@mcp.tool() async def clear_cache() -> dict[str, int]: - coin_mcp/cache.py:290-305 (schema)The clear_cache tool takes no input parameters and returns a dict with a single int key 'cleared', as documented in the docstring.
@mcp.tool() async def clear_cache() -> dict[str, int]: """Drop every entry from the HTTP cache. Reach for this when: - The user explicitly asks to refresh / invalidate cached data. - You suspect cached data is materially stale and a TTL has not yet expired (e.g. user reports a price that disagrees with their exchange). Prefer letting TTLs expire naturally; this tool resets ALL endpoints, not just one. Counters (hits/misses/...) are preserved. Returns: {"cleared": <number of entries dropped>} """ return {"cleared": clear()} - tests/conftest.py:13-17 (helper)Test fixture that calls cache.clear() before and after every test to isolate cache state.
@pytest.fixture(autouse=True) def clear_cache_each_test(): """Drop all cache entries before every test so state can't leak between tests.""" _cache.clear() yield