Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions jmcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,24 @@ async def handle_load_and_commit_config(arguments: dict, context: Context) -> li
return [content_block]


async def handle_execute_fpc_command(arguments: dict, context: Context) -> list[types.ContentBlock]:
"""Handler for execute_fpc_command tool using cprod shell command"""
router_name = arguments.get("router_name", "")
fpc_slot = arguments.get("fpc_slot", "0")
fpc_command = arguments.get("fpc_command", "")
timeout = arguments.get("timeout", 360)

if router_name not in devices:
result = f"Router {router_name} not found in the device mapping."
else:
# Use start shell to access the shell and run cprod command
shell_command = f'start shell command "cprod -A fpc{fpc_slot} -c \'{fpc_command}\'"'
log.debug(f"Executing FPC command '{fpc_command}' on FPC{fpc_slot} of router {router_name} via shell")
result = _run_junos_cli_command(router_name, shell_command, timeout)

return [types.TextContent(type="text", text=result)]


# Tool registry mapping tool names to their handler functions
# To add a new tool:
# 1. Create an async handler function: async def handle_my_new_tool(arguments: dict) -> list[types.ContentBlock]
Expand All @@ -908,6 +926,7 @@ async def handle_load_and_commit_config(arguments: dict, context: Context) -> li
"gather_device_facts": handle_gather_device_facts,
"get_router_list": handle_get_router_list,
"load_and_commit_config": handle_load_and_commit_config,
"execute_fpc_command": handle_execute_fpc_command, # FPC command execution via cprod
"add_device": handle_add_device # Dynamic device management
}

Expand Down Expand Up @@ -1020,6 +1039,20 @@ async def list_tools() -> list[types.Tool]:
"required": ["router_name", "config_text"]
}
),
types.Tool(
name="execute_fpc_command",
description="Execute FPC commands using cprod on a Junos router",
inputSchema={
"type": "object",
"properties": {
"router_name": {"type": "string", "description": "The name of the router"},
"fpc_slot": {"type": "string", "description": "FPC slot number (e.g., '0', '1')", "default": "0"},
"fpc_command": {"type": "string", "description": "The FPC command to execute (e.g., 'show version', 'show memory')"},
"timeout": {"type": "integer", "description": "Command timeout in seconds", "default": 360}
},
"required": ["router_name", "fpc_command"]
}
),
types.Tool(
name="add_device",
description="Add a new Junos device with interactive elicitation for device details",
Expand Down