wip: better mcphub prompting
This commit is contained in:
parent
9cce1fb0b0
commit
22b2647aea
@ -1,5 +1,11 @@
|
|||||||
{
|
{
|
||||||
"diagnostics.disable": [
|
"diagnostics.disable": [
|
||||||
"missing-fields"
|
"missing-fields"
|
||||||
|
],
|
||||||
|
"diagnostics.globals": [
|
||||||
|
"vim",
|
||||||
|
"make_avante_system_prompt",
|
||||||
|
"update_avante_system_prompt",
|
||||||
|
"get_server_list_prompt"
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -32,15 +32,15 @@ vim.cmd("noswapfile")
|
|||||||
vim.cmd("syntax on")
|
vim.cmd("syntax on")
|
||||||
vim.cmd("filetype plugin on")
|
vim.cmd("filetype plugin on")
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, {
|
vim.api.nvim_create_autocmd({ "BufEnter", "BufWinEnter" }, {
|
||||||
pattern = {"*.qnt"},
|
pattern = { "*.qnt" },
|
||||||
callback = function(args)
|
callback = function(args)
|
||||||
vim.lsp.start({
|
vim.lsp.start({
|
||||||
name = 'quint',
|
name = 'quint',
|
||||||
cmd = {'quint-language-server', '--stdio'},
|
cmd = { 'quint-language-server', '--stdio' },
|
||||||
root_dir = vim.fs.dirname(vim.uri_from_bufnr(args.buf))
|
root_dir = vim.fs.dirname(vim.uri_from_bufnr(args.buf))
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
vim.cmd([[
|
vim.cmd([[
|
||||||
@ -76,7 +76,7 @@ au BufNewFile,BufRead *.hrl filetype indent off
|
|||||||
]])
|
]])
|
||||||
|
|
||||||
vim.cmd([[
|
vim.cmd([[
|
||||||
au BufNewFile,BufRead *.nix set tabstop=2 nosmarttab
|
au BufNewFile,BufRead *.nix set tabstop=2 nosmarttab
|
||||||
]])
|
]])
|
||||||
|
|
||||||
vim.cmd([[
|
vim.cmd([[
|
||||||
@ -148,7 +148,7 @@ local caps = vim.tbl_deep_extend(
|
|||||||
local lspconfig = require("lspconfig")
|
local lspconfig = require("lspconfig")
|
||||||
|
|
||||||
-- Typst
|
-- Typst
|
||||||
lspconfig.tinymist.setup{
|
lspconfig.tinymist.setup {
|
||||||
capabilities = caps,
|
capabilities = caps,
|
||||||
settings = {
|
settings = {
|
||||||
exportPdf = "onSave",
|
exportPdf = "onSave",
|
||||||
@ -163,11 +163,11 @@ lspconfig.nil_ls.setup {
|
|||||||
capabilities = caps,
|
capabilities = caps,
|
||||||
}
|
}
|
||||||
|
|
||||||
lspconfig.jedi_language_server.setup{}
|
lspconfig.jedi_language_server.setup {}
|
||||||
|
|
||||||
require('roslyn').setup({
|
require('roslyn').setup({
|
||||||
-- client, bufnr
|
-- client, bufnr
|
||||||
on_attach = function (_, _)
|
on_attach = function(_, _)
|
||||||
--vim.notify(vim.inspect(client))
|
--vim.notify(vim.inspect(client))
|
||||||
end,
|
end,
|
||||||
sdk_framework = "net8.0",
|
sdk_framework = "net8.0",
|
||||||
@ -234,7 +234,7 @@ vim.api.nvim_create_autocmd('LspAttach', {
|
|||||||
vim.keymap.set({ "n", "v" }, "<Leader>a", vim.lsp.buf.code_action, opts)
|
vim.keymap.set({ "n", "v" }, "<Leader>a", vim.lsp.buf.code_action, opts)
|
||||||
vim.keymap.set("n", "<Leader>f", vim.lsp.buf.format, opts)
|
vim.keymap.set("n", "<Leader>f", vim.lsp.buf.format, opts)
|
||||||
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
||||||
---@diagnostic disable-next-line: undefined-field
|
---@diagnostic disable-next-line: undefined-field
|
||||||
if client and client.server_capabilities.codelens then
|
if client and client.server_capabilities.codelens then
|
||||||
vim.lsp.codelens.refresh()
|
vim.lsp.codelens.refresh()
|
||||||
end
|
end
|
||||||
@ -243,9 +243,9 @@ vim.api.nvim_create_autocmd('LspAttach', {
|
|||||||
|
|
||||||
vim.api.nvim_create_autocmd({ 'BufEnter', 'InsertLeave', 'CursorHold' }, {
|
vim.api.nvim_create_autocmd({ 'BufEnter', 'InsertLeave', 'CursorHold' }, {
|
||||||
callback = function(args)
|
callback = function(args)
|
||||||
local clients = vim.lsp.get_clients({bufnr=args.buf})
|
local clients = vim.lsp.get_clients({ bufnr = args.buf })
|
||||||
for cid = 1, #clients do
|
for cid = 1, #clients do
|
||||||
---@diagnostic disable-next-line: undefined-field
|
---@diagnostic disable-next-line: undefined-field
|
||||||
if clients[cid].server_capabilities.codelens then
|
if clients[cid].server_capabilities.codelens then
|
||||||
vim.lsp.codelens.refresh()
|
vim.lsp.codelens.refresh()
|
||||||
break
|
break
|
||||||
@ -529,7 +529,7 @@ lean.setup {
|
|||||||
vim.keymap.set({ "n", "v" }, "<Leader>ti", function() vim.cmd("LeanInfoviewToggle") end, opts)
|
vim.keymap.set({ "n", "v" }, "<Leader>ti", function() vim.cmd("LeanInfoviewToggle") end, opts)
|
||||||
vim.keymap.set({ "n", "v" }, "<Leader>sg", function() vim.cmd("LeanGoal") end, opts)
|
vim.keymap.set({ "n", "v" }, "<Leader>sg", function() vim.cmd("LeanGoal") end, opts)
|
||||||
vim.keymap.set({ "n", "v" }, "<Leader>stg", function() vim.cmd("LeanTermGoal") end, opts)
|
vim.keymap.set({ "n", "v" }, "<Leader>stg", function() vim.cmd("LeanTermGoal") end, opts)
|
||||||
vim.api.nvim_set_option_value('omnifunc', 'v:lua.vim.lsp.omnifunc', {scope = "local", buf=bufnr})
|
vim.api.nvim_set_option_value('omnifunc', 'v:lua.vim.lsp.omnifunc', { scope = "local", buf = bufnr })
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
mappings = true,
|
mappings = true,
|
||||||
@ -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>sl", telescope_builtins.lsp_workspace_symbols)
|
||||||
vim.keymap.set("n", "<Leader>dl", telescope_builtins.diagnostics)
|
vim.keymap.set("n", "<Leader>dl", telescope_builtins.diagnostics)
|
||||||
vim.keymap.set("n", "<Leader>rg", telescope_builtins.live_grep)
|
vim.keymap.set("n", "<Leader>rg", telescope_builtins.live_grep)
|
||||||
vim.keymap.set("n", "<Leader>bl", function() telescope_builtins.buffers({
|
vim.keymap.set("n", "<Leader>bl", function()
|
||||||
}) end)
|
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>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" })
|
vim.keymap.set("n", "<leader>lws", telescope_builtins.lsp_dynamic_workspace_symbols, { desc = "[W]orkspace [S]ymbols" })
|
||||||
|
|
||||||
@ -572,67 +574,67 @@ require('lualine').setup {
|
|||||||
},
|
},
|
||||||
sections = {
|
sections = {
|
||||||
-- left side
|
-- left side
|
||||||
lualine_a = {'mode'},
|
lualine_a = { 'mode' },
|
||||||
lualine_b = {'filename'},
|
lualine_b = { 'filename' },
|
||||||
lualine_c = {'encoding', 'fileformat', 'filetype'},
|
lualine_c = { 'encoding', 'fileformat', 'filetype' },
|
||||||
-- right side
|
-- right side
|
||||||
lualine_x = {'diagnostics'},
|
lualine_x = { 'diagnostics' },
|
||||||
lualine_y = {'progress', 'lsp_progress'},
|
lualine_y = { 'progress', 'lsp_progress' },
|
||||||
lualine_z = {'location'}
|
lualine_z = { 'location' }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Hunk diff tree viewer and editor. Replacement for Meld and company
|
-- Hunk diff tree viewer and editor. Replacement for Meld and company
|
||||||
local hunk = require("hunk")
|
local hunk = require("hunk")
|
||||||
hunk.setup({
|
hunk.setup({
|
||||||
keys = {
|
keys = {
|
||||||
global = {
|
global = {
|
||||||
quit = { "q" },
|
quit = { "q" },
|
||||||
accept = { "<leader><Cr>" },
|
accept = { "<leader><Cr>" },
|
||||||
focus_tree = { "<leader>e" },
|
focus_tree = { "<leader>e" },
|
||||||
|
},
|
||||||
|
|
||||||
|
tree = {
|
||||||
|
expand_node = { "l", "<Right>" },
|
||||||
|
collapse_node = { "h", "<Left>" },
|
||||||
|
|
||||||
|
open_file = { "<Cr>" },
|
||||||
|
|
||||||
|
toggle_file = { "a" },
|
||||||
|
},
|
||||||
|
|
||||||
|
diff = {
|
||||||
|
toggle_line = { "a" },
|
||||||
|
toggle_hunk = { "A" },
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
tree = {
|
ui = {
|
||||||
expand_node = { "l", "<Right>" },
|
tree = {
|
||||||
collapse_node = { "h", "<Left>" },
|
-- Mode can either be `nested` or `flat`
|
||||||
|
mode = "nested",
|
||||||
open_file = { "<Cr>" },
|
width = 35,
|
||||||
|
},
|
||||||
toggle_file = { "a" },
|
--- Can be either `vertical` or `horizontal`
|
||||||
|
layout = "vertical",
|
||||||
},
|
},
|
||||||
|
|
||||||
diff = {
|
icons = {
|
||||||
toggle_line = { "a" },
|
selected = "",
|
||||||
toggle_hunk = { "A" },
|
deselected = "",
|
||||||
|
partially_selected = "",
|
||||||
|
|
||||||
|
folder_open = "",
|
||||||
|
folder_closed = "",
|
||||||
},
|
},
|
||||||
},
|
|
||||||
|
|
||||||
ui = {
|
-- Called right after each window and buffer are created.
|
||||||
tree = {
|
--hooks = {
|
||||||
-- Mode can either be `nested` or `flat`
|
-- ---@param _context { buf: number, tree: NuiTree, opts: table }
|
||||||
mode = "nested",
|
-- on_tree_mount = function(_context) end,
|
||||||
width = 35,
|
-- ---@param _context { buf: number, win: number }
|
||||||
},
|
-- on_diff_mount = function(_context) end,
|
||||||
--- Can be either `vertical` or `horizontal`
|
--},
|
||||||
layout = "vertical",
|
|
||||||
},
|
|
||||||
|
|
||||||
icons = {
|
|
||||||
selected = "",
|
|
||||||
deselected = "",
|
|
||||||
partially_selected = "",
|
|
||||||
|
|
||||||
folder_open = "",
|
|
||||||
folder_closed = "",
|
|
||||||
},
|
|
||||||
|
|
||||||
-- Called right after each window and buffer are created.
|
|
||||||
--hooks = {
|
|
||||||
-- ---@param _context { buf: number, tree: NuiTree, opts: table }
|
|
||||||
-- on_tree_mount = function(_context) end,
|
|
||||||
-- ---@param _context { buf: number, win: number }
|
|
||||||
-- on_diff_mount = function(_context) end,
|
|
||||||
--},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
local dap = require('dap')
|
local dap = require('dap')
|
||||||
@ -678,47 +680,91 @@ local mcphub = require("mcphub")
|
|||||||
mcphub.setup({
|
mcphub.setup({
|
||||||
-- This sets vim.g.mcphub_auto_approve to false by default (can also be toggled from the HUB UI with `ga`)
|
-- 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"),
|
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
|
auto_toggle_mcp_servers = true, -- Let LLMs start and stop MCP servers automatically
|
||||||
extensions = {
|
extensions = {
|
||||||
avante = {
|
avante = {
|
||||||
make_slash_commands = true, -- make /slash commands from MCP server prompts
|
make_slash_commands = true, -- make /slash commands from MCP server prompts
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
cmd = "mcp-hub";
|
cmd = "mcp-hub",
|
||||||
})
|
})
|
||||||
|
|
||||||
local hub_instance = mcphub.get_hub_instance();
|
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('copilot').setup();
|
||||||
|
|
||||||
require('avante').setup ({
|
require('avante').setup({
|
||||||
provider = "claude",
|
provider = "claude",
|
||||||
mode = "agentic",
|
mode = "planning",
|
||||||
cursor_applying_provider = nil, -- default to whatever provide is configured
|
cursor_applying_provider = nil, -- default to whatever provider is configured
|
||||||
claude = {
|
claude = {
|
||||||
endpoint = "https://api.anthropic.com",
|
endpoint = "https://api.anthropic.com",
|
||||||
model = "claude-3-7-sonnet-20250219",
|
model = "claude-3-7-sonnet-20250219",
|
||||||
timeout = 30000, -- Timeout in milliseconds
|
timeout = 30000, -- Timeout in milliseconds
|
||||||
temperature = 0,
|
temperature = 0,
|
||||||
max_tokens = 20480,
|
max_tokens = 20480,
|
||||||
|
},
|
||||||
|
copilot = {
|
||||||
|
model = "claude-3.7-sonnet",
|
||||||
},
|
},
|
||||||
behavior = {
|
behavior = {
|
||||||
enable_cursor_planning_mode = true,
|
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() },
|
custom_tools = { require("mcphub.extensions.avante").mcp_tool() },
|
||||||
-- Disable these because we'll use the mcphub versions instead
|
-- Disable these because we'll use the mcphub versions instead
|
||||||
disabled_tools = {
|
--disabled_tools = {
|
||||||
"list_files", -- Built-in file operations
|
-- "list_files", -- Built-in file operations
|
||||||
"search_files",
|
-- "search_files",
|
||||||
"read_file",
|
-- "read_file",
|
||||||
"create_file",
|
-- "create_file",
|
||||||
"rename_file",
|
-- "rename_file",
|
||||||
"delete_file",
|
-- "delete_file",
|
||||||
"create_dir",
|
-- "create_dir",
|
||||||
"rename_dir",
|
-- "rename_dir",
|
||||||
"delete_dir",
|
-- "delete_dir",
|
||||||
"bash", -- Built-in terminal access
|
-- "bash", -- Built-in terminal access
|
||||||
},
|
--},
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user