wip: better mcphub prompting
This commit is contained in:
parent
9cce1fb0b0
commit
22b2647aea
@ -1,5 +1,11 @@
|
||||
{
|
||||
"diagnostics.disable": [
|
||||
"missing-fields"
|
||||
],
|
||||
"diagnostics.globals": [
|
||||
"vim",
|
||||
"make_avante_system_prompt",
|
||||
"update_avante_system_prompt",
|
||||
"get_server_list_prompt"
|
||||
]
|
||||
}
|
@ -545,8 +545,10 @@ vim.keymap.set("n", "<Leader>rn", vim.lsp.buf.rename)
|
||||
vim.keymap.set("n", "<Leader>sl", telescope_builtins.lsp_workspace_symbols)
|
||||
vim.keymap.set("n", "<Leader>dl", telescope_builtins.diagnostics)
|
||||
vim.keymap.set("n", "<Leader>rg", telescope_builtins.live_grep)
|
||||
vim.keymap.set("n", "<Leader>bl", function() telescope_builtins.buffers({
|
||||
}) end)
|
||||
vim.keymap.set("n", "<Leader>bl", function()
|
||||
telescope_builtins.buffers({
|
||||
})
|
||||
end)
|
||||
vim.keymap.set("n", "<leader>lds", telescope_builtins.lsp_document_symbols, { desc = "[D]ocument [S]ymbols" })
|
||||
vim.keymap.set("n", "<leader>lws", telescope_builtins.lsp_dynamic_workspace_symbols, { desc = "[W]orkspace [S]ymbols" })
|
||||
|
||||
@ -678,24 +680,65 @@ local mcphub = require("mcphub")
|
||||
mcphub.setup({
|
||||
-- This sets vim.g.mcphub_auto_approve to false by default (can also be toggled from the HUB UI with `ga`)
|
||||
config = vim.fn.expand("~/.config/mcphub/servers.json"),
|
||||
auto_approve = false,
|
||||
auto_approve = true,
|
||||
auto_toggle_mcp_servers = true, -- Let LLMs start and stop MCP servers automatically
|
||||
extensions = {
|
||||
avante = {
|
||||
make_slash_commands = true, -- make /slash commands from MCP server prompts
|
||||
}
|
||||
},
|
||||
cmd = "mcp-hub";
|
||||
},
|
||||
cmd = "mcp-hub",
|
||||
})
|
||||
|
||||
function get_server_list_prompt(hub_instance)
|
||||
-- returns a list of mcp-servers with a `name` and a list of tools with `name`
|
||||
local mcp_tool_prompt = "# MCP SERVERS\n\nThe Model Context Protocol (MCP) enables communication between the system and locally running MCP servers that provide additional tools and resources to extend your capabilities.\n\n# Connected MCP Servers\n\nWhen a server is connected, you can use the server's tools via the `use_mcp_tool` tool, and access the server's resources via the `access_mcp_resource` tool.\nNote: Server names are case sensitive and you should always use the exact full name like `Firecrawl MCP` or `src/user/main/time-mcp` etc\n\n"
|
||||
|
||||
if not hub_instance then
|
||||
return ""
|
||||
end
|
||||
|
||||
local servers = hub_instance:get_servers()
|
||||
if not servers or #servers == 0 then
|
||||
return ""
|
||||
end
|
||||
|
||||
for _, server in ipairs(servers) do
|
||||
mcp_tool_prompt = mcp_tool_prompt .. "## server name: `" .. server.name .. "`\n\n"
|
||||
|
||||
if server.capabilities.tools and #server.capabilities.tools > 0 then
|
||||
mcp_tool_prompt = mcp_tool_prompt .. "Available tools:\n\n"
|
||||
for _, tool in ipairs(server.capabilities.tools) do
|
||||
mcp_tool_prompt = mcp_tool_prompt .. "- tool name: `" .. tool.name .. "`\n"
|
||||
if tool.description then
|
||||
mcp_tool_prompt = mcp_tool_prompt .. " - Description: " .. tool.description .. "\n"
|
||||
end
|
||||
end
|
||||
mcp_tool_prompt = mcp_tool_prompt .. "\n"
|
||||
end
|
||||
end
|
||||
|
||||
return mcp_tool_prompt
|
||||
end
|
||||
|
||||
function make_avante_system_prompt(hub_instance)
|
||||
return hub_instance and get_server_list_prompt(hub_instance) or ""
|
||||
end
|
||||
|
||||
function update_avante_system_prompt()
|
||||
local hub_instance = mcphub.get_hub_instance();
|
||||
local system_prompt = make_avante_system_prompt(hub_instance)
|
||||
if system_prompt then
|
||||
require("avante.config").override({system_prompt = system_prompt})
|
||||
end
|
||||
end
|
||||
|
||||
require('copilot').setup();
|
||||
|
||||
require('avante').setup({
|
||||
provider = "claude",
|
||||
mode = "agentic",
|
||||
cursor_applying_provider = nil, -- default to whatever provide is configured
|
||||
mode = "planning",
|
||||
cursor_applying_provider = nil, -- default to whatever provider is configured
|
||||
claude = {
|
||||
endpoint = "https://api.anthropic.com",
|
||||
model = "claude-3-7-sonnet-20250219",
|
||||
@ -703,22 +746,25 @@ require('avante').setup ({
|
||||
temperature = 0,
|
||||
max_tokens = 20480,
|
||||
},
|
||||
copilot = {
|
||||
model = "claude-3.7-sonnet",
|
||||
},
|
||||
behavior = {
|
||||
enable_cursor_planning_mode = true,
|
||||
},
|
||||
system_prompt = hub_instance and hub_instance:get_active_servers_prompt() or "",
|
||||
system_prompt = make_avante_system_prompt(mcphub.get_hub_instance()),
|
||||
custom_tools = { require("mcphub.extensions.avante").mcp_tool() },
|
||||
-- Disable these because we'll use the mcphub versions instead
|
||||
disabled_tools = {
|
||||
"list_files", -- Built-in file operations
|
||||
"search_files",
|
||||
"read_file",
|
||||
"create_file",
|
||||
"rename_file",
|
||||
"delete_file",
|
||||
"create_dir",
|
||||
"rename_dir",
|
||||
"delete_dir",
|
||||
"bash", -- Built-in terminal access
|
||||
},
|
||||
--disabled_tools = {
|
||||
-- "list_files", -- Built-in file operations
|
||||
-- "search_files",
|
||||
-- "read_file",
|
||||
-- "create_file",
|
||||
-- "rename_file",
|
||||
-- "delete_file",
|
||||
-- "create_dir",
|
||||
-- "rename_dir",
|
||||
-- "delete_dir",
|
||||
-- "bash", -- Built-in terminal access
|
||||
--},
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user