Skip to main content
Glama
kesslerio

YOURLS-MCP

by kesslerio

contract_url

Verify if a URL is already shortened in the YOURLS database to avoid duplicate entries, ensuring efficient URL management.

Instructions

Check if a URL has already been shortened without creating a new short URL

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesThe URL to check if it exists in the database

Implementation Reference

  • src/index.js:179-185 (registration)
    Registration of the 'contract_url' MCP tool, including inline Zod input schema validation for the 'url' parameter and references the execute handler.
    server.tool(
      contractUrlTool.name,
      contractUrlTool.description,
      {
        url: z.string().describe('The URL to check if it exists in the database')
      },
      contractUrlTool.execute
  • Alternative registration of the 'contract_url' MCP tool in tools index module, with inline schema and execute handler reference.
    server.tool(
      contractUrlTool.name,
      contractUrlTool.description,
      {
        url: z.string().describe('The URL to check if it exists in the database')
      },
      contractUrlTool.execute
    );
  • Core implementation of contract URL check in YourlsClient, attempts to use 'contract' plugin API or falls back to native search if unavailable. This is the logic the tool handler would invoke.
    async contractUrl(url, useNativeFallback = true) {
      try {
        // First try using the Contract plugin
        const isAvailable = await isPluginAvailable(this, 'contract', 'contract', { url: 'https://example.com' });
        
        if (isAvailable) {
          return this.request('contract', { url });
        } else if (useNativeFallback) {
          // Plugin isn't available, use our fallback implementation
          return this._contractUrlFallback(url);
        } else {
          throw new Error('The contract action is not available. Please install the API Contract plugin.');
        }
      } catch (error) {
        // If the error is from the plugin check or request, but not a missing plugin error,
        // pass it through
        if (!isPluginMissingError(error)) {
          throw error;
        }
        
        // If we're here, the plugin is missing and we need to use our fallback
        if (useNativeFallback) {
          return this._contractUrlFallback(url);
        } else {
          throw new Error('The contract action is not available. Please install the API Contract plugin.');
        }
      }
    }
  • Fallback implementation for contract URL check using YOURLS stats API to search for existing short links matching the given URL.
    async _contractUrlFallback(url) {
      try {
        // Safety limit to prevent performance issues
        const MAX_RESULTS = 1000;
        
        // We can try to use the stats action with a limited results count
        // and filter for the URL we're looking for
        const listResult = await this.request('stats', { 
          limit: MAX_RESULTS, 
          filter: 'url',
          search: encodeURIComponent(url) 
        });
        
        // Process the results to match the Contract plugin's output format
        const links = [];
        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;
              links.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
              });
            }
          }
        }
        
        return {
          message: 'success',
          url_exists: urlExists,
          links: links,
          ...createFallbackInfo('Uses stats API, may be slower for large databases', false, 'API Contract')
        };
      } catch (error) {
        console.error('Contract URL fallback error:', error.message);
        
        // In case of fallback failure, return a safe default
        return {
          message: 'success',
          url_exists: false,
          links: [],
          ...createFallbackInfo('Unable to search database completely', true, 'API Contract')
        };
      }
    }
Behavior3/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. It discloses the tool's read-only behavior by stating it checks without creating, but lacks details on error handling, response format, or database interaction specifics, leaving gaps in behavioral context.

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 purpose and usage, with zero wasted words, making it highly concise and well-structured for quick understanding.

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 adequate for a simple lookup tool but incomplete in explaining return values or potential errors, which could hinder agent usage in more complex scenarios.

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 the 'url' parameter. The description adds minimal semantic context by implying the URL is checked against a database, but does not provide additional syntax or format details beyond what the schema covers.

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

Purpose5/5

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

The description clearly states the specific action ('Check if a URL has already been shortened') and the resource ('URL'), distinguishing it from sibling tools like 'shorten_url' or 'expand_url' by emphasizing it does not create new short URLs.

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

Usage Guidelines5/5

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

It explicitly states when to use this tool ('Check if a URL has already been shortened') and when not to ('without creating a new short URL'), providing clear alternatives by contrasting with sibling tools like 'shorten_url' for creation.

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