MCPcopy
hub / github.com/claude-code-best/claude-code / connect

Method connect

packages/mcp-client/src/manager.ts:97–127  ·  view source on GitHub ↗
(
    name: string,
    config: McpServerConfig,
  )

Source from the content-addressed store, hash-verified

95 }
96
97 async connect(
98 name: string,
99 config: McpServerConfig,
100 ): Promise<MCPServerConnection> {
101 if (!this.connectFn) {
102 throw new Error(
103 'McpManager: connectFn not set. Call setConnectFn() first.',
104 )
105 }
106
107 const scopedConfig: ScopedMcpServerConfig = { ...config, scope: 'dynamic' }
108
109 try {
110 const connection = await this.connectFn(name, scopedConfig)
111 this.connections.set(name, connection)
112
113 if (connection.type === 'connected') {
114 this.emit('connected', name)
115 // Fetch tools for this server
116 await this.refreshTools(name, connection)
117 } else if (connection.type === 'needs-auth') {
118 this.emit('authRequired', name)
119 }
120
121 return connection
122 } catch (err) {
123 const error = err instanceof Error ? err : new Error(String(err))
124 this.emit('error', name, error)
125 throw err
126 }
127 }
128
129 async disconnect(name: string): Promise<void> {
130 const conn = this.connections.get(name)

Callers

nothing calls this directly

Calls 3

emitMethod · 0.95
refreshToolsMethod · 0.95
setMethod · 0.80

Tested by

no test coverage detected