import { Tool } from '@modelcontextprotocol/sdk/types.js';
import { ClickyClient, DateRange } from '../clicky-client.js';
export const getPageTrafficTool: Tool = {
name: 'get_page_traffic',
description: 'Get traffic data for a specific page by filtering with its URL',
inputSchema: {
type: 'object',
properties: {
url: {
type: 'string',
description: 'Full URL or path of the page to get traffic for (e.g., https://example.com/path or /path)'
},
start_date: {
type: 'string',
pattern: '^\\d{4}-\\d{2}-\\d{2}$',
description: 'Start date in YYYY-MM-DD format'
},
end_date: {
type: 'string',
pattern: '^\\d{4}-\\d{2}-\\d{2}$',
description: 'End date in YYYY-MM-DD format'
}
},
required: ['url', 'start_date', 'end_date']
}
};
export async function handleGetPageTraffic(
args: { url: string; start_date: string; end_date: string },
clickyClient: ClickyClient
) {
try {
const dateRange: DateRange = {
startDate: args.start_date,
endDate: args.end_date
};
const data = await clickyClient.getPageTraffic(args.url, dateRange);
return {
content: [
{
type: 'text',
text: JSON.stringify(data, null, 2)
}
]
};
} catch (error) {
return {
content: [
{
type: 'text',
text: `Error fetching page traffic: ${error instanceof Error ? error.message : 'Unknown error'}`
}
],
isError: true
};
}
}