Add MCP server endpoint at /-/mcp - #168
Open
simonw wants to merge 4 commits into
Open
Conversation
Implements a Model Context Protocol server for the dashboard, inspired by https://github.com/datasette/datasette-mcp - so LLM tools can explore the database and answer questions with read-only SQL. - New dependency-free stateless MCP Streamable HTTP endpoint (JSON responses) served at -/mcp under the dashboard URLs - Three read-only tools: list_tables, get_schema and execute_sql, with input/output schemas and readOnlyHint annotations - Requires an authenticated user with the execute_sql permission, and runs SQL through the same protected pattern as the dashboard views: dashboard database alias, rolled-back transaction, single statement only, DASHBOARD_ROW_LIMIT truncation and %(name)s parameter support - Documentation in docs/mcp.md - conftest.py now lets tests declare their own django_db marker, used by new transactional tests that verify read-only enforcement Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ZRFpnuD9tZKWb19Ffg8iF
Headless MCP clients cannot easily obtain a Django session cookie. The new optional DASHBOARD_MCP_TOKENS setting maps secret tokens to usernames, letting clients authenticate to the /-/mcp endpoint with an Authorization: Bearer header. - Tokens are compared with secrets.compare_digest, resolved with get_by_natural_key so custom user models work, and rejected for missing or inactive users - The mapped user must still hold the execute_sql permission - A request carrying a Bearer header never falls back to session auth - Documented in docs/mcp.md and the settings list in docs/setup.md Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ZRFpnuD9tZKWb19Ffg8iF
Two new MCP tools that follow saved dashboard view policies instead of requiring the execute_sql permission: - list_dashboards returns the dashboards the current user can view. Unlisted dashboards are excluded, matching the dashboard index page. - execute_dashboard runs every query saved on a dashboard by slug and returns per-query results or errors, with %(name)s parameter support. Unlisted dashboards work for anyone who knows the slug; dashboards that are missing or not visible produce the same error so private slugs are not disclosed. This makes the MCP endpoint useful to anonymous clients with no credentials at all: they can list and execute public dashboards. The SQL tools (list_tables, get_schema, execute_sql) still require the execute_sql permission, now enforced per tool call, and tools/list only advertises the tools the current user is allowed to use. The dashboard view policy logic is extracted from the dashboard view into a new Dashboard.user_can_view() model method shared by both the web view and the MCP tools. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ZRFpnuD9tZKWb19Ffg8iF
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ZRFpnuD9tZKWb19Ffg8iF
simonw
added a commit
to simonw/simonwillisonblog
that referenced
this pull request
Aug 1, 2026
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.
Implements a Model Context Protocol server for the dashboard, inspired
by https://github.com/datasette/datasette-mcp - so LLM tools can explore
the database and answer questions with read-only SQL.
responses) served at -/mcp under the dashboard URLs
input/output schemas and readOnlyHint annotations
runs SQL through the same protected pattern as the dashboard views:
dashboard database alias, rolled-back transaction, single statement
only, DASHBOARD_ROW_LIMIT truncation and %(name)s parameter support
by new transactional tests that verify read-only enforcement
Co-Authored-By: Claude Fable 5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_017ZRFpnuD9tZKWb19Ffg8iF