MCP server¶
Reference for the ngsw-mcp implementation. The user-facing description is
MCP server.
MCP server exposing the switch library’s read/write ops as MCP tools.
Optional: requires the [mcp] extra (the mcp SDK). server.build_server
constructs a FastMCP instance wired to the same inventory/credential
resolution the ngsw CLI uses; server.main runs it over stdio (the
ngsw-mcp entry point). Writes are OFF unless NGSW_MCP_ALLOW_WRITES is
set, so an MCP client cannot reconfigure a switch by default.
FastMCP server over the python-netgear-switch-library read/write API.
Every tool resolves its target switch through the SAME path the ngsw CLI
uses (cli.resolve.resolve_switch): either a named switch in a TOML
inventory (switch= + config=/$NGSW_INVENTORY) or an ad-hoc
host= + model= pair, with credentials layered from args/env/inventory.
Results are the library’s own models dataclasses, serialized to plain JSON.
Honesty carries through unchanged: an op a given model’s backends genuinely do
not expose returns a structured {"unsupported": true, ...} result (from the
reader’s UnsupportedCapabilityError), never fabricated data.
Writes are gated: the write tools are only registered when
NGSW_MCP_ALLOW_WRITES is truthy, because an MCP tool call is
model-initiated and reconfiguring a live switch is destructive. Even then each
disruptive op requires the caller to pass force=true (the same rail the CLI
and library enforce).
- netgear_switch.mcp.server.writes_enabled(env=None)[source]¶
True iff writes are opted in via
$NGSW_MCP_ALLOW_WRITES.- Return type:
- netgear_switch.mcp.server.list_inventory_switches(config, env)[source]¶
The named switches in the TOML inventory (
[switches.<name>]).
- netgear_switch.mcp.server.build_server(env=None, *, host=None, port=None)[source]¶
Construct the FastMCP server. Write tools are registered only when
$NGSW_MCP_ALLOW_WRITESis set (see module docstring).host/portare the bind address for the HTTP transport (seemain()); they are passed to FastMCP only when given, so the stdio default is untouched.