@@ -65,6 +65,12 @@ import { genEnv } from "./commands/gen/gen.js";
65
65
import { upgradeCommand } from "./commands/update/upgrade.js" ;
66
66
import { updateCommand } from "./commands/update/update.js" ;
67
67
import { addCommand } from "./commands/add/add.js" ;
68
+ import {
69
+ callToolCommand ,
70
+ autocompleteIntegrations ,
71
+ } from "./commands/tools/call-tool.js" ;
72
+ import { completionCommand } from "./commands/completion/completion.js" ;
73
+ import { installCompletionCommand } from "./commands/completion/install.js" ;
68
74
import { detectRuntime } from "./lib/runtime.js" ;
69
75
70
76
const __filename = fileURLToPath ( import . meta. url ) ;
@@ -370,6 +376,111 @@ const add = new Command("add")
370
376
}
371
377
} ) ;
372
378
379
+ // Call-tool command implementation
380
+ const callTool = new Command ( "call-tool" )
381
+ . description ( "Call a tool on an integration using MCP protocol." )
382
+ . argument ( "<tool>" , "Name of the tool to call" )
383
+ . option (
384
+ "-i, --integration <integration>" ,
385
+ "Integration ID to call the tool on" ,
386
+ )
387
+ . option ( "-p, --payload <payload>" , "JSON payload to send to the tool" )
388
+ . option (
389
+ "--set <key=value>" ,
390
+ "Set a key-value pair in the payload (can be used multiple times)" ,
391
+ ( value , previous : string [ ] | undefined ) => {
392
+ return previous ? [ ...previous , value ] : [ value ] ;
393
+ } ,
394
+ )
395
+ . option ( "-w, --workspace <workspace>" , "Workspace name" )
396
+ . configureHelp ( {
397
+ subcommandTerm : ( cmd ) => cmd . name ( ) , // for auto-completion
398
+ } )
399
+ . action ( async ( toolName , options ) => {
400
+ // Validate required integration parameter
401
+ if ( ! options . integration ) {
402
+ console . error (
403
+ "❌ Integration ID is required. Use -i or --integration flag." ,
404
+ ) ;
405
+
406
+ // Show available integrations for user convenience
407
+ try {
408
+ console . log ( "🔍 Available integrations:" ) ;
409
+ const integrations = await autocompleteIntegrations ( "" ) ;
410
+ if ( integrations . length > 0 ) {
411
+ integrations . slice ( 0 , 10 ) . forEach ( ( id ) => console . log ( ` • ${ id } ` ) ) ;
412
+ if ( integrations . length > 10 ) {
413
+ console . log ( ` ... and ${ integrations . length - 10 } more` ) ;
414
+ }
415
+ } else {
416
+ console . log (
417
+ " No integrations found. Run 'deco add' to add integrations." ,
418
+ ) ;
419
+ }
420
+ } catch {
421
+ console . log ( " Run 'deco add' to add integrations." ) ;
422
+ }
423
+
424
+ process . exit ( 1 ) ;
425
+ }
426
+
427
+ try {
428
+ await callToolCommand ( toolName , {
429
+ integration : options . integration ,
430
+ payload : options . payload ,
431
+ set : options . set ,
432
+ workspace : options . workspace ,
433
+ } ) ;
434
+ } catch ( error ) {
435
+ console . error (
436
+ "❌ Tool call failed:" ,
437
+ error instanceof Error ? error . message : String ( error ) ,
438
+ ) ;
439
+ process . exit ( 1 ) ;
440
+ }
441
+ } ) ;
442
+
443
+ // Completion command implementation (internal command)
444
+ const completion = new Command ( "completion" )
445
+ . description ( "Generate shell completions (internal command)" )
446
+ . argument ( "<type>" , "Type of completion to generate" )
447
+ . option ( "--current <current>" , "Current word being completed" )
448
+ . option ( "--previous <previous>" , "Previous word in command line" )
449
+ . option ( "--line <line>" , "Full command line" )
450
+ . action ( async ( type , options ) => {
451
+ try {
452
+ await completionCommand ( type , {
453
+ current : options . current ,
454
+ previous : options . previous ,
455
+ line : options . line ,
456
+ } ) ;
457
+ } catch {
458
+ // Silently fail for completions
459
+ }
460
+ } ) ;
461
+
462
+ // Install completion command
463
+ const installCompletion = new Command ( "install-completion" )
464
+ . description ( "Install shell completion scripts" )
465
+ . argument (
466
+ "[shell]" ,
467
+ "Target shell (bash, zsh). Auto-detected if not specified" ,
468
+ )
469
+ . option ( "-o, --output <path>" , "Output path for completion script" )
470
+ . action ( async ( shell , options ) => {
471
+ try {
472
+ await installCompletionCommand ( shell , {
473
+ output : options . output ,
474
+ } ) ;
475
+ } catch ( error ) {
476
+ console . error (
477
+ "❌ Failed to install completion:" ,
478
+ error instanceof Error ? error . message : String ( error ) ,
479
+ ) ;
480
+ process . exit ( 1 ) ;
481
+ }
482
+ } ) ;
483
+
373
484
// Hosting parent command
374
485
const hosting = new Command ( "hosting" )
375
486
. description ( "Manage hosting apps in a workspace." )
@@ -463,10 +574,13 @@ const program = new Command()
463
574
. addCommand ( dev )
464
575
. addCommand ( configure )
465
576
. addCommand ( add )
577
+ . addCommand ( callTool )
466
578
. addCommand ( upgrade )
467
579
. addCommand ( update )
468
580
. addCommand ( linkCmd )
469
581
. addCommand ( gen )
470
- . addCommand ( create ) ;
582
+ . addCommand ( create )
583
+ . addCommand ( completion )
584
+ . addCommand ( installCompletion ) ;
471
585
472
586
program . parse ( ) ;
0 commit comments