MCPcopy Create free account
hub / github.com/freecodexyz/free-code / processServer

Function processServer

src/services/mcp/client.ts:2284–2388  ·  view source on GitHub ↗
([name, config]: [
    string,
    ScopedMcpServerConfig,
  ])

Source from the content-addressed store, hash-verified

2282 }
2283
2284 const processServer = async ([name, config]: [
2285 string,
2286 ScopedMcpServerConfig,
2287 ]): Promise<void> => {
2288 try {
2289 // Check if server is disabled - if so, just add it to state without connecting
2290 if (isMcpServerDisabled(name)) {
2291 onConnectionAttempt({
2292 client: {
2293 name,
2294 type: 'disabled',
2295 config,
2296 },
2297 tools: [],
2298 commands: [],
2299 })
2300 return
2301 }
2302
2303 // Skip connection for servers that recently returned 401 (15min TTL),
2304 // or that we have probed before but hold no token for. The second
2305 // check closes the gap the TTL leaves open: without it, every 15min
2306 // we re-probe servers that cannot succeed until the user runs /mcp.
2307 // Each probe is a network round-trip for connect-401 plus OAuth
2308 // discovery, and print mode awaits the whole batch (main.tsx:3503).
2309 if (
2310 (config.type === 'claudeai-proxy' ||
2311 config.type === 'http' ||
2312 config.type === 'sse') &&
2313 ((await isMcpAuthCached(name)) ||
2314 ((config.type === 'http' || config.type === 'sse') &&
2315 hasMcpDiscoveryButNoToken(name, config)))
2316 ) {
2317 logMCPDebug(name, `Skipping connection (cached needs-auth)`)
2318 onConnectionAttempt({
2319 client: { name, type: 'needs-auth' as const, config },
2320 tools: [createMcpAuthTool(name, config)],
2321 commands: [],
2322 })
2323 return
2324 }
2325
2326 const client = await connectToServer(name, config, serverStats)
2327
2328 if (client.type !== 'connected') {
2329 onConnectionAttempt({
2330 client,
2331 tools:
2332 client.type === 'needs-auth'
2333 ? [createMcpAuthTool(name, config)]
2334 : [],
2335 commands: [],
2336 })
2337 return
2338 }
2339
2340 if (config.type === 'claudeai-proxy') {
2341 markClaudeAiMcpConnected(name)

Callers

nothing calls this directly

Calls 9

isMcpServerDisabledFunction · 0.85
isMcpAuthCachedFunction · 0.85
logMCPDebugFunction · 0.85
createMcpAuthToolFunction · 0.85
markClaudeAiMcpConnectedFunction · 0.85
logMCPErrorFunction · 0.85
resolveMethod · 0.80
errorMessageFunction · 0.50

Tested by

no test coverage detected