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

Function processServer

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected