Commit 2298302
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- api
- pyplots_mcp
- tests/unit/pyplots_mcp
7 files changed
+1491
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
92 | 93 | | |
93 | 94 | | |
94 | 95 | | |
| 96 | + | |
95 | 97 | | |
96 | 98 | | |
97 | 99 | | |
| |||
123 | 125 | | |
124 | 126 | | |
125 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
126 | 131 | | |
127 | 132 | | |
128 | 133 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
0 commit comments