Skip to main content
Glama
colintoh

Clicky MCP Server

by colintoh

get_traffic_sources

Retrieve traffic source analytics from Clicky to analyze where website visitors originate, with optional filtering by specific page URL for targeted insights.

Instructions

Get traffic sources breakdown from Clicky analytics. Optionally filter by specific page URL.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
start_dateYesStart date in YYYY-MM-DD format
end_dateYesEnd date in YYYY-MM-DD format
page_urlNoOptional: Full URL or path of the page to get traffic sources for (e.g., https://example.com/path or /path)

Implementation Reference

  • The handler function that processes input arguments, calls the Clicky client to fetch traffic sources, transforms the raw API response into a structured JSON format suitable for LLMs, and handles errors by returning an error response.
    export async function handleGetTrafficSources(
      args: { start_date: string; end_date: string; page_url?: string },
      clickyClient: ClickyClient
    ) {
      try {
        const dateRange: DateRange = {
          startDate: args.start_date,
          endDate: args.end_date
        };
    
        const data = await clickyClient.getTrafficSources(dateRange, args.page_url);
    
        // Transform the response to be LLM-friendly
        const cleanedData = data.map((typeData: any) => ({
          type: typeData.type,
          dates: typeData.dates.map((dateData: any) => ({
            date: dateData.date,
            traffic_sources: dateData.items.map((item: any) => ({
              source: item.title,
              visitors: parseInt(item.value),
              percentage: parseFloat(item.value_percent || '0')
            }))
          }))
        }));
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(cleanedData, null, 2)
            }
          ]
        };
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `Error fetching traffic sources: ${error instanceof Error ? error.message : 'Unknown error'}`
            }
          ],
          isError: true
        };
      }
    }
  • The Tool object definition including the input schema that validates start_date and end_date (required, YYYY-MM-DD format) and optional page_url.
    export const getTrafficSourcesTool: Tool = {
      name: 'get_traffic_sources',
      description: 'Get traffic sources breakdown from Clicky analytics. Optionally filter by specific page URL.',
      inputSchema: {
        type: 'object',
        properties: {
          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'
          },
          page_url: {
            type: 'string',
            description: 'Optional: Full URL or path of the page to get traffic sources for (e.g., https://example.com/path or /path)'
          }
        },
        required: ['start_date', 'end_date']
      }
    };
  • src/index.ts:91-99 (registration)
    Registers the getTrafficSourcesTool in the list of available tools for the ListToolsRequest handler.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: [
        getTotalVisitorsTool,
        getDomainVisitorsTool,
        getTopPagesTool,
        getTrafficSourcesTool,
        getPageTrafficTool,
      ],
    }));
  • src/index.ts:115-116 (registration)
    Registers the handler dispatch for 'get_traffic_sources' in the CallToolRequest switch statement.
    case 'get_traffic_sources':
      return await handleGetTrafficSources(args as any, this.clickyClient);
  • Supporting method in ClickyClient that performs the actual API request for traffic sources, using segmentation for page-specific data or general traffic-sources type.
    async getTrafficSources(dateRange: DateRange, pageUrl?: string): Promise<any> {
      this.validateDateRange(dateRange);
    
      let params: any = {
        site_id: this.siteId,
        sitekey: this.siteKey,
        date: `${dateRange.startDate},${dateRange.endDate}`,
        output: 'json'
      };
    
      if (pageUrl) {
        // Extract path from URL and encode it
        let path: string;
        try {
          const urlObj = new URL(pageUrl);
          path = urlObj.pathname;
        } catch (error) {
          // If URL parsing fails, assume it's already a path
          path = pageUrl.startsWith('/') ? pageUrl : '/' + pageUrl;
        }
    
        // Use segmentation API for page-specific traffic sources
        params.type = 'segmentation';
        params.href = path; // Axios will handle the URL encoding automatically
        params.segments = 'traffic-sources';
      } else {
        // Use general traffic sources API
        params.type = 'traffic-sources';
      }
    
      const response = await this.client.get('', { params });
    
      return response.data;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions an optional filter but does not describe the return format, pagination, rate limits, authentication needs, or whether this is a read-only operation. For a tool with no annotations, this leaves significant gaps in understanding its behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the main purpose and includes the optional filter. There is no wasted language, and it is appropriately sized for the tool's complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is incomplete for a tool with three parameters. It covers the basic purpose and optional filtering but lacks details on return values, error handling, or behavioral traits. This is adequate as a minimum but has clear gaps in providing a full context for the agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters (start_date, end_date, page_url) with descriptions and formats. The description adds marginal value by mentioning the optional filter by page URL, but does not provide additional semantics beyond what the schema specifies, such as examples or constraints.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Get') and resource ('traffic sources breakdown from Clicky analytics'), making the purpose evident. It distinguishes from siblings by focusing on traffic sources rather than visitors, page traffic, or top pages. However, it doesn't explicitly contrast with sibling tools like 'get_domain_visitors' or 'get_page_traffic' beyond the resource type.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage through the optional filter by page URL, suggesting it can be used for overall traffic sources or per-page analysis. However, it lacks explicit guidance on when to use this tool versus alternatives like 'get_page_traffic' or 'get_domain_visitors', and does not mention prerequisites or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/colintoh/clicky-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server