Skip to content

feat: add MCP server for AI assistant integration#16

Merged
JacobCoffee merged 4 commits intomainfrom
mcp-server
Nov 30, 2025
Merged

feat: add MCP server for AI assistant integration#16
JacobCoffee merged 4 commits intomainfrom
mcp-server

Conversation

@JacobCoffee
Copy link
Owner

Summary

  • Adds Model Context Protocol (MCP) server enabling AI assistants (Claude Code, Cursor) to access debug toolbar data
  • Implements 10 analysis tools and 10 data resources for comprehensive debugging insights
  • Includes security utilities for automatic sensitive data redaction
  • Provides CLI entry point for standalone server operation

MCP Tools (10)

Tool Purpose
get_request_history List tracked requests with filtering
analyze_performance_bottlenecks Find slow queries, resolvers, blocking calls
detect_n_plus_one_queries Detect N+1 patterns in SQL and GraphQL
get_query_explain_plan Get EXPLAIN for specific queries
analyze_security_alerts Security and config issue analysis
compare_requests Regression comparison between requests
get_graphql_operations GraphQL resolver analysis
get_async_task_profile Async task and event loop analysis
generate_optimization_report Multi-request optimization report
clear_request_history Clear stored history

MCP Resources (10)

URI Pattern Data
debug://requests All request summaries
debug://requests/{id} Full request details
debug://requests/{id}/panels All panel data
debug://requests/{id}/panels/{panel} Single panel
debug://requests/{id}/sql SQL queries
debug://requests/{id}/graphql GraphQL operations
debug://requests/{id}/alerts Security alerts
debug://requests/{id}/memory Memory profile
debug://requests/{id}/async Async profile
debug://config Current config

Usage

# Install with MCP support
pip install debug-toolbar[mcp]

# Run MCP server (stdio for Claude Code)
python -m debug_toolbar.mcp

# Run with HTTP/SSE transport
python -m debug_toolbar.mcp --transport http --port 8765

Test plan

  • 49 new unit tests for MCP module (524 total tests)
  • Security redaction tests (sensitive data filtering)
  • Server creation and configuration tests
  • All existing tests continue to pass

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings November 30, 2025 08:09
@github-actions
Copy link
Contributor

github-actions bot commented Nov 30, 2025

PR Preview Action v1.6.3

🚀 View preview at
https://JacobCoffee.github.io/debug-toolbar/pr-preview/pr-16/

Built to branch gh-pages at 2025-11-30 15:39 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.0 dependency with new mcp extra
  • 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.

JacobCoffee and others added 2 commits November 30, 2025 02:16
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>
Copilot AI review requested due to automatic review settings November 30, 2025 08:25
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 JacobCoffee enabled auto-merge (squash) November 30, 2025 15:39
@JacobCoffee JacobCoffee merged commit fa880ba into main Nov 30, 2025
18 checks passed
@JacobCoffee JacobCoffee deleted the mcp-server branch November 30, 2025 15:41
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants