import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
import { apiRequest, formatResponse, textContent } from "../api-client.js";
interface ClickUrl {
id: number;
name?: string | null;
legacy_id?: string | null;
active?: boolean;
status?: string;
link_type?: string | null;
mmp_click_tracking_url?: string | null;
mmp_impression_tracking_url?: string | null;
campaign?: { id: number; name: string } | null;
client?: { id: number; name: string } | null;
partner?: { id: number; name: string } | null;
track_party?: { id: number; name: string } | null;
client_paid_actions?: string[] | null;
partner_paid_actions?: string[] | null;
postbacks?: { event: string; url: string }[];
created_at?: string;
updated_at?: string;
}
export function registerClickUrlTools(server: McpServer) {
// List click URLs
server.tool(
"list_click_urls",
"List click URLs (tracking links) used for campaign attribution.",
{},
async () => {
const response = await apiRequest<ClickUrl[]>("/click_urls.json");
if (response.error) {
return textContent(`Error: ${response.error}`);
}
return textContent(formatResponse(response));
}
);
// Get click URL details (uses legacy_id)
server.tool(
"get_click_url",
"Get detailed information about a specific click URL by legacy ID.",
{
legacy_id: z.number().describe("The legacy ID of the click URL"),
},
async ({ legacy_id }) => {
const response = await apiRequest<ClickUrl>(`/click_urls/${legacy_id}/legacy.json`);
if (response.error) {
return textContent(`Error: ${response.error}`);
}
return textContent(formatResponse(response));
}
);
}