TestValidateMCPConfigWithSchema tests the ValidateMCPConfigWithSchema function which validates a single MCP server configuration against the MCP config JSON schema.
(t *testing.T)
| 140 | // TestValidateMCPConfigWithSchema tests the ValidateMCPConfigWithSchema function |
| 141 | // which validates a single MCP server configuration against the MCP config JSON schema. |
| 142 | func TestValidateMCPConfigWithSchema(t *testing.T) { |
| 143 | tests := []struct { |
| 144 | name string |
| 145 | mcpConfig map[string]any |
| 146 | wantErr bool |
| 147 | errContains string |
| 148 | }{ |
| 149 | { |
| 150 | name: "valid stdio config with command", |
| 151 | mcpConfig: map[string]any{ |
| 152 | "type": "stdio", |
| 153 | "command": "npx", |
| 154 | "args": []any{"-y", "@modelcontextprotocol/server-filesystem"}, |
| 155 | }, |
| 156 | wantErr: false, |
| 157 | }, |
| 158 | { |
| 159 | name: "valid stdio config with container", |
| 160 | mcpConfig: map[string]any{ |
| 161 | "type": "stdio", |
| 162 | "container": "docker.io/mcp/brave-search", |
| 163 | "env": map[string]any{ |
| 164 | "BRAVE_API_KEY": "secret", |
| 165 | }, |
| 166 | }, |
| 167 | wantErr: false, |
| 168 | }, |
| 169 | { |
| 170 | name: "valid http config", |
| 171 | mcpConfig: map[string]any{ |
| 172 | "type": "http", |
| 173 | "url": "https://api.example.com/mcp", |
| 174 | "headers": map[string]any{ |
| 175 | "Authorization": "Bearer token", |
| 176 | }, |
| 177 | }, |
| 178 | wantErr: false, |
| 179 | }, |
| 180 | { |
| 181 | name: "valid config inferred from url requires explicit type in schema", |
| 182 | mcpConfig: map[string]any{ |
| 183 | "type": "http", |
| 184 | "url": "http://localhost:8765", |
| 185 | }, |
| 186 | wantErr: false, |
| 187 | }, |
| 188 | { |
| 189 | name: "empty config fails anyOf - missing type, url, command, and container", |
| 190 | mcpConfig: map[string]any{}, |
| 191 | wantErr: true, |
| 192 | errContains: "missing property", |
| 193 | }, |
| 194 | { |
| 195 | name: "invalid container pattern rejected by schema", |
| 196 | mcpConfig: map[string]any{ |
| 197 | "container": "INVALID CONTAINER NAME WITH SPACES", |
| 198 | }, |
| 199 | wantErr: true, |
nothing calls this directly
no test coverage detected