MCPcopy Create free account
hub / github.com/github/gh-aw / extractMCPInitialization

Function extractMCPInitialization

actions/setup/js/parse_codex_log.cjs:17–123  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

15 * @returns {{hasInfo: boolean, markdown: string, servers: Array<{name: string, status: string, error?: string}>}} MCP initialization info
16 */
17function 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

Callers 2

parseCodexLogFunction · 0.85

Calls 1

getMethod · 0.80

Tested by

no test coverage detected