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
    );

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