Dune Analytics MCP Server for AI Agents
Connect AI agents to Dune Analytics with an MCP server that streams query results, enables real-time data access, and simplifies analytics-driven decisions.
npx -y @kukapay/dune-analytics-mcpOverview
This MCP (Model Context Protocol) server bridges AI agents and Dune Analytics by streaming query results and exposing them as live, agent-consumable resources. Instead of polling Dune APIs for completed reports, the server invokes Dune queries, monitors progress, and pushes partial and final results to connected agents. That makes it simpler to feed up-to-date analytics into decision-making workflows, conversational agents, and automation pipelines.
The server is particularly useful when agents need iterative access to large or long-running queries: agents can start a query, receive incremental rows as they arrive, and take actions (summaries, alerts, trades) without waiting for the full query to finish. The implementation focuses on a lightweight API and streaming interfaces so developers can integrate analytics-driven context into LLMs or other AI systems with minimal glue code.
Features
- Stream Dune Analytics query results incrementally (Server-Sent Events / HTTP streaming)
- Start and monitor query execution from an HTTP API
- Expose progress, partial rows, and final result sets to connected agents
- Simple configuration via environment variables or Docker
- Basic authentication and rate limiting hooks (pluggable)
- Example client snippets for JavaScript and Python to receive streamed data
- Logging and optional caching of recent query outputs
Installation / Configuration
Clone the repository and install dependencies. This project can run locally or inside Docker.
Bash (clone + install):
# If Node.js/TypeScript project:
# Or for Python-based server:
Environment variables (example):
# Optional:
Run the server (examples):
# Node / npm
# Or direct node
# Docker
Configuration tips:
- Set a short cache TTL when using agents that need frequent fresh data.
- Protect the server with an AUTH_TOKEN or upstream proxy if exposed publicly.
- Monitor rate limits on your Dune account; the server can queue requests but not bypass Dune quotas.
Available Resources
The server exposes a small set of HTTP endpoints and a streaming interface suited for AI agents. Example endpoints:
| Endpoint | Method | Description |
|---|---|---|
| /queries | GET | List available saved query IDs and metadata |
| /query/start | POST | Start a Dune query run (provides run_id) |
| /query/status/{run_id} | GET | Poll run status (queued, running, completed, failed) |
| /query/stream/{run_id} | GET (SSE/stream) | Stream partial rows, progress events, and final results |
| /query/result/{run_id} | GET | Download final result as JSON or CSV |
Typical streaming payloads use SSE with event types like row, progress, and complete. Example SSE event bodies are JSON objects containing a small batch of rows or status metadata.
Client examples:
JavaScript (EventSource):
;
;
'row', ;
'complete', ;
Python (requests, streaming):
continue
# Decode SSE-like lines
Use Cases
Real-time agent-driven dashboards
- An agent monitors blockchain activity on Dune and updates a dashboard as new rows arrive. The MCP server streams partial results, enabling the dashboard to reflect near-real-time analytics without frequent full query re-runs.
Automated trading or alerting systems
- Trading agents subscribe to a streaming query that calculates on-chain signals. When specific thresholds are observed in partial results, the agent executes trades or sends alerts immediately rather than after batch completion.
Conversational analytics assistants
- A chat-based AI answers user questions using fresh on-chain data. The assistant triggers a Dune query via the MCP server and can provide progressive summaries while the query runs, then refine answers using the final data.
Scheduled reports with incremental verification
- Reporting bots launch large aggregation queries and validate intermediate checkpoints as rows arrive. This reduces the time between data availability and automated report generation.
Notes for Developers
- Handle backpressure: downstream agents should be prepared to process frequent row events or unsubscribe when overloaded.
- Respect Dune quotas: batching and caching help reduce load on the upstream Dune API.
- Security: do not embed raw API keys in client code. Use server-side auth and short-lived tokens for agent access.
- Extendability: the server is built to allow adding custom hooks (post-processing, enrichment, storage) on streamed events.
For repository-specific usage details, check the project’s example clients and configuration files in the repo.