diff --git a/lua/opencode/api.lua b/lua/opencode/api.lua index 312d2bcc..e9728395 100644 --- a/lua/opencode/api.lua +++ b/lua/opencode/api.lua @@ -474,7 +474,7 @@ function M.mcp() local info = require('opencode.config_file') local mcp = info.get_mcp_servers() if not mcp then - ui.notify('No MCP configuration found. Please check your opencode config file.', 'warn') + vim.notify('No MCP configuration found. Please check your opencode config file.', vim.log.levels.WARN) return end @@ -484,11 +484,18 @@ function M.mcp() local msg = M.with_header({ '### Available MCP servers', '', - '| Name | Type | cmd |', - '|--------|------|-----|', + '| Name | Type | cmd/url |', + '|--------|------|---------|', }) for name, def in pairs(mcp) do + local cmd_or_url + if def.type == 'local' then + cmd_or_url = def.command and table.concat(def.command, ' ') + elseif def.type == 'remote' then + cmd_or_url = def.url + end + table.insert( msg, string.format( @@ -496,7 +503,7 @@ function M.mcp() (def.enabled and icons.get('status_on') or icons.get('status_off')), name, def.type, - table.concat(def.command, ' ') + cmd_or_url ) ) end diff --git a/tests/unit/api_spec.lua b/tests/unit/api_spec.lua index 8d4060ed..7dc6aa08 100644 --- a/tests/unit/api_spec.lua +++ b/tests/unit/api_spec.lua @@ -214,4 +214,66 @@ describe('opencode.api', function() }) end) end) + + describe('/mcp command', function() + it('displays MCP server configuration when available', function() + local config_file = require('opencode.config_file') + local original_get_mcp_servers = config_file.get_mcp_servers + + config_file.get_mcp_servers = function() + return { + filesystem = { + type = 'local', + enabled = true, + command = { 'npx', '-y', '@modelcontextprotocol/server-filesystem' }, + }, + github = { + type = 'remote', + enabled = false, + url = 'https://example.com/mcp', + }, + } + end + + stub(ui, 'render_lines') + stub(api, 'open_input') + + api.mcp() + + assert.stub(api.open_input).was_called() + assert.stub(ui.render_lines).was_called() + + local render_args = ui.render_lines.calls[1].refs[1] + local rendered_text = table.concat(render_args, '\n') + + assert.truthy(rendered_text:match('Available MCP servers')) + assert.truthy(rendered_text:match('filesystem')) + assert.truthy(rendered_text:match('github')) + assert.truthy(rendered_text:match('local')) + assert.truthy(rendered_text:match('remote')) + + config_file.get_mcp_servers = original_get_mcp_servers + end) + + it('shows warning when no MCP configuration exists', function() + local config_file = require('opencode.config_file') + local original_get_mcp_servers = config_file.get_mcp_servers + + config_file.get_mcp_servers = function() + return nil + end + + local notify_stub = stub(vim, 'notify') + + api.mcp() + + assert.stub(notify_stub).was_called_with( + 'No MCP configuration found. Please check your opencode config file.', + vim.log.levels.WARN + ) + + config_file.get_mcp_servers = original_get_mcp_servers + notify_stub:revert() + end) + end) end)