6955 Commits

Author SHA1 Message Date
YueGuobin
d431ff6eaa
feat: Log registered MCP tools at startup 2026-06-10 22:53:51 +08:00
YueGuobin
658a8d112b
docs: Clarify compute tools descriptions about local compute vs database computes
compute_list and compute_get only return database-registered computes.
The built-in local compute is returned by server_statistics instead.
2026-06-10 22:44:54 +08:00
YueGuobin
8b014693a8
fix: Type compute_id as uuid.UUID to reject non-UUID values at MCP input layer
Previously compute_id was typed as str, so 'local' would pass MCP validation
and reach the controller API where it crashed. Now uuid.UUID type ensures
Pydantic rejects any non-UUID string before the handler runs.
2026-06-10 22:38:38 +08:00
YueGuobin
67fa65a9e0
fix: Require UUID for compute_get/images, remove 'local' string default
The end /v3/computes/{compute_id} expects the compute_id to be a
valid UUID. Previously the MCP tool defaulted to the string 'local',
which caused a ValueError in the database layer. Now compute_id is
required and callers must use compute_list first to resolve names to UUIDs.
2026-06-10 22:31:17 +08:00
YueGuobin
e7038f1ae3
feat: Add device configuration MCP tools (config_send, command_run, vpcs_config_set)
- Add jwt_token/url parameters to get_device_ports_from_topology() and GNS3TopologyTool
  for MCP handler compatibility (backward compatible, auto-detection fallback)
- Add jwt_token/url pass-through to ExecuteMultipleDeviceConfigCommands,
  ExecuteMultipleDeviceCommands, and VPCSCommands _run() methods
- Create MCP handler device_config.py wrapping the 3 device config tools
- Register as device_config_send, device_command_run, vpcs_config_set
2026-06-10 14:34:35 +08:00
YueGuobin
87e14cc49e
refactor: unify MCP tool naming to <module>_<action> convention
All 79 tools renamed for consistent alphabetical grouping:
- project_list, project_get, project_create, project_delete ...
- node_list, node_get, node_start, node_stop, node_file_list ...
- link_list, link_create, link_capture_start, link_capture_stop ...
- template_list, template_get ...
- snapshot_list, snapshot_create, snapshot_delete ...
- drawing_list, drawing_create, drawing_update ...
- symbol_list, symbol_get, symbol_upload ...
- appliance_list, appliance_get ...
- image_list, image_get, image_delete ...
- server_version, server_statistics ...
- compute_list, compute_get, compute_images ...
2026-06-10 14:07:34 +08:00
YueGuobin
41594faf43
feat: Add symbol upload/delete, project load, and locked check MCP tools 2026-06-10 13:59:39 +08:00
YueGuobin
b786f0b7eb
feat: Add image management MCP tools
- Image tools: get_images, get_image, delete_image, prune_images, install_images
2026-06-10 13:58:42 +08:00
YueGuobin
e4d2faec37
feat: Add symbol and appliance MCP tools
- Symbol tools: get_symbols, get_symbol, get_symbol_dimensions, get_default_symbols
- Appliance tools: get_appliances, get_appliance, install_appliance
2026-06-10 13:57:52 +08:00
YueGuobin
db9f645c98
feat: Add node bulk ops, project lock, and server info MCP tools
- Node bulk: start_all_nodes, stop_all_nodes, suspend_all_nodes, reload_all_nodes
- Node advanced: duplicate_node, isolate_node, unisolate_node, get_node_links
- Project: lock_project, unlock_project
- Server: get_version, get_statistics
2026-06-10 13:56:43 +08:00
YueGuobin
e7fbb3ec10
feat: Add snapshot and drawing MCP tools
- Add snapshot tools: get_snapshots, create_snapshot, delete_snapshot, restore_snapshot
- Add drawing tools: get_drawings, create_drawing, get_drawing, update_drawing, delete_drawing
2026-06-10 13:55:13 +08:00
YueGuobin
acce79d243
refactor: unify MCP handlers to use http_call directly, relocate node file ops to Node class
- Move node file operations (list_files, delete_file) from Gns3Connector to Node class
- Add link capture/reset operations (reset, start_capture, stop_capture) to Link class
- Convert all MCP handlers to use conn.http_call() directly instead of
  Gns3Connector/Node/Link abstraction methods
- Register 4 new MCP tools: reset_link, start_capture, stop_capture,
  download_capture_file
