Skip to main content
Glama
kesslerio

YOURLS-MCP

by kesslerio

change_keyword

Modify the keyword of an existing short URL to update it with a new keyword or title, ensuring the short URL remains accurate and relevant.

Instructions

Change the keyword of an existing short URL

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
newshorturlYesThe new keyword to use
oldshorturlYesThe existing short URL or keyword
titleNoOptional new title

Implementation Reference

  • The execute function implementing the change_keyword tool logic: validates input implicitly via schema, calls yourlsClient.changeKeyword with fallback, processes response, handles errors.
    execute: async ({ oldshorturl, newshorturl, url, title }) => {
      try {
        // Use the changeKeyword method with fallback enabled
        const result = await yourlsClient.changeKeyword(oldshorturl, newshorturl, url, title, true);
        
        if (result.status === 'success' || result.message === 'success: updated' || result.statusCode === 200) {
          const responseData = {
            message: result.message || result.simple || `Keyword changed from '${oldshorturl}' to '${newshorturl}'`,
            oldshorturl: oldshorturl,
            newshorturl: newshorturl,
            shorturl: result.shorturl
          };
          
          // Add fallback information if applicable
          if (result.fallback_used) {
            responseData.fallback_used = true;
            if (result.fallback_limited) {
              responseData.fallback_limited = 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,
          oldshorturl: oldshorturl,
          newshorturl: newshorturl
        });
      }
    }
  • Input schema defining parameters for the change_keyword tool.
    inputSchema: {
      type: 'object',
      properties: {
        oldshorturl: {
          type: 'string',
          description: 'The existing short URL or keyword'
        },
        newshorturl: {
          type: 'string',
          description: 'The new keyword to use'
        },
        url: {
          type: 'string',
          description: 'Optional URL (if not provided, will use the URL from oldshorturl)'
        },
        title: {
          type: 'string',
          description: 'Optional new title ("keep" to keep existing, "auto" to fetch from URL)'
        }
      },
      required: ['oldshorturl', 'newshorturl']
    },
  • src/index.js:199-208 (registration)
    MCP server registration of the change_keyword tool, providing Zod schema and execute handler.
    server.tool(
      changeKeywordTool.name,
      changeKeywordTool.description,
      {
        oldshorturl: z.string().describe('The existing short URL or keyword'),
        newshorturl: z.string().describe('The new keyword to use'),
        title: z.string().optional().describe('Optional new title')
      },
      changeKeywordTool.execute
    );
  • YourlsClient.changeKeyword helper method: checks for API Edit URL plugin availability, makes 'change_keyword' API request, or falls back to _changeKeywordFallback.
    async changeKeyword(oldshorturl, newshorturl, url = null, title = null, useNativeFallback = true) {
      const params = { 
        oldshorturl,
        newshorturl
      };
      
      if (url) {
        params.url = url;
      }
      
      if (title) {
        params.title = title;
      }
      
      try {
        // First check if the plugin is available
        const isAvailable = await isPluginAvailable(this, 'edit_url', 'change_keyword', { 
          oldshorturl: 'test', 
          newshorturl: 'test2' 
        });
        
        if (isAvailable) {
          return this.request('change_keyword', params);
        } else if (useNativeFallback) {
          // Use our fallback implementation
          return this._changeKeywordFallback(oldshorturl, newshorturl, url, title);
        } else {
          throw new Error('The change_keyword 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._changeKeywordFallback(oldshorturl, newshorturl, url, title);
        } else {
          throw new Error('The change_keyword action is not available. Please install the API Edit URL plugin.');
        }
      }
    }
  • Fallback implementation when API Edit URL plugin unavailable: expands oldshorturl, creates new shorturl with new keyword (keeping URL/title), notes limitation (old keyword remains).
    async _changeKeywordFallback(oldshorturl, newshorturl, url = null, title = null) {
      try {
        // First, get the current details for the oldshorturl
        const currentDetails = await this.expand(oldshorturl);
        
        if (!currentDetails || !currentDetails.longurl) {
          throw new Error(`Short URL '${oldshorturl}' not found.`);
        }
        
        // Use the provided URL or the one from the current short URL
        const targetUrl = url || currentDetails.longurl;
        
        // Safety check for URL format
        validateUrl(targetUrl);
        
        // Determine the title
        let targetTitle = '';
        if (title === 'keep') {
          targetTitle = currentDetails.title || '';
        } else if (title === 'auto') {
          targetTitle = ''; // Let YOURLS fetch it from the URL
        } else if (title) {
          targetTitle = title;
        } else {
          targetTitle = currentDetails.title || '';
        }
        
        // Create the new shorturl
        const shortenResult = await this.request('shorturl', {
          url: targetUrl,
          keyword: newshorturl,
          title: targetTitle
        });
        
        if (shortenResult.status === 'fail') {
          throw new Error(`Failed to create new keyword: ${shortenResult.message || 'Unknown error'}`);
        }
        
        // Limitation: We can't delete the old shorturl without the Delete plugin
        const limitations = 'Creates new keyword but cannot delete old one (requires API Delete plugin)';
        
        return {
          status: 'success',
          statusCode: 200,
          message: `Keyword changed (Note: The old keyword '${oldshorturl}' still exists)`,
          oldshorturl: oldshorturl,
          newshorturl: newshorturl,
          shorturl: shortenResult.shorturl,
          url: targetUrl,
          title: targetTitle,
          ...createFallbackInfo(limitations, true, 'API Edit URL and API Delete')
        };
      } catch (error) {
        console.error('Change keyword fallback error:', error.message);
        throw error;
      }
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It implies a mutation ('change') but doesn't specify permissions needed, whether changes are reversible, rate limits, or error handling. This is inadequate for a tool that modifies existing data without structured safety 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 front-loads the core action without unnecessary words. Every part earns its place by directly stating the tool's function, making it highly concise and well-structured.

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 tool performs a mutation with no annotations and no output schema, the description is insufficient. It doesn't explain what happens on success (e.g., returns updated URL), error cases, or how it fits among siblings like 'update_url'. For a 3-parameter tool that alters data, more context is needed.

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 parameters are well-documented in the schema. The description adds no additional meaning beyond implying 'oldshorturl' and 'newshorturl' relate to keywords, but doesn't clarify format or constraints. This meets the baseline for high schema coverage.

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 ('change') and resource ('keyword of an existing short URL'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'update_url' or 'get_url_keyword', which could handle similar operations, so it doesn't reach the highest 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 like 'update_url' or 'create_custom_url'. It lacks context about prerequisites (e.g., needing an existing short URL) or exclusions, leaving the agent to infer usage from the name 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