Skip to content

Lualine Integration

MCP Hub provides multiple ways to integrate with lualine, with the recommended approach using global variables for optimal lazy-loading support.

Use MCPHub's global variables for a lightweight, lazy-load friendly component:

lua
require('lualine').setup {
    sections = {
        lualine_x = {
            {
                function()
                    -- Check if MCPHub is loaded
                    if not vim.g.loaded_mcphub then
                        return "󰐻 -"
                    end
                    
                    local count = vim.g.mcphub_servers_count or 0
                    local status = vim.g.mcphub_status or "stopped"
                    local executing = vim.g.mcphub_executing
                    
                    -- Show "-" when stopped
                    if status == "stopped" then
                        return "󰐻 -"
                    end
                    
                    -- Show spinner when executing, starting, or restarting
                    if executing or status == "starting" or status == "restarting" then
                        local frames = { "⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏" }
                        local frame = math.floor(vim.loop.now() / 100) % #frames + 1
                        return "󰐻 " .. frames[frame]
                    end
                    
                    return "󰐻 " .. count
                end,
                color = function()
                    if not vim.g.loaded_mcphub then
                        return { fg = "#6c7086" } -- Gray for not loaded
                    end
                    
                    local status = vim.g.mcphub_status or "stopped"
                    if status == "ready" or status == "restarted" then
                        return { fg = "#50fa7b" } -- Green for connected
                    elseif status == "starting" or status == "restarting" then  
                        return { fg = "#ffb86c" } -- Orange for connecting
                    else
                        return { fg = "#ff5555" } -- Red for error/stopped
                    end
                end,
            },
        },
    },
}

Available Global Variables

MCPHub automatically maintains these global variables:

  • vim.g.loaded_mcphub - Whether MCPHub plugin is loaded (set by plugin loader)
  • vim.g.mcphub_status - Current hub state ("starting", "ready", "stopped", etc.)
  • vim.g.mcphub_servers_count - Number of connected servers
  • vim.g.mcphub_executing - Whether a tool/resource is currently executing

Legacy: Full Component (Loads MCPHub) - DEPRECATED

⚠️ DEPRECATED: This approach will load MCPHub even with lazy loading enabled and shows a deprecation warning. Use the global variables approach above instead.

lua
require('lualine').setup {
    sections = {
        lualine_x = {
            {require('mcphub.extensions.lualine')}, -- Uses defaults
        },
    },
}

When MCP Hub is connecting:

image

When connected shows number of connected servers:

image

When a tool or resource is being called, shows spinner:

image

Legacy Component Options

The lualine component accepts the standard lualine options and the following options:

  • icon: Icon to display. (default: "󰐻")
  • colored: Enable dynamic colors (default: true)
  • colors: The color to dynamically display for each MCP Hub state
    • connecting: The color to use when MCP Hub is connecting (default: "DiagnosticWarn")
    • connected: The color to use when MCP Hub is connected (default: "DiagnosticInfo")
    • error: The color to use when MCP Hub encounters an error (default: "DiagnosticError")

Customization examples

lua
-- Custom icon
{require('mcphub.extensions.lualine'), icon = ''}

Image

lua
-- Custom colors
{
  require('mcphub.extensions.lualine'),
  colors = {
    connecting = { fg = "#ffff00" }, -- Yellow
    connected = { fg = "#00ff00" }, -- Green
    error = { fg = "#ff0000" }, -- Red
  },
}

Image

lua
-- Statically color the icon, dynamically color the status text
{require('mcphub.extensions.lualine'), icon = { '󰐻', color = {fg = '#eeeeee'}}}

Image

lua
-- Dynamically color the icon, statically color the status text
{require('mcphub.extensions.lualine'), color = {fg = '#eeeeee'}}

Image

lua
-- Disable coloring
{require('mcphub.extensions.lualine'), colored = false}

Image

Released under the MIT License.