import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
import { apiRequest, formatResponse, textContent } from "../api-client.js";
interface Partner {
id: number;
name: string;
legacy_id?: number | null;
status?: string;
is_test?: boolean;
email?: string | null;
email_suffix?: string | null;
headline?: string | null;
description?: string | null;
website?: string | null;
main_category?: { id: number; name: string } | null;
created_at?: string;
updated_at?: string;
}
interface PartnerCategory {
id: number;
name: string;
}
interface PartnerDocument {
id: number;
title: string;
url?: string | null;
category?: string | null;
}
export function registerPartnerTools(server: McpServer) {
// List partners
server.tool(
"list_partners",
"List partners (vendors/ad networks) with optional filters.",
{
name_cont: z.string().optional().describe("Filter partners whose name contains this substring"),
status: z.enum(["onboarding", "archived", "paused", "running", "all"]).optional().describe("Filter by status (default: running)"),
hide_test_data: z.boolean().optional().describe("Hide test partners (default: true)"),
category_id: z.number().optional().describe("Filter by category ID"),
},
async ({ name_cont, status, hide_test_data, category_id }) => {
const response = await apiRequest<Partner[]>("/partners.json", {
name_cont,
status,
hide_test_data,
category_id,
});
if (response.error) {
return textContent(`Error: ${response.error}`);
}
return textContent(formatResponse(response));
}
);
// Get partner details
server.tool(
"get_partner",
"Get detailed information about a specific partner by ID.",
{
id: z.number().describe("The partner ID"),
},
async ({ id }) => {
const response = await apiRequest<Partner>(`/partners/${id}.json`);
if (response.error) {
return textContent(`Error: ${response.error}`);
}
return textContent(formatResponse(response));
}
);
// List partner categories
server.tool(
"list_partner_categories",
"List all partner categories with their IDs.",
{},
async () => {
const response = await apiRequest<PartnerCategory[]>("/partner_categories.json");
if (response.error) {
return textContent(`Error: ${response.error}`);
}
return textContent(formatResponse(response));
}
);
// List partner documents
server.tool(
"list_partner_documents",
"List documents associated with partners.",
{
partner_id: z.number().optional().describe("Filter by partner ID"),
title_cont: z.string().optional().describe("Filter documents whose title contains this substring"),
category: z.enum(["onboarding_paperwork", "media_deck", "other"]).optional().describe("Filter by document category"),
},
async ({ partner_id, title_cont, category }) => {
const response = await apiRequest<PartnerDocument[]>("/partner_documents.json", {
partner_id,
title_cont,
category,
});
if (response.error) {
return textContent(`Error: ${response.error}`);
}
return textContent(formatResponse(response));
}
);
}