MCPcopy Index your code
hub / github.com/codeaashu/claude-code / reconnectMcpServerImpl

Function reconnectMcpServerImpl

src/services/mcp/client.ts:2137–2210  ·  view source on GitHub ↗
(
  name: string,
  config: ScopedMcpServerConfig,
)

Source from the content-addressed store, hash-verified

2135 * @returns Object containing the client connection and its resources
2136 */
2137export async function reconnectMcpServerImpl(
2138 name: string,
2139 config: ScopedMcpServerConfig,
2140): Promise<{
2141 client: MCPServerConnection
2142 tools: Tool[]
2143 commands: Command[]
2144 resources?: ServerResource[]
2145}> {
2146 try {
2147 // Invalidate the keychain cache so we read fresh credentials from disk.
2148 // This is necessary when another process (e.g. the VS Code extension host)
2149 // has modified stored tokens (cleared auth, saved new OAuth tokens) and then
2150 // asks the CLI subprocess to reconnect. Without this, the subprocess would
2151 // use stale cached data and never notice the tokens were removed.
2152 clearKeychainCache()
2153
2154 await clearServerCache(name, config)
2155 const client = await connectToServer(name, config)
2156
2157 if (client.type !== 'connected') {
2158 return {
2159 client,
2160 tools: [],
2161 commands: [],
2162 }
2163 }
2164
2165 if (config.type === 'claudeai-proxy') {
2166 markClaudeAiMcpConnected(name)
2167 }
2168
2169 const supportsResources = !!client.capabilities?.resources
2170
2171 const [tools, mcpCommands, mcpSkills, resources] = await Promise.all([
2172 fetchToolsForClient(client),
2173 fetchCommandsForClient(client),
2174 feature('MCP_SKILLS') && supportsResources
2175 ? fetchMcpSkillsForClient!(client)
2176 : Promise.resolve([]),
2177 supportsResources ? fetchResourcesForClient(client) : Promise.resolve([]),
2178 ])
2179 const commands = [...mcpCommands, ...mcpSkills]
2180
2181 // Check if we need to add resource tools
2182 const resourceTools: Tool[] = []
2183 if (supportsResources) {
2184 // Only add resource tools if no other server has them
2185 const hasResourceTools = [ListMcpResourcesTool, ReadMcpResourceTool].some(
2186 tool => tools.some(t => toolMatchesName(t, tool.name)),
2187 )
2188 if (!hasResourceTools) {
2189 resourceTools.push(ListMcpResourcesTool, ReadMcpResourceTool)
2190 }
2191 }
2192
2193 return {
2194 client,

Callers 4

callFunction · 0.85
runHeadlessStreamingFunction · 0.85
reconnectWithBackoffFunction · 0.85
useManageMCPConnectionsFunction · 0.85

Calls 9

clearKeychainCacheFunction · 0.85
clearServerCacheFunction · 0.85
markClaudeAiMcpConnectedFunction · 0.85
featureFunction · 0.85
toolMatchesNameFunction · 0.85
logMCPErrorFunction · 0.85
errorMessageFunction · 0.50
resolveMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected