1- import { config } from 'dotenv' ;
2- import { Logger } from '../logger.js' ;
3- import type { CommandResult } from '../types.js' ;
4- import type { ToolCall } from '../types.js' ;
5- import type { Tool } from '@modelcontextprotocol/sdk/types.js' ;
6- import type { LLMConfigData , ServerActionData } from '../types.js' ;
7- import { AgentService } from './agent-service.js' ;
8- import { LLMService } from './llm-service.js' ;
9- import { MCPConfigService , type MCPServerConfig } from './mcp-config-service.js' ;
10- import { UtilityService } from './utility-service.js' ;
1+ import { config } from 'dotenv' ;
2+ import { Logger } from '../logger.js' ;
3+ import type { CommandResult } from '../types.js' ;
4+ import type { ToolCall } from '../types.js' ;
5+ import type { Tool } from '@modelcontextprotocol/sdk/types.js' ;
6+ import type { LLMConfigData , ServerActionData } from '../types.js' ;
7+ import { AgentService } from './agent-service.js' ;
8+ import { LLMService } from './llm-service.js' ;
9+ import { MCPConfigService , type MCPServerConfig } from './mcp-config-service.js' ;
10+ import { UtilityService } from './utility-service.js' ;
1111
1212// Load environment variables
1313config ( ) ;
@@ -27,7 +27,7 @@ type CommandHandler = (
2727/**
2828 * Registry entry for a command, including its handler and metadata.
2929 */
30- interface CommandRegistryEntry {
30+ export interface CommandRegistryEntry {
3131 handler : CommandHandler ;
3232 description : string ;
3333}
@@ -230,9 +230,8 @@ export class CLIService {
230230 } ) ;
231231 return {
232232 type : 'error' ,
233- message : `Command failed: ${
234- error instanceof Error ? error . message : 'Unknown error'
235- } `,
233+ message : `Command failed: ${ error instanceof Error ? error . message : 'Unknown error'
234+ } `,
236235 } ;
237236 }
238237 }
@@ -257,7 +256,7 @@ export class CLIService {
257256 pendingModel ?: string ,
258257 isServerConfigInput ?: boolean ,
259258 serverConfigStep ?: string ,
260- serverConfig ?: Partial < MCPServerConfig > & { name ?: string } ,
259+ serverConfig ?: Partial < MCPServerConfig > & { name ?: string } ,
261260 ) : AsyncGenerator < {
262261 response ?: string ;
263262 toolCalls ?: ToolCall [ ] ;
@@ -356,12 +355,11 @@ export class CLIService {
356355 return ;
357356 } catch ( error ) {
358357 yield {
359- response : `Command error: ${
360- error instanceof Error ? error . message : 'Unknown error'
361- } `,
358+ response : `Command error: ${ error instanceof Error ? error . message : 'Unknown error'
359+ } `,
362360 toolCalls : [ ] ,
363361 isCommand : true ,
364- commandResult : { type : 'error' , message : 'Command failed' } ,
362+ commandResult : { type : 'error' , message : 'Command failed' } ,
365363 done : true ,
366364 } ;
367365 return ;
@@ -405,16 +403,15 @@ export class CLIService {
405403 done : false ,
406404 } ;
407405 }
408- yield { done : true } ;
406+ yield { done : true } ;
409407 } catch ( error ) {
410408 Logger . error ( 'Error sending message via Agent service' , {
411409 error : error instanceof Error ? error . message : 'Unknown error' ,
412410 stack : error instanceof Error ? error . stack : undefined ,
413411 } ) ;
414412 yield {
415- response : `Error: ${
416- error instanceof Error ? error . message : 'Unknown error'
417- } `,
413+ response : `Error: ${ error instanceof Error ? error . message : 'Unknown error'
414+ } `,
418415 thought : undefined ,
419416 done : true ,
420417 } ;
@@ -483,7 +480,7 @@ export class CLIService {
483480 * Gets the list of available tools from the agent.
484481 * @returns A promise that resolves to an object containing the tools or an error.
485482 */
486- async getAvailableTools ( ) : Promise < { tools : Tool [ ] ; error ?: string } > {
483+ async getAvailableTools ( ) : Promise < { tools : Tool [ ] ; error ?: string } > {
487484 return this . agentService . getAvailableTools ( ) ;
488485 }
489486
@@ -512,7 +509,7 @@ export class CLIService {
512509 return {
513510 type : 'list_servers' ,
514511 message : 'MCP Server Status:' ,
515- data : { servers : serversWithStatus } ,
512+ data : { servers : serversWithStatus } ,
516513 } ;
517514 }
518515
@@ -547,7 +544,7 @@ export class CLIService {
547544 type : 'prompt_server_config' ,
548545 message :
549546 'Let\'s configure a new MCP server!\n\nYou can either:\n1. Enter a server name for interactive setup\n2. Paste a complete JSON configuration\n\nExample JSON:\n{\n "mcpServers": {\n "myserver": {\n "command": "npx",\n "args": ["-y", "@example/server"]\n }\n }\n}\n\nEnter server name or paste JSON:' ,
550- data : { step : 'name_or_json' } ,
547+ data : { step : 'name_or_json' } ,
551548 } ;
552549 }
553550
@@ -611,17 +608,16 @@ export class CLIService {
611608 return {
612609 type : 'success' ,
613610 message : `Connected to server "${ serverName } "!` ,
614- data : { reinitializeAgent : true } ,
611+ data : { reinitializeAgent : true } ,
615612 } ;
616613 } catch ( error ) {
617614 Logger . error ( `Failed to connect to server ${ serverName } ` , {
618615 error : error instanceof Error ? error . message : String ( error ) ,
619616 } ) ;
620617 return {
621618 type : 'error' ,
622- message : `Failed to connect to server "${ serverName } ": ${
623- error instanceof Error ? error . message : 'Unknown error'
624- } `,
619+ message : `Failed to connect to server "${ serverName } ": ${ error instanceof Error ? error . message : 'Unknown error'
620+ } `,
625621 } ;
626622 }
627623 }
@@ -675,20 +671,27 @@ export class CLIService {
675671 return {
676672 type : 'success' ,
677673 message : `✅ Disconnected from server "${ serverName } ".` ,
678- data : { reinitializeAgent : true } ,
674+ data : { reinitializeAgent : true } ,
679675 } ;
680676 } catch ( error ) {
681677 Logger . error ( `Failed to disconnect from server ${ serverName } ` , {
682678 error : error instanceof Error ? error . message : String ( error ) ,
683679 } ) ;
684680 return {
685681 type : 'error' ,
686- message : `Failed to disconnect from server "${ serverName } ": ${
687- error instanceof Error ? error . message : 'Unknown error'
688- } `,
682+ message : `Failed to disconnect from server "${ serverName } ": ${ error instanceof Error ? error . message : 'Unknown error'
683+ } `,
689684 } ;
690685 }
691686 }
687+
688+ /**
689+ * Returns the command registry.
690+ * @returns The map of registered commands
691+ */
692+ getCommandRegistry ( ) : Map < string , CommandRegistryEntry > {
693+ return this . commandRegistry ;
694+ }
692695}
693696
694697// Export a singleton instance
0 commit comments