feat: add MCP server for AI assistant integration#16
Merged
JacobCoffee merged 4 commits intomainfrom Nov 30, 2025
Merged
Conversation
Add Model Context Protocol (MCP) server that enables AI assistants like Claude Code and Cursor to access debug toolbar data programmatically. Features: - 10 analysis tools: get_request_history, analyze_performance_bottlenecks, detect_n_plus_one_queries, get_query_explain_plan, analyze_security_alerts, compare_requests, get_graphql_operations, get_async_task_profile, generate_optimization_report, clear_request_history - 10 data resources: requests list, request details, panel data, SQL queries, GraphQL operations, security alerts, memory profile, async profile, config - Security utilities for sensitive data redaction - CLI entry point: python -m debug_toolbar.mcp - Support for stdio (Claude Code) and HTTP/SSE transports Optional dependency: pip install debug-toolbar[mcp] 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds Model Context Protocol (MCP) server support to enable AI assistants (Claude Code, Cursor) to access debug toolbar data for analysis and troubleshooting.
Key Changes:
- Adds optional
mcp>=1.0.0dependency with newmcpextra - Implements 10 MCP tools for performance analysis, N+1 detection, and optimization reporting
- Implements 10 MCP resources for structured data access via URI patterns
- Includes security utilities for automatic sensitive data redaction
- Provides CLI entry point (
python -m debug_toolbar.mcp) for standalone operation
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
uv.lock |
Adds mcp 1.22.0 and dependencies (pydantic, httpx-sse, jsonschema, cryptography, etc.) |
pyproject.toml |
Adds mcp extra with mcp>=1.0.0 requirement |
src/debug_toolbar/mcp/__init__.py |
Module initialization exposing create_mcp_server and is_available |
src/debug_toolbar/mcp/__main__.py |
CLI entry point with transport options and configuration |
src/debug_toolbar/mcp/server.py |
Core MCP server creation with lifecycle management |
src/debug_toolbar/mcp/security.py |
Security utilities for redacting sensitive data (passwords, tokens, etc.) |
src/debug_toolbar/mcp/tools.py |
10 MCP tools for performance analysis and debugging |
src/debug_toolbar/mcp/resources.py |
10 MCP resources for structured data access |
tests/unit/mcp/test_server.py |
Unit tests for MCP server creation and availability |
tests/unit/mcp/test_security.py |
Unit tests for security redaction utilities |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add runnable example demonstrating: - Debug toolbar web app with shared storage - MCP server connecting to same storage - Claude Code integration instructions Usage: make example-mcp # Run web app make example-mcp-server # Run MCP server 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add noqa comments for C901 complexity (inherent to tool registration) - Define constants for magic values (PLR2004) - Make boolean args keyword-only (FBT001/002) - Use X | Y in isinstance (UP038) - Update MCP run() API to match SDK changes - Remove host/port params (not in current FastMCP.run() signature) - Add type annotations to fix sorted() overload matching 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 13 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Handle zero baseline edge case in compare_requests - Return None for duration_pct_change when baseline is 0 but comparison > 0 - Detect regression when going from 0 to any positive duration - Replace type: ignore with cast() for sorted() calls - Improve regression/improvement detection logic 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
JacobCoffee
added a commit
that referenced
this pull request
Nov 30, 2025
- Mark Phase 13 (AI & Modern Tooling) as COMPLETE - Update competitive analysis: AI Integration now best-in-class - Update next steps: MCP docs and v0.3.0 release fix: use local dev environment for MCP example - Use `uv run python` instead of `uv run` for MCP examples - Avoids PEP 723 trying to install from PyPI before release 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
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.
Summary
MCP Tools (10)
get_request_historyanalyze_performance_bottlenecksdetect_n_plus_one_queriesget_query_explain_plananalyze_security_alertscompare_requestsget_graphql_operationsget_async_task_profilegenerate_optimization_reportclear_request_historyMCP Resources (10)
debug://requestsdebug://requests/{id}debug://requests/{id}/panelsdebug://requests/{id}/panels/{panel}debug://requests/{id}/sqldebug://requests/{id}/graphqldebug://requests/{id}/alertsdebug://requests/{id}/memorydebug://requests/{id}/asyncdebug://configUsage
Test plan
🤖 Generated with Claude Code