Skip to content

Server crashes with ModuleNotFoundError: No module named 'mcp' when optional fastmcp dependency is not installed #2794

Description

@unlikeneptunev

The server fails to start when the optional fastmcp dependency is not installed. The MCP feature routes are imported unconditionally in multiple locations without a guard for ModuleNotFoundError, even though fastmcp is marked as an optional dependency in packaging metadata (confirmed on the Arch Linux AUR package, where fastmcp is listed under Optional Deps, not Depends On).

This differs from the handling of the AI Copilot feature in the same codebase, where the missing langchain_core dependency is caught and logged as a warning, allowing the server to continue running with that feature disabled. The MCP feature does not follow the same pattern.

To Reproduce

  1. Install gns3-server 3.1.0a3 without the optional fastmcp / mcp package installed.
  2. Run gns3server from the terminal.
  3. Server starts initializing, passes initial config and database migration steps, then crashes during the FastAPI lifespan startup phase.

Expected behavior

The server should start successfully with MCP routes disabled and log a warning, consistent with how the AI Copilot feature degrades gracefully.

Error output

First failure point, at import time in gns3server/api/server.py:

File "/usr/lib/python3.14/site-packages/gns3server/api/server.py", line 48, in <module>
    from gns3server.api.routes import mcp
  File "/usr/lib/python3.14/site-packages/gns3server/api/routes/mcp/__init__.py", line 42, in <module>
    from mcp.server.fastmcp import FastMCP
ModuleNotFoundError: No module named 'mcp'

After patching the import in server.py (wrapping in try/except and guarding the two usages at router registration and Starlette route registration), a second unguarded import surfaces at runtime in gns3server/core/tasks.py, inside the startup() lifespan function:

File "/usr/lib/python3.14/site-packages/gns3server/core/tasks.py", line 88, in startup
    from gns3server.api.routes.mcp import set_mcp_server_ready
  File "/usr/lib/python3.14/site-packages/gns3server/api/routes/mcp/__init__.py", line 42, in <module>
    from mcp.server.fastmcp import FastMCP
ModuleNotFoundError: No module named 'mcp'

Environment

  • GNS3 server version: 3.1.0a3
  • OS: CachyOS (Arch-based), installed via AUR (with paru) package gns3-server
  • Python: 3.14.6

Workaround

Manually wrapping all four unguarded references to the mcp module (one import and one router registration in server.py, one import and one function call in tasks.py) in try/except ModuleNotFoundError blocks allows the server to start normally with MCP routes disabled. Happy to share the exact patch if useful.

Suggested fix

Apply the same graceful-degradation pattern already used for the AI Copilot dependency check to the MCP feature imports, in both gns3server/api/server.py and gns3server/core/tasks.py.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions