Skip to main content
Glama
kesslerio

YOURLS-MCP

by kesslerio

url_analytics

Analyze click statistics for shortened URLs within specific timeframes, providing insights into performance and usage trends.

Instructions

Get detailed click analytics for a shortened URL within a date range

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
periodNoThe time period for analytics (e.g., "day", "week", "month")
shorturlYesThe short URL to get analytics for

Implementation Reference

  • The execute function implementing the core logic of the url_analytics tool. It calls the YOURLS API via yourlsClient.shortUrlAnalytics and formats the response using createMcpResponse.
    execute: async ({ shorturl, date, date_end }) => {
      try {
        const result = await yourlsClient.shortUrlAnalytics(shorturl, date, date_end);
        
        if (result.stats) {
          return createMcpResponse(true, {
            shorturl: shorturl,
            total_clicks: result.stats.total_clicks || 0,
            range_clicks: result.stats.range_clicks || 0,
            daily_clicks: result.stats.daily_clicks || {},
            date_range: {
              start: date,
              end: date_end || date
            }
          });
        } else {
          throw new Error(result.message || 'Unknown error');
        }
      } catch (error) {
        return createMcpResponse(false, {
          message: error.message,
          shorturl: shorturl,
          date: date,
          date_end: date_end || date
        });
      }
    }
  • JSON schema defining the input parameters for the url_analytics tool: shorturl (required), date (required), date_end (optional).
    inputSchema: {
      type: 'object',
      properties: {
        shorturl: {
          type: 'string',
          description: 'The short URL or keyword to get analytics for'
        },
        date: {
          type: 'string',
          description: 'Start date for analytics (YYYY-MM-DD format)'
        },
        date_end: {
          type: 'string',
          description: 'Optional end date for analytics (YYYY-MM-DD format). Defaults to start date if not provided.'
        }
      },
      required: ['shorturl', 'date']
    },
  • src/index.js:168-177 (registration)
    Registration of the url_analytics tool on the MCP server in the main entry point, using Zod schema adapted for shorturl and period.
    // Register plugin-based tools
    server.tool(
      shortUrlAnalyticsTool.name,
      shortUrlAnalyticsTool.description,
      {
        shorturl: z.string().describe('The short URL to get analytics for'),
        period: z.string().optional().describe('The time period for analytics (e.g., "day", "week", "month")')
      },
      shortUrlAnalyticsTool.execute
    );
  • Helper method in YourlsClient that performs the actual API request to YOURLS 'shorturl_analytics' endpoint, used by the tool handler.
    async shortUrlAnalytics(shorturl, date, dateEnd = null) {
      const params = { 
        shorturl, 
        date 
      };
      
      if (dateEnd) {
        params.date_end = dateEnd;
      }
      
      try {
        return this.request('shorturl_analytics', params);
      } catch (error) {
        // If the plugin isn't installed, we'll get an error about unknown action
        if (isPluginMissingError(error)) {
          throw new Error('The shorturl_analytics action is not available. Please install the API ShortURL Analytics plugin.');
        }
        
        // Otherwise, re-throw the original error
        throw error;
      }
    }
  • Alternative registration of the url_analytics tool in the tools module (may be unused).
    server.tool(
      shortUrlAnalyticsTool.name,
      shortUrlAnalyticsTool.description,
      {
        shorturl: z.string().describe('The short URL to get analytics for'),
        period: z.string().optional().describe('The time period for analytics (e.g., "day", "week", "month")')
      },
      shortUrlAnalyticsTool.execute
    );
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool retrieves analytics (implying read-only) but doesn't mention authentication needs, rate limits, error conditions, or what 'detailed click analytics' includes (e.g., metrics like clicks, locations, devices). This leaves significant gaps for safe and effective use.

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 core purpose without unnecessary words. Every part earns its place by specifying the action, resource, and scope concisely.

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

Completeness2/5

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

Given the complexity of analytics tools, no annotations, and no output schema, the description is incomplete. It doesn't explain what data is returned, how to interpret results, or handle edge cases (e.g., invalid URLs, no data in range). For a tool with potential rich outputs, this leaves the agent under-informed.

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 both parameters ('shorturl' and 'period') adequately. The description adds minimal value beyond implying date-range filtering, but doesn't provide additional syntax, format examples, or constraints beyond what's in the schema descriptions.

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 action ('Get detailed click analytics') and resource ('for a shortened URL within a date range'), making the purpose immediately understandable. However, it doesn't explicitly distinguish this tool from sibling tools like 'url_stats' or 'shorten_with_analytics', which likely have overlapping analytics functionality.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives like 'url_stats' or 'shorten_with_analytics'. It mentions a date range but doesn't specify prerequisites, exclusions, or comparative contexts with sibling tools, leaving the agent to guess based on tool names alone.

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

Related 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/kesslerio/yourls-mcp'

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