examples/kai.ts starts the server over stdio as a client does and asks kai_choice once.

This commit is contained in:
2026-09-28 15:35:10 -07:00
parent 8d13859eb0
commit e63e2b3e8c
+26
View File
@@ -0,0 +1,26 @@
// Starts @hanzo/mcp over stdio as an MCP client does, lists its kai tools and calls kai_choice once.
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
const [command, ...args] = (process.env.MCP_SERVER ?? "npx -y @hanzo/mcp serve").split(" ");
const transport = new StdioClientTransport({ command, args, env: { HANZO_API_KEY: process.env.HANZO_API_KEY ?? "" } });
const client = new Client({ name: "kai-docs", version: "1.0.0" });
await client.connect(transport);
const { tools } = await client.listTools();
console.log(tools.map((tool) => tool.name).filter((name) => name.startsWith("kai_")).join(", "));
const result = await client.callTool({
name: "kai_choice",
arguments: {
state: "I was charged twice for my March invoice and the second charge is still pending.",
instructions: "Which team should handle this ticket?",
criteria: {
billing: "charges, invoices and refunds",
technical: "bugs, errors and outages",
account: "logins and profiles",
},
},
});
console.log((result.content as { type: string; text: string }[])[0].text);
await client.close();