@@ -170,7 +170,7 @@ export class McpManager {
170170 /**
171171 * Load configurations and initialize each enabled server.
172172 */
173- private async discoverAllServers ( authIntent : AuthIntent = AuthIntent . Silent ) : Promise < void > {
173+ private async discoverAllServers ( ) : Promise < void > {
174174 // Load agent config
175175 const result = await loadAgentConfig ( this . features . workspace , this . features . logging , this . agentPaths )
176176
@@ -221,7 +221,7 @@ export class McpManager {
221221 // Process servers in batches
222222 for ( let i = 0 ; i < totalServers ; i += MAX_CONCURRENT_SERVERS ) {
223223 const batch = serversToInit . slice ( i , i + MAX_CONCURRENT_SERVERS )
224- const batchPromises = batch . map ( ( [ name , cfg ] ) => this . initOneServer ( name , cfg , authIntent ) )
224+ const batchPromises = batch . map ( ( [ name , cfg ] ) => this . initOneServer ( name , cfg , AuthIntent . Silent ) )
225225
226226 this . features . logging . debug (
227227 `MCP: initializing batch of ${ batch . length } servers (${ i + 1 } -${ Math . min ( i + MAX_CONCURRENT_SERVERS , totalServers ) } of ${ totalServers } )`
@@ -373,19 +373,29 @@ export class McpManager {
373373
374374 if ( needsOAuth ) {
375375 OAuthClient . initialize ( this . features . workspace , this . features . logging )
376- const bearer = await OAuthClient . getValidAccessToken ( base , {
377- interactive : authIntent === 'interactive' ,
378- } )
379- // add authorization header if we are able to obtain a bearer token
380- if ( bearer ) {
381- headers = { ...headers , Authorization : `Bearer ${ bearer } ` }
382- } else if ( authIntent === 'silent' ) {
383- // In silent mode we never launch a browser. If we cannot obtain a token
384- // from cache/refresh, surface a clear auth-required error and stop here.
385- throw new AgenticChatError (
386- `MCP: server '${ serverName } ' requires OAuth. Open "Edit MCP Server" and save to sign in.` ,
387- 'MCPServerAuthFailed'
388- )
376+ try {
377+ const bearer = await OAuthClient . getValidAccessToken ( base , {
378+ interactive : authIntent === AuthIntent . Interactive ,
379+ } )
380+ if ( bearer ) {
381+ headers = { ...headers , Authorization : `Bearer ${ bearer } ` }
382+ } else if ( authIntent === AuthIntent . Silent ) {
383+ throw new AgenticChatError (
384+ `MCP: server '${ serverName } ' requires OAuth. Open "Edit MCP Server" and save to sign in.` ,
385+ 'MCPServerAuthFailed'
386+ )
387+ }
388+ } catch ( e : any ) {
389+ const msg = e ?. message || ''
390+ const short = / a u t h o r i z a t i o n _ t i m e d _ o u t / i. test ( msg )
391+ ? 'Sign-in timed out. Please try again.'
392+ : / A u t h o r i z a t i o n e r r o r | P K C E | a c c e s s _ d e n i e d | l o g i n | c o n s e n t | t o k e n e x c h a n g e f a i l e d / i. test (
393+ msg
394+ )
395+ ? 'Sign-in was cancelled or failed. Please try again.'
396+ : `OAuth failed: ${ msg } `
397+
398+ throw new AgenticChatError ( `MCP: ${ short } ` , 'MCPServerAuthFailed' )
389399 }
390400 }
391401
@@ -1156,15 +1166,16 @@ export class McpManager {
11561166 */
11571167 public async removeServerFromConfigFile ( serverName : string ) : Promise < void > {
11581168 try {
1159- const cfg = this . mcpServers . get ( serverName )
1169+ const sanitized = sanitizeName ( serverName )
1170+ const cfg = this . mcpServers . get ( sanitized )
11601171 if ( ! cfg || ! cfg . __configPath__ ) {
11611172 this . features . logging . warn (
11621173 `Cannot remove config for server '${ serverName } ': Config not found or missing path`
11631174 )
11641175 return
11651176 }
11661177
1167- const unsanitizedName = this . serverNameMapping . get ( serverName ) || serverName
1178+ const unsanitizedName = this . serverNameMapping . get ( sanitized ) || serverName
11681179
11691180 // Remove from agent config
11701181 if ( unsanitizedName && this . agentConfig ) {
0 commit comments