Add official MCP server for Batfish (beta)#970
Conversation
Co-authored-by: dhalperi <526415+dhalperi@users.noreply.github.com>
Co-authored-by: dhalperi <526415+dhalperi@users.noreply.github.com>
dhalperi
left a comment
There was a problem hiding this comment.
Please mark this clearly as a beta in the docs and MCP instructions and everywhere else it makes sense to do so.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #970 +/- ##
==========================================
+ Coverage 86.93% 87.77% +0.84%
==========================================
Files 23 26 +3
Lines 3490 3763 +273
Branches 457 501 +44
==========================================
+ Hits 3034 3303 +269
- Misses 324 330 +6
+ Partials 132 130 -2
🚀 New features to boost your workflow:
|
|
@copilot read review feedback, also get checks and tests to pass |
There was a problem hiding this comment.
Pull request overview
Adds a first-party pybatfish.mcp package implementing an MCP (Model Context Protocol) server so MCP clients can drive Batfish workflows via registered tools.
Changes:
- Introduces
pybatfish.mcp.server.create_server()(FastMCP) with 23 Batfish tools (snapshots, reachability/traceroute, ACLs, routes, BGP, properties, validations). - Adds a stdio entrypoint (
python -m pybatfish.mcp/batfish-mcp) and packages/dependency wiring viapyproject.toml. - Adds a new
tests/mcp/suite with mocked-Session integration-style tests plus helper unit tests.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
pybatfish/mcp/server.py |
Implements the MCP server and tool handlers plus helper functions. |
pybatfish/mcp/__main__.py |
Provides stdio runtime entrypoint for MCP server execution. |
pybatfish/mcp/__init__.py |
Exposes create_server() as the package’s public API. |
pyproject.toml |
Adds mcp optional extra, includes mcp in dev, and registers batfish-mcp console script. |
tests/mcp/test_server.py |
Adds coverage for helper functions and all tool registrations/behaviors with mocked Session. |
tests/mcp/__init__.py |
Adds test package marker. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…exthop cols, fix mypy, add integration tests Co-authored-by: dhalperi <526415+dhalperi@users.noreply.github.com>
Done in 89bc611. Added |
…n every tool call Co-authored-by: dhalperi <526415+dhalperi@users.noreply.github.com>
…failure Co-authored-by: dhalperi <526415+dhalperi@users.noreply.github.com>
Addressed all review feedback in d2ed184 (and prior commits eb54113, 89bc611):
|
…iminate duplicated setup logic Co-authored-by: dhalperi <526415+dhalperi@users.noreply.github.com>
All review feedback addressed in a144def (and prior commits d2ed184, eb54113): Remaining reviewer comment (duplicated setup logic) — done in a144def. Extracted three private helpers:
All 23 tool functions now use one of these two helpers instead of repeating the 3-4 line setup block. Also fixed a bug: CI: The integration test failure ( Coverage: |
…ion for all tools Co-authored-by: dhalperi <526415+dhalperi@users.noreply.github.com>
…route and optional param branches Co-authored-by: dhalperi <526415+dhalperi@users.noreply.github.com>
Addressed in c0f1e8f. Added 13 new unit tests covering the uncovered branches:
Coverage improved from 84.6% → 99.4% (78 tests). Only lines 35–36 remain uncovered — the
CI (Pre-commit) is passing (success) on commit a376a16. The latest round of coverage improvements is in c0f1e8f — 78 unit tests, 99.4% coverage of server.py. |
dhalperi
left a comment
There was a problem hiding this comment.
@dhalperi reviewed 7 files and all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on copilot[bot]).
pybatfish/mcp/package with MCP server implementationmcp>=1.23.0optional dependency topyproject.tomlbatfish-mcpconsole script entry pointtests/mcp/(78 tests, 99.4% coverage)tests/integration/test_mcp_server.py(14 tests against live Batfish)__init__.py,__main__.py, and server instructionsbf_prefix from all 23 tool namesNext_Hop_parse_interfaces()to raiseValueErrorfor bare node tokens (notnode[interface]format)get_bgp_session_compatibilitydocstring to clarify it returns full table unless status is specifieddetect_loopsfails with empty snapshot; switch totracert_snapshot_resolve_host(),_mgmt_session(),_analysis_session()helpers to centralize duplicated setup logic across all 23 toolsNext_Hop_Type/NextHopTypecolumns from_LEGACY_NEXTHOP_COLUMNSload_questions=Falsepath)TestRunBidirectionalTracerouteTooland optional parameter branch tests for all analysis toolsOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.