forked from aws/agentcore-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathattach.ts
More file actions
118 lines (103 loc) · 3.89 KB
/
Copy pathattach.ts
File metadata and controls
118 lines (103 loc) · 3.89 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { ConfigIO } from '../../lib';
import type { McpRuntimeBinding } from '../../schema';
// ─────────────────────────────────────────────────────────────────────────────
// Data Loading Functions
// ─────────────────────────────────────────────────────────────────────────────
/**
* Get list of agent names from project spec.
*/
export async function getAvailableAgents(): Promise<string[]> {
try {
const configIO = new ConfigIO();
const project = await configIO.readProjectSpec();
return project.runtimes.map(agent => agent.name);
} catch {
return [];
}
}
/**
* Get list of memory names from project spec.
*/
export async function getMemories(): Promise<string[]> {
try {
const configIO = new ConfigIO();
const project = await configIO.readProjectSpec();
return project.memories.map(m => m.name);
} catch {
return [];
}
}
/**
* Get list of credential names from project spec.
*/
export async function getCredentials(): Promise<string[]> {
try {
const configIO = new ConfigIO();
const project = await configIO.readProjectSpec();
return project.credentials.map(c => c.name);
} catch {
return [];
}
}
/**
* Get list of MCP runtime tools from agentcore.json.
*/
export async function getMcpRuntimeTools(): Promise<string[]> {
try {
const configIO = new ConfigIO();
const project = await configIO.readProjectSpec();
if (!project?.mcpRuntimeTools) return [];
return project.mcpRuntimeTools.map(tool => tool.name);
} catch {
return [];
}
}
/**
* Get list of gateways from agentcore.json.
*/
export async function getGateways(): Promise<string[]> {
try {
const configIO = new ConfigIO();
const project = await configIO.readProjectSpec();
return project.agentCoreGateways.map(gw => gw.name);
} catch {
return [];
}
}
// ─────────────────────────────────────────────────────────────────────────────
// MCP Binding Functions
// ─────────────────────────────────────────────────────────────────────────────
export interface BindMcpRuntimeConfig {
runtimeName: string;
envVarName: string;
}
/**
* Bind an agent to an MCP runtime tool.
* Adds the binding to the MCP runtime's bindings array in agentcore.json.
*/
export async function bindMcpRuntimeToAgent(mcpRuntimeName: string, config: BindMcpRuntimeConfig): Promise<void> {
const configIO = new ConfigIO();
// Validate the runtime exists
const project = await configIO.readProjectSpec();
const agent = project.runtimes.find(a => a.name === config.runtimeName);
if (!agent) {
throw new Error(`Runtime "${config.runtimeName}" not found.`);
}
// Find the MCP runtime tool
const runtimeTool = project.mcpRuntimeTools?.find(t => t.name === mcpRuntimeName);
if (!runtimeTool) {
throw new Error(`MCP runtime tool "${mcpRuntimeName}" not found in agentcore.json.`);
}
// Initialize bindings array if needed
runtimeTool.bindings ??= [];
// Check if already bound
if (runtimeTool.bindings.some(b => b.runtimeName === config.runtimeName)) {
throw new Error(`Runtime "${config.runtimeName}" is already bound to MCP runtime "${mcpRuntimeName}".`);
}
const binding: McpRuntimeBinding = {
runtimeName: config.runtimeName,
envVarName: config.envVarName,
};
runtimeTool.bindings.push(binding);
await configIO.writeProjectSpec(project);
}