import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
import type { ToolContext } from "../utils/api.js";
export function registerPing(server: McpServer, ctx: ToolContext): void {
server.registerTool(
"ping",
{
description: "Health check. Verifies env and optionally the Storyblok API. Set check_api=1 to call the API.",
inputSchema: { check_api: z.literal(1).optional() },
},
async (a) => {
ctx.requireConfig();
const out: { ok: boolean; env: boolean; api?: string; error?: string } = { ok: true, env: true };
if (a?.check_api === 1) {
try {
await ctx.api("");
out.api = "ok";
} catch (e: unknown) {
out.ok = false;
out.api = "error";
out.error = e instanceof Error ? e.message : String(e);
}
}
return { content: [{ type: "text" as const, text: JSON.stringify(out, null, 2) }] };
}
);
}