Skip to content

feat: add MCP server support for agent integration - #55

Merged
codeasier merged 3 commits into
mainfrom
feat/mcp-server-support
Apr 19, 2026
Merged

codeasier merged 3 commits into
mainfrom
feat/mcp-server-support

Conversation

@codeasier

Copy link
Copy Markdown
Owner

📝 Description

Add MCP (Model Context Protocol) server support so LLM agents (Claude Desktop, Cursor, etc.) can programmatically query PyTorch memory snapshots without shelling out to CLI commands.

New architecture layer:

  • api.py — SnapshotAnalyzer service layer (no MCP dependency, reusable by CLI and MCP)
  • mcp/server.py — FastMCP server with 5 tools, 1 resource, 1 prompt
  • mcp optional dependency — pip install pt-snap-cli[mcp]

🔗 Related Issue

Fixes #54

🧪 Testing

  • Tests added: 23 new tests (test_api.py, test_mcp_server.py)
  • All 249 tests pass
  • Ruff lint check passes
  • Black format check passes
  • 91% overall coverage

✅ Checklist

  • Code follows project guidelines
  • No new warnings introduced
  • Changes tested locally
  • Backward compatible — existing CLI unchanged

📋 Additional Notes

MCP Tools Exposed

Tool Description
get_focus Get current analysis focus (db path + device)
set_focus Set analysis focus to specific db/device
list_templates List query templates (optional category filter)
get_template_info Get template params and output schema
execute_query Execute a query template with structured results

Usage

pip install -e ".[mcp]"
pt-snap-mcp  # starts MCP server via stdio

codeasier and others added 3 commits April 19, 2026 17:01
Add MCP (Model Context Protocol) server so LLM agents can programmatically
query PyTorch memory snapshots without shelling out to CLI commands.

- src/pt_snap_cli/api.py: SnapshotAnalyzer service layer (no MCP dep)
- src/pt_snap_cli/mcp/server.py: FastMCP server with 5 tools, 1 resource, 1 prompt
- pyproject.toml: add mcp optional dependency and pt-snap-mcp entry point
- tests/test_api.py, tests/test_mcp_server.py: 23 new tests

Tools exposed: get_focus, set_focus, list_templates, get_template_info,
execute_query. Backward compatible — existing CLI unchanged.

Fixes #54
CI installs only core + dev dependencies. Having mcp as optional
meant 'pip install -e .[dev]' skipped it, causing all MCP tests
to fail with ModuleNotFoundError.
Update README (EN/ZH), quickstart guides, and add dedicated MCP docs
covering tools, resources, prompts, and usage workflow.

@codeasier codeasier left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

LGTM

@codeasier
codeasier merged commit f7deb5d into main Apr 19, 2026
5 checks passed
@codeasier
codeasier deleted the feat/mcp-server-support branch April 19, 2026 16:48
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.

[FEATURE] MCP Server Support for Agent Integration

1 participant