diff --git a/src/assets/__tests__/__snapshots__/assets.snapshot.test.ts.snap b/src/assets/__tests__/__snapshots__/assets.snapshot.test.ts.snap index 241253b59..84718b089 100644 --- a/src/assets/__tests__/__snapshots__/assets.snapshot.test.ts.snap +++ b/src/assets/__tests__/__snapshots__/assets.snapshot.test.ts.snap @@ -5693,38 +5693,33 @@ Thumbs.db exports[`Assets Directory Snapshots > TypeScript assets > typescript/typescript/http/strands/base/main.ts should match snapshot 1`] = ` "import { BedrockAgentCoreApp } from 'bedrock-agentcore/runtime'; -import { Agent, tool } from '@strands-agents/sdk'; +import { Agent, McpClient, tool, type ToolList } from '@strands-agents/sdk'; +import { z } from 'zod'; import { loadModel } from './model/load.js'; import { getStreamableHttpMcpClient } from './mcp_client/client.js'; -// Define a collection of MCP clients -const mcpClients = [getStreamableHttpMcpClient()].filter(Boolean); +// Define a collection of MCP clients (filter out anything that failed to initialize) +const mcpClients: McpClient[] = [getStreamableHttpMcpClient()].filter( + (client): client is McpClient => Boolean(client) +); // Define a collection of tools used by the model -const tools: unknown[] = []; +const tools: ToolList = []; -// Define a simple function tool +// Define a simple function tool — the Zod schema gives us type inference and runtime validation for free const addNumbers = tool({ name: 'add_numbers', description: 'Return the sum of two numbers', - inputSchema: { - type: 'object', - properties: { - a: { type: 'number' }, - b: { type: 'number' }, - }, - required: ['a', 'b'], - }, - callback: async ({ a, b }: { a: number; b: number }) => a + b, + inputSchema: z.object({ + a: z.number(), + b: z.number(), + }), + callback: async ({ a, b }) => a + b, }); tools.push(addNumbers); -// Add MCP clients to tools if available -for (const mcpClient of mcpClients) { - if (mcpClient) { - tools.push(mcpClient); - } -} +// Add MCP clients to tools +tools.push(...mcpClients); const SYSTEM_PROMPT = \` You are a helpful assistant. Use tools when appropriate. @@ -5912,7 +5907,8 @@ exports[`Assets Directory Snapshots > TypeScript assets > typescript/typescript/ "@modelcontextprotocol/sdk": "^1.25.2", "@strands-agents/sdk": "1.0.0-rc.4", "bedrock-agentcore": "^0.2.4", - "tsx": "^4.19.0" + "tsx": "^4.19.0", + "zod": "^4.4.3" }, "devDependencies": { "@types/node": "^22.0.0", diff --git a/src/assets/typescript/http/strands/base/main.ts b/src/assets/typescript/http/strands/base/main.ts index 698b9afc4..84428c181 100644 --- a/src/assets/typescript/http/strands/base/main.ts +++ b/src/assets/typescript/http/strands/base/main.ts @@ -1,36 +1,31 @@ import { BedrockAgentCoreApp } from 'bedrock-agentcore/runtime'; -import { Agent, tool } from '@strands-agents/sdk'; +import { Agent, McpClient, tool, type ToolList } from '@strands-agents/sdk'; +import { z } from 'zod'; import { loadModel } from './model/load.js'; import { getStreamableHttpMcpClient } from './mcp_client/client.js'; -// Define a collection of MCP clients -const mcpClients = [getStreamableHttpMcpClient()].filter(Boolean); +// Define a collection of MCP clients (filter out anything that failed to initialize) +const mcpClients: McpClient[] = [getStreamableHttpMcpClient()].filter( + (client): client is McpClient => Boolean(client) +); // Define a collection of tools used by the model -const tools: unknown[] = []; +const tools: ToolList = []; -// Define a simple function tool +// Define a simple function tool — the Zod schema gives us type inference and runtime validation for free const addNumbers = tool({ name: 'add_numbers', description: 'Return the sum of two numbers', - inputSchema: { - type: 'object', - properties: { - a: { type: 'number' }, - b: { type: 'number' }, - }, - required: ['a', 'b'], - }, - callback: async ({ a, b }: { a: number; b: number }) => a + b, + inputSchema: z.object({ + a: z.number(), + b: z.number(), + }), + callback: async ({ a, b }) => a + b, }); tools.push(addNumbers); -// Add MCP clients to tools if available -for (const mcpClient of mcpClients) { - if (mcpClient) { - tools.push(mcpClient); - } -} +// Add MCP clients to tools +tools.push(...mcpClients); const SYSTEM_PROMPT = ` You are a helpful assistant. Use tools when appropriate. diff --git a/src/assets/typescript/http/strands/base/package.json b/src/assets/typescript/http/strands/base/package.json index 0edb269db..09680ec6f 100644 --- a/src/assets/typescript/http/strands/base/package.json +++ b/src/assets/typescript/http/strands/base/package.json @@ -22,7 +22,8 @@ "@modelcontextprotocol/sdk": "^1.25.2", "@strands-agents/sdk": "1.0.0-rc.4", "bedrock-agentcore": "^0.2.4", - "tsx": "^4.19.0" + "tsx": "^4.19.0", + "zod": "^4.4.3" }, "devDependencies": { "@types/node": "^22.0.0",