import { McpAgent } from "agents/mcp";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
import type { GeneratedEnv } from "@ayjnt/env";
type State = { invocations: number };
export default class Tools extends McpAgent<GeneratedEnv, State> {
override initialState: State = { invocations: 0 };
server = new McpServer({ name: "my-tools", version: "0.1.0" });
async init() {
this.server.tool("echo", "Echo the input.", { text: z.string() },
async ({ text }) => {
this.setState({ invocations: this.state.invocations + 1 });
return { content: [{ type: "text", text }] };
});
this.server.tool("add", "Add two numbers.",
{ a: z.number(), b: z.number() },
async ({ a, b }) => {
this.setState({ invocations: this.state.invocations + 1 });
return { content: [{ type: "text", text: String(a + b) }] };
});
}
}