Skip to content

Commit 1b605c3

Browse files
committed
fix tests
1 parent 429d227 commit 1b605c3

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

packages/use-agently/src/commands/tools.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ describe("tools command (free)", () => {
7575
"-o",
7676
"tui",
7777
"tools",
78+
"--uri",
79+
fixture.agent.getAgentHost() + "/mcp",
7880
"call",
7981
"--tool",
8082
"echo",
8183
"--args",
8284
'{"message":"hello from tools"}',
83-
"--uri",
84-
fixture.agent.getAgentHost() + "/mcp",
8585
]);
8686
expect(out.stdout).toStrictEqual("hello from tools");
8787

@@ -108,13 +108,13 @@ describe("tools command x402 payment (paid)", () => {
108108
"test",
109109
"use-agently",
110110
"tools",
111+
"--uri",
112+
fixture.agent.getAgentHost() + "/mcp",
111113
"call",
112114
"--tool",
113115
"paid-echo-tool",
114116
"--args",
115117
'{"message":"dry run"}',
116-
"--uri",
117-
fixture.agent.getAgentHost() + "/mcp",
118118
]);
119119
} catch {
120120
// expected: process.exit throws
@@ -137,13 +137,13 @@ describe("tools command x402 payment (paid)", () => {
137137
"-o",
138138
"tui",
139139
"tools",
140+
"--uri",
141+
fixture.agent.getAgentHost() + "/mcp",
140142
"call",
141143
"--tool",
142144
"paid-echo-tool",
143145
"--args",
144146
'{"message":"paid cli test"}',
145-
"--uri",
146-
fixture.agent.getAgentHost() + "/mcp",
147147
"--pay",
148148
]);
149149

@@ -180,13 +180,13 @@ describe("tools command x402 payment (paid)", () => {
180180
"test",
181181
"use-agently",
182182
"tools",
183+
"--uri",
184+
fixture.agent.getAgentHost() + "/mcp",
183185
"call",
184186
"--tool",
185187
"paid-echo-tool",
186188
"--args",
187189
'{"message":"should fail"}',
188-
"--uri",
189-
fixture.agent.getAgentHost() + "/mcp",
190190
"--pay",
191191
]);
192192
} catch {
@@ -211,13 +211,13 @@ describe("tools command x402 payment (paid)", () => {
211211
"-o",
212212
"json",
213213
"tools",
214+
"--uri",
215+
fixture.agent.getAgentHost() + "/mcp",
214216
"call",
215217
"--tool",
216218
"paid-echo-tool",
217219
"--args",
218220
'{"message":"json output test"}',
219-
"--uri",
220-
fixture.agent.getAgentHost() + "/mcp",
221221
"--pay",
222222
]);
223223

packages/use-agently/src/commands/tools.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Command } from "commander";
22
import boxen from "boxen";
33
import { formatUnits } from "viem";
4-
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
54
import {
65
DryRunTransaction,
76
PayTransaction,
@@ -40,16 +39,13 @@ function checkSpendLimit(err: DryRunPaymentRequired, maxSpendPerCall: number): v
4039

4140
export 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

6056
const 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

Comments
 (0)