11import { Command } from "commander" ;
22import boxen from "boxen" ;
33import { formatUnits } from "viem" ;
4- import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js" ;
54import {
65 DryRunTransaction ,
76 PayTransaction ,
@@ -40,16 +39,13 @@ function checkSpendLimit(err: DryRunPaymentRequired, maxSpendPerCall: number): v
4039
4140export const toolsCommand = new Command ( "tools" )
4241 . description ( "List or call tools on an MCP server" )
43- . option ( "-u, --uri <value>" , "MCP server URL or CAIP-19 ID" )
42+ . requiredOption ( "-u, --uri <value>" , "MCP server URL or CAIP-19 ID" )
43+ . showHelpAfterError ( true )
4444 . addHelpText (
4545 "after" ,
4646 "\nExamples:\n use-agently tools --uri https://example.com/mcp\n use-agently tools --uri eip155:8453/erc8004:0x1234/1\n use-agently tools call --uri https://example.com/mcp --tool echo" ,
4747 )
48- . action ( async ( options : { uri ?: string } , command : Command ) => {
49- if ( ! options . uri ) {
50- command . outputHelp ( ) ;
51- return ;
52- }
48+ . action ( async ( options : { uri : string } , command : Command ) => {
5349 const tools = await listMcpTools ( defaultClient , options . uri , {
5450 clientInfo : { name : "use-agently" , version : pkg . version } ,
5551 fetchImpl : clientFetch ,
@@ -59,7 +55,6 @@ export const toolsCommand = new Command("tools")
5955
6056const toolsCallCommand = new Command ( "call" )
6157 . description ( "Call a specific tool on an MCP server" )
62- . requiredOption ( "-u, --uri <value>" , "MCP server URL or CAIP-19 ID" )
6358 . requiredOption ( "--tool <name>" , "Tool name to call" )
6459 . option ( "--args <json>" , "JSON arguments to pass to the tool" )
6560 . option ( "--pay" , "Authorize payment if the tool requires it (default: dry-run, shows cost only)" )
@@ -68,8 +63,8 @@ const toolsCallCommand = new Command("call")
6863 "after" ,
6964 '\nExamples:\n use-agently tools call --uri https://example.com/mcp --tool echo --args \'{"message":"hello"}\'\n use-agently tools call --uri https://example.com/mcp --tool paid-tool --args \'{"message":"hello"}\' --pay' ,
7065 )
71- . action ( async ( options : { uri : string ; tool : string ; args ?: string ; pay ?: boolean } , command : Command ) => {
72- const uri = options . uri ;
66+ . action ( async ( options : { tool : string ; args ?: string ; pay ?: boolean } , command : Command ) => {
67+ const uri = command . optsWithGlobals ( ) . uri as string ;
7368 const tool = options . tool ;
7469 let args : Record < string , unknown > = { } ;
7570 if ( options . args !== undefined ) {
@@ -146,8 +141,11 @@ function tryParseJson(text: string): unknown {
146141 }
147142}
148143
149- function outputMcpResult ( result : CallToolResult , command : Command ) : void {
150- const content = result . content as Array < { type : string ; text ?: string } > ;
144+ function outputMcpResult (
145+ result : { content : Array < { type : string ; text ?: string } > ; isError ?: boolean } ,
146+ command : Command ,
147+ ) : void {
148+ const content = result . content ;
151149
152150 // Handle error responses
153151 if ( result . isError ) {
0 commit comments