import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
import { apiRequest, formatResponse, textContent } from "../api-client.js";
interface PlaybookItem {
id: number;
title: string;
content?: string | null;
playbook_id?: number;
associable_type?: string | null;
associable_id?: number | null;
created_at?: string;
updated_at?: string;
}
interface Playbook {
id: number;
name: string;
slug?: string;
description?: string | null;
playbook_items?: { id: number; title: string }[];
}
export function registerPlaybookTools(server: McpServer) {
// List playbooks
server.tool(
"list_playbooks",
"List playbooks accessible to the current user. Playbooks are guides and documentation.",
{
name_cont: z.string().optional().describe("Filter playbooks whose name contains this substring"),
},
async ({ name_cont }) => {
const response = await apiRequest<Playbook[]>("/playbooks.json", {
name_cont,
});
if (response.error) {
return textContent(`Error: ${response.error}`);
}
return textContent(formatResponse(response));
}
);
// Get playbook details
server.tool(
"get_playbook",
"Get detailed information about a playbook, including its list of items.",
{
id: z.string().describe("The playbook ID or slug"),
},
async ({ id }) => {
const response = await apiRequest<Playbook>(`/playbooks/${id}.json`);
if (response.error) {
return textContent(`Error: ${response.error}`);
}
return textContent(formatResponse(response));
}
);
// Get playbook item content
server.tool(
"get_playbook_item",
"Get the full content of a specific playbook item.",
{
id: z.number().describe("The playbook item ID"),
},
async ({ id }) => {
const response = await apiRequest<PlaybookItem>(`/playbook_items/${id}.json`);
if (response.error) {
return textContent(`Error: ${response.error}`);
}
return textContent(formatResponse(response));
}
);
}