Skip to main content
Glama
kesslerio

YOURLS-MCP

by kesslerio

get_url_keyword

Extract keywords from a long URL to identify its unique short link identifier. Optionally return a single result for precise URL management within the YOURLS-MCP server.

Instructions

Get the keyword(s) for a long URL

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
exactly_oneNoWhether to return only one result (default: false)
urlYesThe URL to find keywords for

Implementation Reference

  • The execute handler function that implements the core logic of the 'get_url_keyword' tool, processing input, calling the YOURLS client, and formatting the response.
    execute: async ({ url, exactly_one = true }) => {
      try {
        // Normalize boolean parameter if it's passed as a string
        if (typeof exactly_one === 'string') {
          exactly_one = exactly_one.toLowerCase() === 'true';
        }
        
        // Use the getUrlKeyword method with fallback enabled
        const result = await yourlsClient.getUrlKeyword(url, exactly_one, true);
        
        if (result.status === 'success' || result.message === 'success: found') {
          const responseData = {
            url: url
          };
          
          // Add keyword information based on response format
          if (exactly_one && result.keyword) {
            responseData.keyword = result.keyword;
            if (result.shorturl) responseData.shorturl = result.shorturl;
            if (result.title) responseData.title = result.title;
          } else if (!exactly_one && result.keywords) {
            responseData.keywords = result.keywords;
          }
          
          // Add message if available
          if (result.simple) responseData.message = result.simple;
          
          // Add fallback information if applicable
          if (result.fallback_used) {
            responseData.fallback_used = true;
            if (result.fallback_limitations) {
              responseData.fallback_limitations = result.fallback_limitations;
            }
          }
          
          return createMcpResponse(true, responseData);
        } else {
          throw new Error(result.message || 'Unknown error');
        }
      } catch (error) {
        return createMcpResponse(false, {
          message: error.message,
          url: url
        });
      }
    }
  • Input schema definition for the 'get_url_keyword' tool parameters.
    inputSchema: {
      type: 'object',
      properties: {
        url: {
          type: 'string',
          description: 'The long URL to look up'
        },
        exactly_one: {
          type: 'boolean',
          description: 'If false, returns all keywords for this URL (default: true)'
        }
      },
      required: ['url']
    },
  • src/index.js:211-217 (registration)
    Registration of the 'get_url_keyword' tool with the MCP server, including Zod schema conversion and binding the execute handler.
    getUrlKeywordTool.name,
    getUrlKeywordTool.description,
    {
      url: z.string().describe('The URL to find keywords for'),
      exactly_one: z.boolean().optional().describe('Whether to return only one result (default: false)')
    },
    getUrlKeywordTool.execute
  • The YourlsClient.getUrlKeyword method called by the tool handler, with plugin detection and fallback logic.
    async getUrlKeyword(url, exactlyOne = true, useNativeFallback = true) {
      const params = { url };
      
      if (!exactlyOne) {
        params.exactly_one = 'false';
      }
      
      try {
        // First check if the plugin is available
        const isAvailable = await isPluginAvailable(this, 'edit_url', 'geturl', { url: 'https://example.com' });
        
        if (isAvailable) {
          return this.request('geturl', params);
        } else if (useNativeFallback) {
          // Use our fallback implementation
          return this._getUrlKeywordFallback(url, exactlyOne);
        } else {
          throw new Error('The geturl action is not available. Please install the API Edit URL plugin.');
        }
      } catch (error) {
        // If the error is not about a missing plugin, re-throw it
        if (!isPluginMissingError(error)) {
          throw error;
        }
        
        // If we're here, the plugin is missing and we need to use the fallback
        if (useNativeFallback) {
          return this._getUrlKeywordFallback(url, exactlyOne);
        } else {
          throw new Error('The geturl action is not available. Please install the API Edit URL plugin.');
        }
      }
  • Fallback implementation _getUrlKeywordFallback used when the API Edit URL plugin is unavailable, searches via stats API.
    async _getUrlKeywordFallback(url, exactlyOne) {
      try {
        // Safety limit to prevent performance issues
        const MAX_RESULTS = 1000;
        
        // We can try to use the stats action with a filter
        const listResult = await this.request('stats', { 
          limit: MAX_RESULTS,
          filter: 'url',
          search: encodeURIComponent(url) 
        });
        
        // Process the results to match the geturl plugin's output format
        const keywords = [];
        let urlExists = false;
        
        if (listResult.links) {
          // Iterate through the results and find exact URL matches
          for (const [keyword, data] of Object.entries(listResult.links)) {
            if (data.url === url) {
              urlExists = true;
              keywords.push({
                keyword: keyword,
                shorturl: `${this.api_url.replace('yourls-api.php', '')}${keyword}`,
                title: data.title,
                url: data.url,
                date: data.timestamp,
                ip: data.ip,
                clicks: data.clicks
              });
              
              // If we only want one result and we found it, break
              if (exactlyOne) {
                break;
              }
            }
          }
        }
        
        // Format the response similarly to what the geturl plugin would return
        if (urlExists) {
          if (exactlyOne && keywords.length > 0) {
            // Return just the first match
            return {
              status: 'success',
              keyword: keywords[0].keyword,
              url: keywords[0].url,
              title: keywords[0].title,
              shorturl: keywords[0].shorturl,
              message: 'success',
              ...createFallbackInfo('Search limited to latest URLs', false, 'API Edit URL')
            };
          } else {
            // Return all matches
            return {
              status: 'success',
              keywords: keywords,
              url: url,
              message: 'success',
              ...createFallbackInfo('Search limited to latest URLs', false, 'API Edit URL')
            };
          }
        } else {
          // No matches found
          return {
            status: 'fail',
            message: 'URL not found',
            ...createFallbackInfo('Search limited to latest URLs', false, 'API Edit URL')
          };
        }
      } catch (error) {
        console.error('Get URL keyword fallback error:', error.message);
        
        // In case of fallback failure, return a safe default
        return {
          status: 'fail',
          message: 'Error looking up URL: ' + error.message,
          ...createFallbackInfo('Error during fallback search', true, 'API Edit URL')
        };
      }
    }
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 states what the tool does but lacks details on how it works (e.g., how keywords are extracted, any rate limits, error handling, or response format). This is a significant gap for a tool with no structured safety or behavioral hints.

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 directly states the tool's purpose without any wasted words. It is appropriately sized and front-loaded, making it easy for an agent to parse quickly.

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 no annotations and no output schema, the description is incomplete. It does not explain what the return value looks like (e.g., format of keywords, potential errors), and with siblings like 'url_analytics', more context on use cases would be helpful. The tool's complexity is low, but the description lacks necessary behavioral details.

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 input schema already documents both parameters ('url' and 'exactly_one') with clear descriptions. The description does not add any meaning beyond this, such as examples or edge cases, but the schema provides adequate baseline information.

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 the resource 'keyword(s) for a long URL', making the purpose understandable. However, it does not explicitly differentiate this tool from siblings like 'url_analytics' or 'url_stats', which might also involve URL analysis, so it falls short of a perfect score.

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. With siblings like 'url_analytics' or 'list_urls', there is no indication of context, prerequisites, or exclusions, 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