@@ -214,4 +214,66 @@ describe('opencode.api', function()
214214 })
215215 end )
216216 end )
217+
218+ describe (' /mcp command' , function ()
219+ it (' displays MCP server configuration when available' , function ()
220+ local config_file = require (' opencode.config_file' )
221+ local original_get_mcp_servers = config_file .get_mcp_servers
222+
223+ config_file .get_mcp_servers = function ()
224+ return {
225+ filesystem = {
226+ type = ' local' ,
227+ enabled = true ,
228+ command = { ' npx' , ' -y' , ' @modelcontextprotocol/server-filesystem' },
229+ },
230+ github = {
231+ type = ' remote' ,
232+ enabled = false ,
233+ url = ' https://example.com/mcp' ,
234+ },
235+ }
236+ end
237+
238+ stub (ui , ' render_lines' )
239+ stub (api , ' open_input' )
240+
241+ api .mcp ()
242+
243+ assert .stub (api .open_input ).was_called ()
244+ assert .stub (ui .render_lines ).was_called ()
245+
246+ local render_args = ui .render_lines .calls [1 ].refs [1 ]
247+ local rendered_text = table.concat (render_args , ' \n ' )
248+
249+ assert .truthy (rendered_text :match (' Available MCP servers' ))
250+ assert .truthy (rendered_text :match (' filesystem' ))
251+ assert .truthy (rendered_text :match (' github' ))
252+ assert .truthy (rendered_text :match (' local' ))
253+ assert .truthy (rendered_text :match (' remote' ))
254+
255+ config_file .get_mcp_servers = original_get_mcp_servers
256+ end )
257+
258+ it (' shows warning when no MCP configuration exists' , function ()
259+ local config_file = require (' opencode.config_file' )
260+ local original_get_mcp_servers = config_file .get_mcp_servers
261+
262+ config_file .get_mcp_servers = function ()
263+ return nil
264+ end
265+
266+ local notify_stub = stub (vim , ' notify' )
267+
268+ api .mcp ()
269+
270+ assert .stub (notify_stub ).was_called_with (
271+ ' No MCP configuration found. Please check your opencode config file.' ,
272+ vim .log .levels .WARN
273+ )
274+
275+ config_file .get_mcp_servers = original_get_mcp_servers
276+ notify_stub :revert ()
277+ end )
278+ end )
217279end )
0 commit comments