nicolargo/glances · error · RuntimeError

The 'mcp' package is required for MCP support. Install it wi

Error message

The 'mcp' package is required for MCP support. Install it with: pip install 'glances[mcp]'

What it means

GlancesMcpServer.__init__ raises RuntimeError when the 'mcp' python package could not be imported (MCP_AVAILABLE is False). MCP support is an optional extra, so the constructor hard-fails rather than serving a broken server.

Source

Thrown at glances/outputs/glances_mcp.py:73

    MCP_DEFAULT_PATH = "/mcp"

    def __init__(self, stats, args, config):
        """Initialize the MCP server.

        Args:
            stats: GlancesStats instance.  May be None at construction time if the
                   stats manager has not been created yet; call set_stats() before
                   the server receives its first request.
            args:  Parsed command-line arguments (argparse.Namespace).
            config: Glances configuration object (GlancesConfig).
        """
        self._stats = stats
        self._args = args
        self._config = config

        if not MCP_AVAILABLE:
            raise RuntimeError(
                "The 'mcp' package is required for MCP support. Install it with: pip install 'glances[mcp]'"
            )

        self._load_config(config)

        self._mcp = FastMCP(
            "Glances",
            instructions=(
                "Glances is a cross-platform system monitoring tool. "
                "Use resources to access real-time system metrics "
                "(CPU, memory, disk, network, processes, containers, sensors, …). "
                "Use prompts to generate structured analyses of the current system state."
            ),
            transport_security=self._build_transport_security(),
        )

        self._setup_resources()
        self._setup_prompts()

View on GitHub (pinned to a240d8dfb3)

Solutions

  1. Install the extra: pip install 'glances[mcp]'.
  2. Verify with python -c 'import mcp' — resolve any ImportError it shows.
  3. For Docker, use an image/requirements that includes the mcp extra.

Example fix

# before
pip install glances
python -m glances -s --mint
# RuntimeError: The 'mcp' package is required...

# after
pip install 'glances[mcp]'
python -m glances -s --mint
Defensive patterns

Strategy: validation

Validate before calling

try:
    import mcp  # noqa
    mcp_ok = True
except ImportError:
    mcp_ok = False
if not mcp_ok:
    raise SystemExit("pip install 'glances[mcp]' before enabling MCP")

Try / catch

try:
    from glances.outputs.glances_mcp import GlancesMcpServer
    server = GlancesMcpServer(stats, args, config)
except (ImportError, RuntimeError):
    # MCP unavailable: skip MCP serving

Prevention

When it happens

Trigger: Constructing GlancesMcpServer (directly or via the --mint MCP/REST-MCP output path) in an environment where 'import mcp' failed — typically because glances was installed without the [mcp] extra.

Common situations: Running the MCP server mode in a pip install glances environment without extras; slim Docker images; CI environments testing MCP tooling.

Related errors


AI-assisted analysis of nicolargo/glances@a240d8dfb3 (2026-08-27). Data as JSON: /api/errors/8d95d9c43ddd0fd6. Report an issue: GitHub.