88
99import { log } from "../../lib/log.ts" ;
1010import { cyan , dim , green , yellow } from "../../lib/color.ts" ;
11- import { isAgent , isHuman } from "../../mode.ts" ;
12- import { intro , outro } from "../../lib/spinner.ts" ;
11+ import { isAgent } from "../../mode.ts" ;
12+ import { withGutter } from "../../lib/spinner.ts" ;
1313import {
1414 pickClients ,
15- printNextSteps ,
1615 resolveName ,
1716 resolveUrl ,
1817 settleClients ,
@@ -55,18 +54,15 @@ type ClientUpsert = { client: McpClient; result: UpsertResult };
5554// Writing the config isn't enough — the editor must reload before it connects
5655// (and sign in, if the server requires it). Surface that for every client we
5756// just wrote, so "added" doesn't read as "done and working".
58- function printInstallNextSteps ( settled : ClientUpsert [ ] ) : void {
57+ function installNextSteps ( settled : ClientUpsert [ ] ) : string [ ] {
5958 const activated = settled . filter (
6059 ( { result } ) => result . status === "added" || result . status === "updated" ,
6160 ) ;
62- if ( activated . length === 0 ) return ;
63-
64- printNextSteps ( activated . map ( ( { client } ) => `${ client . displayName } : ${ client . activation } ` ) ) ;
65- log . info (
66- dim (
67- "If the server requires authentication, your editor opens a browser to sign in on first connect." ,
68- ) ,
69- ) ;
61+ if ( activated . length === 0 ) return [ ] ;
62+ return [
63+ ...activated . map ( ( { client } ) => `${ client . displayName } : ${ client . activation } ` ) ,
64+ "If the server requires authentication, your editor opens a browser to sign in on first connect." ,
65+ ] ;
7066}
7167
7268export async function mcpInstall ( options : McpOptions = { } ) : Promise < void > {
@@ -77,26 +73,24 @@ export async function mcpInstall(options: McpOptions = {}): Promise<void> {
7773 const force = Boolean ( options . force ) ;
7874 const json = wantsJson ( options ) ;
7975
80- if ( clients . length === 0 && json ) {
81- log . data ( JSON . stringify ( { url, name, results : [ ] } , null , 2 ) ) ;
82- return ;
83- }
8476 if ( clients . length === 0 ) {
85- log . warn ( "No MCP clients selected." ) ;
86- return ;
87- }
88-
89- if ( isHuman ( ) && ! json ) intro ( `Installing Clerk MCP (${ cyan ( url ) } )` ) ;
90-
91- const settled = await settleClients ( clients , ( c ) => c . upsert ( { name, url } , cwd , force ) ) ;
92- const results = settled . map ( ( s ) => s . result ) ;
93-
94- if ( json ) {
95- log . data ( JSON . stringify ( { url, name, results } , null , 2 ) ) ;
77+ if ( json ) log . data ( JSON . stringify ( { url, name, results : [ ] } , null , 2 ) ) ;
78+ else log . warn ( "No MCP clients selected." ) ;
9679 return ;
9780 }
9881
99- settled . forEach ( ( { client, result } ) => printResult ( client , result ) ) ;
100- printInstallNextSteps ( settled ) ;
101- outro ( "Done" ) ;
82+ await withGutter (
83+ `Installing Clerk MCP (${ cyan ( url ) } )` ,
84+ async ( { setNextSteps } ) => {
85+ const settled = await settleClients ( clients , ( c ) => c . upsert ( { name, url } , cwd , force ) ) ;
86+ if ( json ) {
87+ log . data ( JSON . stringify ( { url, name, results : settled . map ( ( s ) => s . result ) } , null , 2 ) ) ;
88+ return ;
89+ }
90+ settled . forEach ( ( { client, result } ) => printResult ( client , result ) ) ;
91+ const steps = installNextSteps ( settled ) ;
92+ if ( steps . length > 0 ) setNextSteps ( steps ) ;
93+ } ,
94+ { skip : json } ,
95+ ) ;
10296}
0 commit comments