2026-06-10 13:47:10 +08:00
YueGuobin
28b06f37c4
feat: Add node file operations as MCP tools (list, get, write, delete)
- Add list_node_files, get_node_file, write_node_file, delete_node_file methods to Gns3Connector
- Add MCP handlers with offset/limit line-based reading for get_node_file
- Auto-truncate files >50KB with truncated flag in response
- Rich metadata returned (total_lines, total_bytes, has_more, etc.)
- Tool docstrings guide AI to check file sizes before reading chunked
2026-06-10 12:16:35 +08:00
YueGuobin
066b7076c0
Add comment about rootful Docker permissions at container start
Rootful Docker recreates volume mount points as root on start,
preventing the GNS3 process from writing files into node directories
while the container is running. self._fix_permissions() would resolve
this but is currently only called at container stop time.
2026-06-10 00:46:10 +08:00
YueGuobin
ce95c89b64
Fix _fix_permissions test: set process.returncode=0 and update assertion
- Set returncode=0 on mock process to follow the success path
- Update assertion to include stderr=asyncio.subprocess.PIPE parameter
2026-06-10 00:44:12 +08:00
YueGuobin
eb15c7138b
Fix list_node_files PermissionError on os.scandir
Wrap os.scandir() in try-except to return empty list instead of
crashing when a node directory is not readable.
2026-06-10 00:15:26 +08:00
YueGuobin
1a307edbca
Fix _fix_permissions error handling and list_node_files PermissionError
- _fix_permissions: capture stderr, check returncode, only set
  _permissions_fixed on success instead of silently marking as fixed
- list_node_files: wrap os.scandir in try-except to handle
  PermissionError gracefully
2026-06-10 00:14:40 +08:00
YueGuobin
e659b64bf0
Add async_iterable_to_stream utility to avoid aiohttp compatibility issues
Create async_iterable_to_stream() in gns3server.utils.asyncio that
converts an async iterable to an aiohttp StreamReader via a background
feeder task. This bypasses aiohttp's AsyncIterablePayload which can
cause 'Connection reset by peer' with certain HTTP servers.

Use it in _run_http_query for the __aiter__ data path.
2026-06-09 23:55:59 +08:00
YueGuobin
8e340f0ce8
Add descriptive detail to 403 errors in compute file endpoints
Both is_safe_path rejection and PermissionError were returning 403
without a detail message, making them indistinguishable in logs.
Add specific detail strings to each:
- is_safe_path: 'Path is outside the project directory'
- PermissionError (write): 'Permission denied writing to ...'
- PermissionError (delete): 'Permission denied deleting ...'
2026-06-09 23:33:35 +08:00
YueGuobin
16a9064eb8
Fix silent file write failure in write_compute_project_file
The inner try-except caught OSError/UnicodeEncodeError with 'pass',
silently swallowing all write failures and returning HTTP 204 as if
the file was written successfully.

Remove the nested try-except and let errors propagate properly:
- OSError → 500 with error detail
- PermissionError → 403 (already handled)
- FileNotFoundError → 404 (already handled)
2026-06-09 23:27:45 +08:00
YueGuobin
cbb21e8e40
feat: Node file streaming, recursive listing, file type detection, and file delete
- Stream file GET/POST through controller without buffering in memory
- Add recursive and subdirectory filtering to node file listing
- Replace file extension with magic-based file type detection
- Add DELETE endpoint for node and project files
- Include directories in listing response
- Add params and stream support to http_query
- Fix lambda closures, streamer exception scope, and delete error codes
2026-06-09 22:52:50 +08:00
Jeremy Grossmann
c70a4660c1
Merge pull request #2777 from yueguobin/mcp/project-tools
Add MCP project tools: update, duplicate, and README operations
2026-06-07 18:11:16 +02:00
YueGuobin
f91d7b18e9
Update README tool descriptions: .txt → .md
Only description strings changed to tell AI the content is Markdown
format (.md). The actual handler still reads/writes README.txt for
Web UI compatibility.
2026-06-07 23:32:26 +08:00
YueGuobin
4ca1a80adb
Update README tool descriptions to mention Markdown format
Web UI supports rendering Markdown in README.txt, so note this in the
tool descriptions and content parameter.
2026-06-07 23:23:38 +08:00
YueGuobin
4921b98948
Add MCP project tools: update, duplicate, and README operations
- Add update_project and duplicate_project MCP tools
- Add get_project_readme and update_project_readme tools
- Add Gns3Connector methods: update_project, duplicate_project,
  get_project_file, write_project_file
