@@ -40,118 +40,25 @@ func TestGetSupportedMCPConfig(t *testing.T) {
4040 assert .Contains (t , err .Error (), "failed to decode mcp file" )
4141 })
4242
43- t .Run ("stdio servers always included " , func (t * testing.T ) {
43+ t .Run ("empty file returns warning and empty slice " , func (t * testing.T ) {
4444 tmpDir := t .TempDir ()
45- mcpFile := filepath .Join (tmpDir , "mcp.json" )
46- // Claude MCP format: mcpServers is a map with server name as key
47- mcpContent := `{
48- "mcpServers": {
49- "test-stdio": {
50- "command": "/usr/bin/test",
51- "args": ["--stdio"],
52- "env": {
53- "DEBUG": "true"
54- }
55- }
56- }
57- }`
58- err := os .WriteFile (mcpFile , []byte (mcpContent ), 0o644 )
45+ mcpFile := filepath .Join (tmpDir , "empty.json" )
46+ err := os .WriteFile (mcpFile , []byte ("" ), 0o644 )
5947 require .NoError (t , err )
6048
61- initResp := & acp.InitializeResponse {
62- AgentCapabilities : acp.AgentCapabilities {
63- McpCapabilities : acp.McpCapabilities {
64- Http : false ,
65- Sse : false ,
66- },
67- },
68- }
69- result , err := getSupportedMCPConfig (mcpFile , logger , initResp )
70- require .NoError (t , err )
71- assert .Len (t , result , 1 )
72- assert .NotNil (t , result [0 ].Stdio )
73- assert .Equal (t , "test-stdio" , result [0 ].Stdio .Name )
74- assert .Equal (t , "/usr/bin/test" , result [0 ].Stdio .Command )
75- assert .Equal (t , []string {"--stdio" }, result [0 ].Stdio .Args )
76- // Check env was converted correctly
77- assert .Len (t , result [0 ].Stdio .Env , 1 )
78- assert .Equal (t , "DEBUG" , result [0 ].Stdio .Env [0 ].Name )
79- assert .Equal (t , "true" , result [0 ].Stdio .Env [0 ].Value )
80- })
81-
82- t .Run ("http servers filtered when capability is false" , func (t * testing.T ) {
83- tmpDir := t .TempDir ()
84- mcpFile := filepath .Join (tmpDir , "mcp.json" )
85- mcpContent := `{
86- "mcpServers": {
87- "test-http": {
88- "type": "http",
89- "url": "https://example.com/mcp",
90- "headers": {
91- "Authorization": "Bearer token123"
92- }
93- }
94- }
95- }`
96- err := os .WriteFile (mcpFile , []byte (mcpContent ), 0o644 )
97- require .NoError (t , err )
98-
99- initResp := & acp.InitializeResponse {
100- AgentCapabilities : acp.AgentCapabilities {
101- McpCapabilities : acp.McpCapabilities {
102- Http : false ,
103- Sse : false ,
104- },
105- },
106- }
49+ initResp := & acp.InitializeResponse {}
10750 result , err := getSupportedMCPConfig (mcpFile , logger , initResp )
10851 require .NoError (t , err )
10952 assert .Empty (t , result )
11053 })
11154
112- t .Run ("http servers included when capability is true" , func (t * testing.T ) {
113- tmpDir := t .TempDir ()
114- mcpFile := filepath .Join (tmpDir , "mcp.json" )
115- mcpContent := `{
116- "mcpServers": {
117- "test-http": {
118- "type": "http",
119- "url": "https://example.com/mcp",
120- "headers": {
121- "Authorization": "Bearer token123"
122- }
123- }
124- }
125- }`
126- err := os .WriteFile (mcpFile , []byte (mcpContent ), 0o644 )
127- require .NoError (t , err )
128-
129- initResp := & acp.InitializeResponse {
130- AgentCapabilities : acp.AgentCapabilities {
131- McpCapabilities : acp.McpCapabilities {
132- Http : true ,
133- Sse : false ,
134- },
135- },
136- }
137- result , err := getSupportedMCPConfig (mcpFile , logger , initResp )
138- require .NoError (t , err )
139- assert .Len (t , result , 1 )
140- assert .NotNil (t , result [0 ].Http )
141- assert .Equal (t , "test-http" , result [0 ].Http .Name )
142- assert .Equal (t , "https://example.com/mcp" , result [0 ].Http .Url )
143- // Check headers were converted correctly
144- assert .Len (t , result [0 ].Http .Headers , 1 )
145- assert .Equal (t , "Authorization" , result [0 ].Http .Headers [0 ].Name )
146- assert .Equal (t , "Bearer token123" , result [0 ].Http .Headers [0 ].Value )
147- })
148-
149- t .Run ("mixed servers filtered correctly" , func (t * testing.T ) {
55+ t .Run ("servers filtered correctly" , func (t * testing.T ) {
15056 tmpDir := t .TempDir ()
15157 mcpFile := filepath .Join (tmpDir , "mcp.json" )
15258 mcpContent := `{
15359 "mcpServers": {
15460 "stdio-server": {
61+ "type": "stdio",
15562 "command": "/usr/bin/stdio-mcp",
15663 "args": []
15764 },
@@ -206,6 +113,7 @@ func TestGetSupportedMCPConfig(t *testing.T) {
206113 mcpContent := `{
207114 "mcpServers": {
208115 "invalid-server": {
116+ "type": "stdio",
209117 "args": ["--foo"]
210118 }
211119 }
@@ -220,32 +128,24 @@ func TestGetSupportedMCPConfig(t *testing.T) {
220128 assert .Empty (t , result )
221129 })
222130
223- t .Run ("http server inferred from url field " , func (t * testing.T ) {
131+ t .Run ("server without type is skipped " , func (t * testing.T ) {
224132 tmpDir := t .TempDir ()
225133 mcpFile := filepath .Join (tmpDir , "mcp.json" )
226- // No explicit type, but has url - should be inferred as http
227134 mcpContent := `{
228135 "mcpServers": {
229- "inferred-http ": {
230- "url ": "https://example.com/mcp "
136+ "no-type-server ": {
137+ "command ": "/usr/bin/test "
231138 }
232139 }
233140 }`
234141 err := os .WriteFile (mcpFile , []byte (mcpContent ), 0o644 )
235142 require .NoError (t , err )
236143
237- initResp := & acp.InitializeResponse {
238- AgentCapabilities : acp.AgentCapabilities {
239- McpCapabilities : acp.McpCapabilities {
240- Http : true ,
241- },
242- },
243- }
144+ initResp := & acp.InitializeResponse {}
244145 result , err := getSupportedMCPConfig (mcpFile , logger , initResp )
245146 require .NoError (t , err )
246- assert .Len (t , result , 1 )
247- assert .NotNil (t , result [0 ].Http )
248- assert .Equal (t , "inferred-http" , result [0 ].Http .Name )
147+ // Servers without type are skipped with a warning
148+ assert .Empty (t , result )
249149 })
250150}
251151
@@ -318,4 +218,14 @@ func TestConvertAgentapiMcpToAcp(t *testing.T) {
318218 require .Error (t , err )
319219 assert .Contains (t , err .Error (), "unsupported server type" )
320220 })
221+
222+ t .Run ("returns error for missing type" , func (t * testing.T ) {
223+ server := AgentapiMcpServer {
224+ Command : "/usr/bin/test" ,
225+ }
226+
227+ _ , err := server .convertAgentapiMcpToAcp ("no-type-server" )
228+ require .Error (t , err )
229+ assert .Contains (t , err .Error (), "unsupported server type" )
230+ })
321231}
0 commit comments