Skip to content

Commit 2298302

Browse files
feat: implement MCP server for AI assistant integration (#4132)
Implements #4129 ## Summary Adds MCP (Model Context Protocol) server integration to enable AI assistants like Claude Code to discover plot specifications and retrieve implementation code from the pyplots platform. ## Features - **6 MCP tools** for plot discovery and code retrieval: - `list_specs` - Browse all specifications with pagination - `search_specs_by_tags` - Filter by 9 tag categories (spec + impl level) - `get_spec_detail` - Full spec with all library implementations - `get_implementation` - Single library code with quality score - `list_libraries` - All 9 supported plotting libraries - `get_tag_values` - Available values for tag discovery ## Technical Implementation - FastMCP SDK integration - Mounted at `/mcp` endpoint in FastAPI - Reuses existing repositories (SpecRepository, LibraryRepository, ImplRepository) - Async database context management - Response models from `api/schemas.py` ## Testing - ✅ **15/15 unit tests passing** (with mocked database sessions) - ✅ **Tested with live database** (253 specs, 9 libraries, all tools working) - ✅ **Code quality checks passing** (ruff lint + format) ## Dependencies Added - `mcp>=1.0.0` (protocol package) - `fastmcp>=0.1.0` (SDK) ## Commits - `eac996e9` - Initial MCP server implementation - `d05edb14` - Fix database model attribute names Closes #4129 --------- Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 4421576 commit 2298302

File tree

7 files changed

+1491
-5
lines changed

7 files changed

+1491
-5
lines changed

api/main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
stats_router,
3636
)
3737
from core.database import close_db, init_db, is_db_configured # noqa: E402
38+
from pyplots_mcp.server import mcp_server # noqa: E402
3839

3940

4041
# Configure logging
@@ -92,6 +93,7 @@ async def lifespan(app: FastAPI):
9293
allow_credentials=True,
9394
allow_methods=["*"],
9495
allow_headers=["*"],
96+
expose_headers=["Mcp-Session-Id"], # MCP session tracking
9597
)
9698

9799

@@ -123,6 +125,9 @@ async def add_cache_headers(request: Request, call_next):
123125
return response
124126

125127

128+
# Mount MCP server for AI assistant integration
129+
app.mount("/mcp", mcp_server.http_app())
130+
126131
# Register routers
127132
app.include_router(health_router)
128133
app.include_router(stats_router)

pyplots_mcp/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""
2+
MCP (Model Context Protocol) server for pyplots.
3+
4+
Enables AI assistants to search plot specifications and fetch implementation code.
5+
"""

0 commit comments

Comments
 (0)