2026-06-07 23:14:07 +08:00
grossmj
95b1a35300
Development on 3.1.0.dev4 2026-06-07 00:13:59 +02:00
grossmj
aad66e8ede
Release v3.1.0a3 v3.1.0a3 2026-06-06 23:19:24 +02:00
grossmj
259b7824af
Bundle web-ui v3.1.0a3 2026-06-06 23:11:04 +02:00
grossmj
bd22911066
Sync appliances 2026-06-06 22:53:12 +02:00
Jeremy Grossmann
c6a6cd9ad9
Merge pull request #2776 from yueguobin/fix/mcp-template-update-kwargs-handling
Fix MCP tool parameter handling for nested kwargs
2026-06-06 18:52:12 +02:00
Guobin Yue
fbe6b280d5
Merge branch '3.1' into fix/mcp-template-update-kwargs-handling 2026-06-07 00:37:02 +08:00
YueGuobin
012df5af57
docs: add simplified MCP tool description guide to project memory
Added a focused, concise memory document about MCP tool description
location. Simplified from 180 lines to 45 lines to capture only the
essential information needed for future conversations.

Key points documented:
- MCP tool descriptions are defined in @mcp.tool() functions in __init__.py
- NOT in *_TOOLS arrays in individual module files
- Must restart GNS3 server to see description updates
- Description requirements: explicit formats, ranges, and examples

This replaces the verbose 180-line version with a practical 45-line
guide focused on answering: 'Where should I write tool descriptions so
the AI can see them?'
2026-06-07 00:32:39 +08:00
YueGuobin
1f985a2823
fix: update MCP link tools descriptions with detailed filter info
Updated the actual MCP tool definitions in __init__.py with detailed
filter parameter descriptions. The previous update to links.py was incorrect
because MCP tools are defined via @mcp.tool() decorators in __init__.py.

Changes:
- Updated update_link tool docstring with comprehensive filter information
- Updated create_link tool filters parameter description
- Added all 5 filter types with proper array format requirements
- Added parameter ranges and usage examples

Filters now properly documented:
- frequency_drop: [N] (N: -1 to 32767)
- packet_loss: [rate] (rate: 0 to 100)
- delay: [ms, jitter] (milliseconds)
- corrupt: [rate] (rate: 0 to 100)
- bpf: [expression] (BPF syntax)

This will prevent TypeError: 'int' object is not iterable errors and
help users understand the correct filter format.
2026-06-07 00:20:29 +08:00
YueGuobin
eac6c9f17d
docs: improve MCP link tools filter parameter descriptions
Updated the filters parameter description in create_link and update_link
MCP tools to specify the required array format and provide examples.

Changes:
- Updated create_link filters description with array format requirements
- Updated update_link filters description with array format and example
- Added specific filter types: frequency_drop, packet_loss, delay, corrupt, bpf

This helps users understand the correct format:
- frequency_drop: [N] (drop every Nth packet)
- packet_loss: [rate] (packet loss percentage)
- delay: [ms, jitter] (latency and jitter in milliseconds)
- corrupt: [rate] (packet corruption percentage)
- bpf: [expression] (Berkeley Packet Filter)

Prevents TypeError: 'int' object is not iterable errors.
2026-06-06 23:46:22 +08:00
YueGuobin
3ba11c8bff
fix: correct MCP nodes and links tool parameter handling for nested kwargs
Extended the kwargs parameter handling fix to nodes and links MCP tools,
which had the same nested kwargs structure issue as templates.

Changes:
- Modified update_node_handler to extract params from nested kwargs
- Modified update_link_handler to extract params from nested kwargs

This ensures that node and link updates through MCP tools work correctly,
allowing proper modification of node and link properties.
2026-06-06 23:31:32 +08:00
YueGuobin
0d22d275fb
fix: correct MCP template tool parameter handling for nested kwargs
Fixed an issue where MCP template tools (update_template, create_template)
were not correctly handling nested kwargs parameter structure from MCP clients.

The problem occurred when MCP clients passed parameters in the format:
  {'template_id': 'xxx', 'kwargs': {'adapters': 3}}

The original code was passing the entire kwargs dictionary as a parameter,
instead of extracting the actual update parameters from within it.

Changes:
- Modified update_template_handler to extract params from nested kwargs
- Modified create_template_handler to handle the same issue

