* Extract MCP server initialization information from Codex logs * @param {string[]} lines - Array of log lines * @returns {{hasInfo: boolean, markdown: string, servers: Array<{name: string, status: string, error?: string}>}} MCP initialization info
(lines)
| 15 | * @returns {{hasInfo: boolean, markdown: string, servers: Array<{name: string, status: string, error?: string}>}} MCP initialization info |
| 16 | */ |
| 17 | function extractMCPInitialization(lines) { |
| 18 | const mcpServers = new Map(); // Map server name to status/error info |
| 19 | let serverCount = 0; |
| 20 | let connectedCount = 0; |
| 21 | let availableTools = []; |
| 22 | |
| 23 | for (const line of lines) { |
| 24 | // Match: Initializing MCP servers from config |
| 25 | if (line.includes("Initializing MCP servers") || (line.includes("mcp") && line.includes("init"))) { |
| 26 | // Continue to next patterns |
| 27 | } |
| 28 | |
| 29 | // Match: Found N MCP servers in configuration |
| 30 | const countMatch = line.match(/Found (\d+) MCP servers? in configuration/i); |
| 31 | if (countMatch) { |
| 32 | serverCount = parseInt(countMatch[1]); |
| 33 | } |
| 34 | |
| 35 | // Match: Connecting to MCP server: <name> |
| 36 | const connectingMatch = line.match(/Connecting to MCP server[:\s]+['"]?(\w+)['"]?/i); |
| 37 | if (connectingMatch) { |
| 38 | const serverName = connectingMatch[1]; |
| 39 | if (!mcpServers.has(serverName)) { |
| 40 | mcpServers.set(serverName, { name: serverName, status: "connecting" }); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | // Match: MCP server '<name>' connected successfully |
| 45 | const connectedMatch = line.match(/MCP server ['"](\w+)['"] connected successfully/i); |
| 46 | if (connectedMatch) { |
| 47 | const serverName = connectedMatch[1]; |
| 48 | mcpServers.set(serverName, { name: serverName, status: "connected" }); |
| 49 | connectedCount++; |
| 50 | } |
| 51 | |
| 52 | // Match: Failed to connect to MCP server '<name>': <error> |
| 53 | const failedMatch = line.match(/Failed to connect to MCP server ['"](\w+)['"][:]\s*(.+)/i); |
| 54 | if (failedMatch) { |
| 55 | const serverName = failedMatch[1]; |
| 56 | const error = failedMatch[2].trim(); |
| 57 | mcpServers.set(serverName, { name: serverName, status: "failed", error }); |
| 58 | } |
| 59 | |
| 60 | // Match: MCP server '<name>' initialization failed |
| 61 | const initFailedMatch = line.match(/MCP server ['"](\w+)['"] initialization failed/i); |
| 62 | if (initFailedMatch) { |
| 63 | const serverName = initFailedMatch[1]; |
| 64 | const existing = mcpServers.get(serverName); |
| 65 | if (existing && existing.status !== "failed") { |
| 66 | mcpServers.set(serverName, { name: serverName, status: "failed", error: "Initialization failed" }); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | // Match: Available tools: tool1, tool2, tool3 |
| 71 | const toolsMatch = line.match(/Available tools:\s*(.+)/i); |
| 72 | if (toolsMatch) { |
| 73 | const toolsStr = toolsMatch[1]; |
| 74 | availableTools = toolsStr |
no test coverage detected