forked from aws/agentcore-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGatewayTargetRenderer.ts
More file actions
86 lines (81 loc) · 2.76 KB
/
Copy pathGatewayTargetRenderer.ts
File metadata and controls
86 lines (81 loc) · 2.76 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
import type { ToolDefinition } from '../../schema';
import type { ComputeHost, TargetLanguage } from '../tui/screens/mcp/types';
import { copyAndRenderDir } from './render';
import { getTemplatePath } from './templateRoot';
/**
* Tool definitions for the Lambda template.
* Each tool has a complete inputSchema for proper gateway integration.
*/
export const LAMBDA_TEMPLATE_TOOLS: ToolDefinition[] = [
{
name: 'lookup_ip',
description: 'Look up geolocation and network info for an IP address',
inputSchema: {
type: 'object',
properties: {
ip_address: { type: 'string', description: 'IPv4 or IPv6 address to look up' },
},
required: ['ip_address'],
},
},
{
name: 'get_random_user',
description: 'Generate a random user profile for testing or mock data',
inputSchema: { type: 'object' },
},
{
name: 'fetch_post',
description: 'Fetch a post by ID from JSONPlaceholder API',
inputSchema: {
type: 'object',
properties: {
post_id: { type: 'integer', description: 'The post ID (1-100)' },
},
required: ['post_id'],
},
},
];
/**
* Get tool definitions for a template based on compute host.
* Lambda template has multiple pre-defined tools with proper inputSchemas.
* AgentCoreRuntime uses a single generic tool definition.
*/
export function getTemplateToolDefinitions(toolName: string, host: ComputeHost): ToolDefinition[] {
if (host === 'Lambda') {
// Prefix template tool names with the gateway target name to avoid conflicts
// when adding multiple Lambda tools to the same project
return LAMBDA_TEMPLATE_TOOLS.map(tool => ({
...tool,
name: `${toolName}_${tool.name}`,
}));
}
// AgentCoreRuntime - single tool with generic schema
return [
{
name: toolName,
description: `Tool for ${toolName}`,
inputSchema: { type: 'object' },
},
];
}
/**
* Renders a gateway target project template to the specified output directory.
* @param toolName - Name of the tool (used for {{ Name }} substitution)
* @param outputDir - Target directory for the project
* @param language - Target language ('Python' or 'TypeScript')
* @param host - Compute host ('Lambda' or 'AgentCoreRuntime')
*/
export async function renderGatewayTargetTemplate(
toolName: string,
outputDir: string,
language: TargetLanguage,
host: ComputeHost = 'AgentCoreRuntime'
): Promise<void> {
if (language !== 'Python') {
throw new Error(`Gateway target templates for ${language} are not yet supported.`);
}
// Select template based on compute host
const templateSubdir = host === 'Lambda' ? 'python-lambda' : 'python';
const templateDir = getTemplatePath('mcp', templateSubdir);
await copyAndRenderDir(templateDir, outputDir, { Name: toolName });
}