-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathtool-command.ts
More file actions
82 lines (78 loc) · 3.16 KB
/
Copy pathtool-command.ts
File metadata and controls
82 lines (78 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { findConfigRoot } from '../../../lib';
import { getErrorMessage } from '../../errors';
import { handleAddTool } from './tool-action';
import type { Command } from '@commander-js/extra-typings';
export function registerAddTool(addCmd: Command): void {
addCmd
.command('tool')
.description('Add a tool to a harness')
.requiredOption('--harness <name>', 'Target harness name')
.requiredOption(
'--type <type>',
'Tool type: agentcore_browser, agentcore_code_interpreter, remote_mcp, agentcore_gateway, inline_function'
)
.requiredOption('--name <name>', 'Tool name')
.option('--url <url>', 'MCP server URL (required for remote_mcp)')
.option('--browser-arn <arn>', 'Custom browser ARN (optional for agentcore_browser)')
.option('--code-interpreter-arn <arn>', 'Custom code interpreter ARN (optional for agentcore_code_interpreter)')
.option('--gateway-arn <arn>', 'Gateway ARN (for agentcore_gateway)')
.option('--gateway <name>', 'Project gateway name — resolves ARN from deployed state (for agentcore_gateway)')
.option(
'--outbound-auth <type>',
'Gateway outbound auth: awsIam, none, or oauth (default: awsIam if omitted) [agentcore_gateway]'
)
.option('--provider-arn <arn>', 'OAuth credential provider ARN (required when --outbound-auth oauth)')
.option(
'--scopes <scopes>',
'Comma-separated OAuth scopes (required when --outbound-auth oauth), e.g. "openid,profile" or "https://api.example.com/read"'
)
.option(
'--grant-type <type>',
'OAuth grant type: CLIENT_CREDENTIALS or USER_FEDERATION (for --outbound-auth oauth)'
)
.option('--json', 'Output as JSON')
.action(async cliOptions => {
if (!findConfigRoot()) {
console.error('No agentcore project found. Run `agentcore create` first.');
process.exit(1);
}
try {
const result = await handleAddTool({
harness: cliOptions.harness,
type: cliOptions.type,
name: cliOptions.name,
url: cliOptions.url,
browserArn: cliOptions.browserArn,
codeInterpreterArn: cliOptions.codeInterpreterArn,
gatewayArn: cliOptions.gatewayArn,
gateway: cliOptions.gateway,
outboundAuth: cliOptions.outboundAuth,
providerArn: cliOptions.providerArn,
scopes: cliOptions.scopes,
grantType: cliOptions.grantType,
json: cliOptions.json,
});
if (!result.success) {
if (cliOptions.json) {
console.log(JSON.stringify(result));
} else {
console.error(result.error);
}
process.exit(1);
}
if (cliOptions.json) {
console.log(JSON.stringify(result));
} else {
console.log(`Added tool '${result.toolName}' to harness '${result.harnessName}'.`);
console.log(`Run 'agentcore deploy' to apply changes.`);
}
} catch (error) {
if (cliOptions.json) {
console.log(JSON.stringify({ success: false, error: getErrorMessage(error) }));
} else {
console.error(getErrorMessage(error));
}
process.exit(1);
}
});
}