feat(mcp): Add MCP server for Querybook#1698
Open
baumandm wants to merge 1 commit intopinterest:masterfrom
Open
feat(mcp): Add MCP server for Querybook#1698baumandm wants to merge 1 commit intopinterest:masterfrom
baumandm wants to merge 1 commit intopinterest:masterfrom
Conversation
Adds a Model Context Protocol (MCP) server that exposes Querybook's
core functionality as structured tools and resources, enabling AI
agents to easily interact with Querybook programmatically.
Tools (42):
- DataDocs: full CRUD for docs, cells (query/text/chart/python),
editors, and template variables
- Query Execution: run cells, execute ad-hoc queries, run full
DataDocs, list executions with status/engine filters
- Lists: CRUD for lists, items (data_doc/table/list/query types),
and editors with permission control
- Comments & Reactions: threaded comments on cells with emoji reactions
- Schedules: cron-based DataDoc scheduling with notifications,
retries, and result exports
- Users: current user, batch lookup, search
- Environments & Engines: discovery and enumeration
Resources (15 URI templates):
- querybook://datadoc/{id}, datadoc-cell/{id}, query-execution/{id},
statement-execution/{id}/results, comment/{id}, schedule/{id},
list/{id}, environment/{id}, query-engine/{id}, user/{id}
- Paginated sub-resources for cell executions, schedule runs, and
cell comments
- Static resource guide at querybook://resource-guide
Infrastructure:
- Built with FastMCP 3.0
- Authentication with existing API token
- MCP event logging middleware for all tool and resource operations
- Docker Compose service and runservice integration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a Model Context Protocol (MCP) server to Querybook, enabling AI agents to easily interact with Querybook programmatically. Built on FastMCP, the server runs as a standalone stateless HTTP service that can be horizontally scaled alongside the existing web, worker, and scheduler services.
The server is opt-in and has no impact on existing deployments. It runs as a separate container a separate port.
We've been using this server internally at Expedia for a while now with great success.
Usage
In Claude Code, something like this:
Implementation
It is designed to mirror Querybook's existing REST API surface, reusing the same foundational layers and sharing as much code as possible. There are a handful of deviations from the REST API, specifically to simplify things for AI agents to reduce API calls and token use.
Resources
The MCP server exposes both Tools and Resources:
querybook://URI scheme, and are discoverable through tool responsesquerybook://datadoc/{id},datadoc-cell/{id},query-execution/{id},statement-execution/{id}/results,comment/{id},schedule/{id},list/{id},environment/{id},query-engine/{id}, user/{id}querybook://resource-guideAuth
Querybook's existing API token implementation is used here, with a
QuerybookTokenVerifierthat validates Bearer tokens. The authenticated user's identity flows through to all permission checks as expected.Event Logging
Both tools and resources are wired up with the existing Event Log system, recording all actions with
EventType.MCP, capturing timing, user, operation details, and status for audit purposes.There is one Alembic migration to add this EventType to the schema.
Notes
Boards are called Lists in the UI, so we went with Lists in the MCP server so it would match the terminology our users would be familiar with. This is a spot where the REST API differs.
Some of the responses have been humanized compared to the REST API counterparts
Missing functionality: