Skip to content

Commit f3f6fd5

Browse files
committed
feat:native server config fields can also be edited from UI
1 parent 224374a commit f3f6fd5

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

lua/mcphub/ui/views/main.lua

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,19 @@ function MainView:handle_edit()
137137
local cursor = vim.api.nvim_win_get_cursor(0)
138138
local line = cursor[1]
139139

140-
local type, context = self:get_line_info(line)
141-
if not type or not context then
140+
local line_type, context = self:get_line_info(line)
141+
if not line_type or not context then
142142
return
143143
end
144144
local server_name = context.name
145-
if type == "server" then
145+
if line_type == "server" then
146146
local is_native = native.is_native_server(server_name)
147+
local config
147148
if is_native then
148-
return vim.notify("Native servers cannot be edited")
149+
config = State.native_servers_config[server_name] or {}
150+
else
151+
config = State.servers_config[server_name] or {}
149152
end
150-
local config = State.servers_config[server_name] or {}
151153
local text = utils.pretty_json(vim.json.encode({
152154
[server_name] = config,
153155
}) or "")
@@ -186,15 +188,27 @@ function MainView:handle_edit()
186188
local new_name, new_config = next(result)
187189
---@cast new_name string
188190
---@cast new_config table
189-
local valid = validation.validate_server_config(new_name, new_config)
190-
if not valid.ok then
191-
vim.notify(valid.error.message, vim.log.levels.ERROR)
192-
return false
191+
192+
-- For native servers, we only need to validate basic structure
193+
-- since they don't require command/url fields
194+
if is_native then
195+
if type(new_config) ~= "table" then
196+
vim.notify("Config must be a table", vim.log.levels.ERROR)
197+
return false
198+
end
199+
-- Native servers only need basic config validation
200+
return true
201+
else
202+
local valid = validation.validate_server_config(new_name, new_config)
203+
if not valid.ok then
204+
vim.notify(valid.error.message, vim.log.levels.ERROR)
205+
return false
206+
end
193207
end
194208
return true
195209
end,
196210
})
197-
elseif (type == "customInstructions") and context then
211+
elseif (line_type == "customInstructions") and context then
198212
self:handle_custom_instructions(context)
199213
end
200214
end
@@ -212,7 +226,7 @@ function MainView:handle_delete()
212226
local server_name = context.name
213227
local is_native = native.is_native_server(server_name)
214228
if is_native then
215-
return vim.notify("Native servers cannot be deleted")
229+
return vim.notify("Native servers cannot be deleted, only their configuration can be edited")
216230
end
217231

218232
-- Using vim.ui.select instead of vim.fn.confirm

lua/mcphub/utils/renderer.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,12 @@ function M.render_server_capabilities(server, lines, current_line, config_source
171171
current_line = current_line + 1
172172

173173
-- Prepare hover hint based on server status
174-
local hint = is_native and "[<t> Toggle]" or "[<t> Toggle, <e> Edit, <d> Delete]"
174+
local hint = is_native and "[<t> Toggle, <e> Edit]" or "[<t> Toggle, <e> Edit, <d> Delete]"
175175
local needs_authorization = server.status == "unauthorized"
176-
local enabled_hint = is_native and "[<l> Expand, <t> Toggle]"
176+
local enabled_hint = is_native and "[<l> Expand, <t> Toggle, <e> Edit]"
177177
or needs_authorization and "[<l> Authorize, <t> Toggle, <e> Edit, <d> Delete]"
178178
or "[<l> Expand, <t> Toggle, <e> Edit, <d> Delete]"
179-
local expanded_hint = is_native and "[<h> Collapse, <t> Toggle]"
179+
local expanded_hint = is_native and "[<h> Collapse, <t> Toggle, <e> Edit]"
180180
or "[<h> Collapse, <t> Toggle, <e> Edit, <d> Delete]"
181181
if server.status ~= "disabled" and server.status ~= "disconnected" then
182182
hint = view.expanded_server == server.name and expanded_hint or enabled_hint

0 commit comments

Comments
 (0)