@@ -56,11 +56,13 @@ export class McpHub {
5656 private disposables : vscode . Disposable [ ] = [ ]
5757 private settingsWatcher ?: vscode . FileSystemWatcher
5858 private fileWatchers : Map < string , FSWatcher > = new Map ( )
59+ private context : vscode . ExtensionContext
5960 connections : McpConnection [ ] = [ ]
6061 isConnecting : boolean = false
6162
62- constructor ( provider : ClineProvider ) {
63+ constructor ( provider : ClineProvider , context : vscode . ExtensionContext ) {
6364 this . providerRef = new WeakRef ( provider )
65+ this . context = context
6466 this . watchMcpSettingsFile ( )
6567 this . initializeMcpServers ( )
6668 }
@@ -154,6 +156,16 @@ export class McpHub {
154156 }
155157 }
156158
159+ private async getPearAiApiKey ( ) : Promise < string | null > {
160+ try {
161+ const token = await this . context . secrets . get ( "pearai-token" )
162+ return token || null
163+ } catch ( error ) {
164+ console . error ( "Failed to get PearAI token from secrets:" , error )
165+ return null
166+ }
167+ }
168+
157169 private async initializeMcpServers ( ) : Promise < void > {
158170 try {
159171 const settingsPath = await this . getMcpSettingsFilePath ( )
@@ -168,6 +180,17 @@ export class McpHub {
168180 if ( ! mergedServers [ serverName ] ) {
169181 mergedServers [ serverName ] = serverConfig
170182 }
183+
184+ // If this is the pearai server, check login status and update API key
185+ if ( serverName === "pearai" ) {
186+ const apiKey = await this . getPearAiApiKey ( )
187+ if ( apiKey ) {
188+ mergedServers [ serverName ] = {
189+ ...serverConfig ,
190+ args : [ "pearai-mcp" , apiKey ] ,
191+ }
192+ }
193+ }
171194 }
172195
173196 // Update the settings file with merged settings
@@ -482,6 +505,29 @@ export class McpHub {
482505 } )
483506 }
484507
508+ public async updatePearAiApiKey ( apiKey : string ) : Promise < void > {
509+ try {
510+ const settingsPath = await this . getMcpSettingsFilePath ( )
511+ const content = await fs . readFile ( settingsPath , "utf-8" )
512+ const config = JSON . parse ( content )
513+
514+ if ( config . mcpServers ?. pearai ) {
515+ config . mcpServers . pearai = {
516+ ...config . mcpServers . pearai ,
517+ args : [ "pearai-mcp" , apiKey ] ,
518+ }
519+
520+ await fs . writeFile ( settingsPath , JSON . stringify ( config , null , 2 ) )
521+ await this . updateServerConnections ( config . mcpServers )
522+ vscode . window . showInformationMessage ( "PearAI API key updated successfully" )
523+ }
524+ } catch ( error ) {
525+ console . error ( "Failed to update PearAI API key:" , error )
526+ vscode . window . showErrorMessage ( "Failed to update PearAI API key" )
527+ throw error
528+ }
529+ }
530+
485531 public async toggleServerDisabled ( serverName : string , disabled : boolean ) : Promise < void > {
486532 let settingsPath : string
487533 try {
0 commit comments