* Test an MCP server. * * Provide either: * - `name` to test a configured server by looking up its config, OR * - `command` to test an arbitrary stdio command, OR * - `url`+`transport` to test an arbitrary HTTP/SSE endpoint.
(options: {
projectPath: string;
/** Whether repo-local MCP config is allowed for this project. */
trusted?: boolean;
name?: string;
command?: string;
transport?: MCPServerTransport;
url?: string;
headers?: Record<string, MCPHeaderValue>;
projectSecrets?: Record<string, string>;
})
| 1286 | * - `url`+`transport` to test an arbitrary HTTP/SSE endpoint. |
| 1287 | */ |
| 1288 | async test(options: { |
| 1289 | projectPath: string; |
| 1290 | /** Whether repo-local MCP config is allowed for this project. */ |
| 1291 | trusted?: boolean; |
| 1292 | name?: string; |
| 1293 | command?: string; |
| 1294 | transport?: MCPServerTransport; |
| 1295 | url?: string; |
| 1296 | headers?: Record<string, MCPHeaderValue>; |
| 1297 | projectSecrets?: Record<string, string>; |
| 1298 | }): Promise<MCPTestResult> { |
| 1299 | const isTransportAllowed = (t: MCPServerTransport): boolean => { |
| 1300 | return !this.policyService?.isEnforced() || this.policyService.isMcpTransportAllowed(t); |
| 1301 | }; |
| 1302 | const { |
| 1303 | projectPath, |
| 1304 | trusted = false, |
| 1305 | name, |
| 1306 | command, |
| 1307 | transport, |
| 1308 | url, |
| 1309 | headers, |
| 1310 | projectSecrets, |
| 1311 | } = options; |
| 1312 | const trimmedName = name?.trim(); |
| 1313 | |
| 1314 | if (trimmedName && !command?.trim() && !url?.trim()) { |
| 1315 | const servers = await this.configService.listServers(projectPath, trusted); |
| 1316 | const server = servers[trimmedName]; |
| 1317 | if (!server) { |
| 1318 | return { success: false, error: `Server "${trimmedName}" not found in configuration` }; |
| 1319 | } |
| 1320 | |
| 1321 | if (!isTransportAllowed(server.transport)) { |
| 1322 | return { success: false, error: "MCP transport is disabled by policy" }; |
| 1323 | } |
| 1324 | |
| 1325 | if (server.transport === "stdio") { |
| 1326 | return runServerTest( |
| 1327 | { transport: "stdio", command: server.command }, |
| 1328 | projectPath, |
| 1329 | `server "${trimmedName}"` |
| 1330 | ); |
| 1331 | } |
| 1332 | |
| 1333 | try { |
| 1334 | const resolved = resolveHeaders(server.headers, projectSecrets); |
| 1335 | |
| 1336 | const authProvider = await this.mcpOauthService?.getAuthProviderForServer({ |
| 1337 | serverName: trimmedName, |
| 1338 | serverUrl: server.url, |
| 1339 | }); |
| 1340 | |
| 1341 | return runServerTest( |
| 1342 | { |
| 1343 | transport: server.transport, |
| 1344 | url: server.url, |
| 1345 | headers: resolved.headers, |
no test coverage detected