This fix ensures that template updates through MCP tools now work correctly,
allowing proper modification of template properties like adapters count.
2026-06-06 23:26:21 +08:00
Jeremy Grossmann
93293a327d
Merge pull request #2775 from yueguobin/fix/mcp-initialization-ready-check
Feature: add MCP server initialization check with ready state tracking
2026-06-06 16:56:18 +02:00
Guobin Yue
0a97e85a21
Merge branch '3.1' into fix/mcp-initialization-ready-check 2026-06-06 22:48:36 +08:00
Jeremy Grossmann
8e50d3f31b
Merge pull request #2774 from cristian-ciobanu/3.1
fix(templates): Database error detected when saving a template with a disk image change
2026-06-06 16:40:52 +02:00
YueGuobin
3958279b8a
feat: add client information logging to MCP connection rejection
Add reusable utility for extracting client information from ASGI scope:
- Create gns3server/utils/request_utils.py with extract_client_info()
- Extract client IP, port, path, method, and authenticated username
- Format comprehensive log messages with client context

Benefits:
- Better observability for connection rejection events
- Reusable utility for other modules
- Consistent client logging format across codebase
- Helps diagnose timing issues during server startup

Usage:
  from gns3server.utils.request_utils import extract_client_info
  client_info = extract_client_info(scope, auth_service)
  log.warning(f"Connection rejected - Client: {client_info['host']}:{client_info['port']} ({client_info['user_info']})")
2026-06-06 22:35:43 +08:00
YueGuobin
9e5b575d1c
refactor: replace MCP ready state polling with asyncio.Event
Replace the global variable + lock + polling mechanism with asyncio.Event
pattern for MCP server ready state tracking.

Benefits:
- Eliminates race conditions (Event.set() is thread-safe)
- Event-driven notification instead of polling (no 50x sleep overhead)
- Fixes test contamination from global state
- Reduces code from 54 lines to 30 lines
- Uses standard asyncio primitive for this pattern
2026-06-06 22:24:10 +08:00
Cristi
03b3078271 fix: revert duplicate image check to fix failing tests 2026-06-06 15:04:06 +03:00
Cristi
1e40fa1b70 fix (templates): Add ordering to handle the duplicate cases gracefully 2026-06-06 14:46:27 +03:00
Cristi
da3a34144b fix(templates): Database error detected when saving a template with a disk image change 2026-06-06 14:21:15 +03:00
YueGuobin
67a960fbce
fix: return 503 error on MCP server ready timeout
Instead of allowing connections to proceed when server initialization
times out, return HTTP 503 Service Unavailable to prevent MCP
protocol initialization errors.

This prevents the original "Received request before initialization
was complete" errors when GNS3 server startup takes longer than
the 5-second timeout.
2026-06-06 15:23:52 +08:00
YueGuobin
b1514edf88
fix: add MCP server ready check to prevent initialization errors
Add server ready state tracking for MCP service to prevent
"Received request before initialization was complete" errors
when clients connect before GNS3 server completes startup.

Changes:
- Add MCP server ready state management with wait/notify mechanism
- Modify auth wrapper to wait for server initialization before accepting connections
- Set MCP server ready flag after GNS3 startup completes

This ensures MCP protocol initialization handshake only occurs
after GNS3 server is fully initialized, preventing race
conditions during server startup.
2026-06-06 15:21:17 +08:00
Jeremy Grossmann
13d1563762
Merge pull request #2772 from yueguobin/feature/mcp-transport-security-config
feat: add configurable MCP transport security settings via gns3_server.conf
2026-06-05 19:05:23 +02:00
YueGuobin
1dcbd9199f
docs: document MCP server URL host resolution behavior
Add documentation explaining how _server_url() resolves the host
when Server.host is 0.0.0.0 or :: — using the default route
interface IP instead of hardcoding 127.0.0.1.
2026-06-06 00:52:21 +08:00
YueGuobin
db9772ca7a
fix: resolve MCP server URL host via default route IP when bound to 0.0.0.0
When GNS3 server is configured to listen on 0.0.0.0 (all interfaces),
_server_url() was hardcoding 127.0.0.1, making the WebSocket console
URL unreachable from remote MCP clients.

Use the UDP connect trick (connect to 8.8.8.8:80 without sending data)
to discover the default route interface IP, which is the address remote
clients can actually reach.
2026-06-06 00:48:22 +08:00
YueGuobin
4d87b57f18
docs: add MCP transport security documentation
Added Transport Security section to MCP service documentation covering:
- Default behaviour (disabled, allow all hosts)
- How to enable protection via gns3_server.conf
- Protection mechanism (Host header validation)
- DNS rebinding attack prevention explanation
- Behaviour summary table
2026-06-05 23:40:01 +08:00