Server-Side Data Analysis
query_cache is one of the most powerful features of the MCP Server — it allows you to analyze data without consuming context window tokens.The Problem
When you search for 50 LinkedIn profiles, all 50 results are returned into the LLM’s context. Filtering, sorting, or aggregating requires the LLM to process all data in-context — expensive and limited by context size.The Solution: ClickHouse-Backed Cache
Everyexecute() call stores results in a ClickHouse cache (TTL: 7 days). The query_cache tool lets you query this cache server-side — only the filtered/aggregated results are returned to context.
Filtering
Useconditions to filter cached results by any field:
Supported Filter Operators
| Operator | Description | Example |
|---|---|---|
= | Exact match | {"field": "country", "op": "=", "value": "US"} |
!= | Not equal | {"field": "status", "op": "!=", "value": "inactive"} |
> | Greater than | {"field": "followers", "op": ">", "value": 1000} |
< | Less than | {"field": "age", "op": "<", "value": 30} |
>= | Greater or equal | {"field": "score", "op": ">=", "value": 4.5} |
<= | Less or equal | {"field": "price", "op": "<=", "value": 100} |
contains | Substring match | {"field": "title", "op": "contains", "value": "Engineer"} |
not_contains | Substring exclusion | {"field": "bio", "op": "not_contains", "value": "retired"} |
Aggregation
Calculate summary statistics without loading individual records:Supported Aggregation Functions
| Function | Description | Example |
|---|---|---|
count | Count records | {"field": "id", "op": "count"} |
sum | Sum values | {"field": "likes", "op": "sum"} |
avg | Average value | {"field": "followers", "op": "avg"} |
min | Minimum value | {"field": "price", "op": "min"} |
max | Maximum value | {"field": "score", "op": "max"} |
uniq | Count unique values | {"field": "country", "op": "uniq"} |
Group By
Combine aggregation with grouping to get breakdowns:Sorting
Sort cached results by any field:Combined Example
A full workflow combining all features:Export Data
Download full cached datasets as files:Supported Formats
| Format | Description |
|---|---|
json | JSON array |
csv | Comma-separated values |
jsonl | JSON Lines (one record per line) |
Best Practices
Use Large Counts
Fetch more data with
execute() (count: 100-200), then filter with query_cache. Cheaper than multiple small requests.Filter Before Reading
Always use
query_cache to narrow results before loading them into context. Saves tokens and improves response quality.Aggregate Server-Side
Use aggregation functions instead of asking the LLM to calculate averages, counts, or sums from raw data.
Export for External Use
Use
export_data when you need the full dataset outside of the AI conversation (spreadsheets, databases, reports).