|
| 1 | +local M = {} |
| 2 | + |
| 3 | +local SHUTDOWN_DELAY = 10 * 60 * 1000 -- 10 minutes |
| 4 | + |
| 5 | +---@class MCPHub.Config |
| 6 | +local defaults = { |
| 7 | + port = 37373, -- Default port for MCP Hub |
| 8 | + server_url = nil, -- In cases where mcp-hub is hosted somewhere, set this to the server URL e.g `http://mydomain.com:customport` or `https://url_without_need_for_port.com` |
| 9 | + config = vim.fn.expand("~/.config/mcphub/servers.json"), -- Default config location |
| 10 | + shutdown_delay = SHUTDOWN_DELAY, -- Delay before shutting down the mcp-hub |
| 11 | + ---@type table<string, NativeServerDef> |
| 12 | + native_servers = {}, |
| 13 | + auto_approve = false, |
| 14 | + auto_toggle_mcp_servers = true, -- Let LLMs start and stop MCP servers automatically |
| 15 | + use_bundled_binary = false, -- Whether to use bundled mcp-hub binary |
| 16 | + ---@type string? |
| 17 | + cmd = nil, -- will be set based on system if not provided |
| 18 | + ---@type table? |
| 19 | + cmdArgs = nil, -- will be set based on system if not provided |
| 20 | + ---@type LogConfig |
| 21 | + log = { |
| 22 | + level = vim.log.levels.ERROR, |
| 23 | + to_file = false, |
| 24 | + file_path = nil, |
| 25 | + prefix = "MCPHub", |
| 26 | + }, |
| 27 | + ---@type MCPHub.UIConfig |
| 28 | + ui = { |
| 29 | + window = { |
| 30 | + width = 0.85, -- 0-1 (ratio); "50%" (percentage); 50 (raw number) |
| 31 | + height = 0.85, -- 0-1 (ratio); "50%" (percentage); 50 (raw number) |
| 32 | + border = "rounded", -- "none", "single", "double", "rounded", "solid", "shadow" |
| 33 | + relative = "editor", |
| 34 | + zindex = 50, |
| 35 | + }, |
| 36 | + }, |
| 37 | + extensions = { |
| 38 | + avante = { |
| 39 | + enabled = true, |
| 40 | + make_slash_commands = true, |
| 41 | + }, |
| 42 | + }, |
| 43 | + on_ready = function() end, |
| 44 | + ---@param msg string |
| 45 | + on_error = function(msg) end, |
| 46 | +} |
| 47 | + |
| 48 | +---@param opts MCPHub.Config? |
| 49 | +---@return MCPHub.Config |
| 50 | +function M.setup(opts) |
| 51 | + M.config = vim.tbl_deep_extend("force", defaults, opts or {}) |
| 52 | + return M.config |
| 53 | +end |
| 54 | + |
| 55 | +return setmetatable(M, { |
| 56 | + __index = function(_, key) |
| 57 | + if key == "setup" then |
| 58 | + return M.setup |
| 59 | + end |
| 60 | + return rawget(M.config, key) |
| 61 | + end, |
| 62 | +}) |
0 commit comments