import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
import { apiRequest, formatResponse, textContent } from "../api-client.js";
interface Client {
id: number;
name: string;
legacy_id?: number | null;
active?: boolean;
is_test?: boolean;
alert_channel?: string | null;
email_suffix?: string | null;
headline?: string | null;
website?: string | null;
web_url?: string;
created_at?: string;
updated_at?: string;
pod?: { id: number; name: string } | null;
}
interface ClientDocument {
id: number;
title: string;
url?: string | null;
category?: string | null;
}
export function registerClientTools(server: McpServer) {
// List clients
server.tool(
"list_clients",
"List clients with optional filters. Returns client names, IDs, and legacy IDs.",
{
name_cont: z.string().optional().describe("Filter clients whose name contains this substring"),
active_status: z.enum(["active", "inactive", "all"]).optional().describe("Filter by active status (default: active)"),
pod_id: z.number().optional().describe("Filter by pod ID"),
},
async ({ name_cont, active_status, pod_id }) => {
const response = await apiRequest<Client[]>("/clients.json", {
name_cont,
active_status,
pod_id,
});
if (response.error) {
return textContent(`Error: ${response.error}`);
}
return textContent(formatResponse(response));
}
);
// Get client details
server.tool(
"get_client",
"Get detailed information about a specific client by ID.",
{
id: z.number().describe("The client ID"),
},
async ({ id }) => {
const response = await apiRequest<Client>(`/clients/${id}.json`);
if (response.error) {
return textContent(`Error: ${response.error}`);
}
return textContent(formatResponse(response));
}
);
// List client documents
server.tool(
"list_client_documents",
"List documents associated with clients. Can filter by client ID, title, or category.",
{
client_id: z.number().optional().describe("Filter by client ID"),
title_cont: z.string().optional().describe("Filter documents whose title contains this substring"),
category: z.enum(["media_plan", "adops_note", "creative", "insertion_order", "other"]).optional().describe("Filter by document category"),
},
async ({ client_id, title_cont, category }) => {
const response = await apiRequest<ClientDocument[]>("/client_documents.json", {
client_id,
title_cont,
category,
});
if (response.error) {
return textContent(`Error: ${response.error}`);
}
return textContent(formatResponse(response));
}
);
}