MCP Hub Extension
MCP Hub is a powerful extension that adds Model Context Protocol (MCP) support to CodeCompanion, allowing you to use MCP tools and resources in your chat interactions.
Features
- Access MCP tools via
@mcp
in chat - Use MCP resources as chat variables with
#
prefix - Execute MCP prompts via slash commands
- Real-time updates when servers change
Installation
First, install MCP Hub:
lua
{
"ravitemer/mcphub.nvim",
build = "npm install -g mcp-hub@latest",
config = function()
require("mcphub").setup()
end
}
For detailed MCP Hub configuration options, see the MCPHub documentation.
CodeCompanion Setup
Add MCP Hub as an extension in your CodeCompanion configuration:
lua
require("codecompanion").setup({
extensions = {
mcphub = {
callback = "mcphub.extensions.codecompanion",
opts = {
show_result_in_chat = true, -- Show mcp tool results in chat
make_vars = true, -- Convert resources to #variables
make_slash_commands = true, -- Add prompts as /slash commands
}
}
}
})
Usage
- Type
@mcp
to add available MCP servers to system prompts and add tool access - Use
#variable_name
to access MCP resources in chat - Use
/mcp:prompt_name
to execute MCP prompts
Resources as Variables
When make_vars = true
, MCP resources become available as chat variables. For example:
- E.g LSP current file diagnostics
Prompts as Slash Commands
When make_slash_commands = true
, MCP prompts become available as slash commands:
- Format:
/mcp:prompt_name
- Arguments are handled via vim.ui.input
Auto-approval
Tool requests can be automatically approved in several ways:
- MCPHub config:
config.auto_approve = true
- Global MCPHub setting:
vim.g.mcphub_auto_approve = true
- CodeCompanion's gta mode:
vim.g.codecompanion_auto_tool_mode = true
- Using the
gta
command in chat
The tool will respect any of these auto-approval settings.