Skip to main content
Glama

upsert_link

Create or update short links on Dub.co, allowing users to specify domains and custom slugs for destination URLs.

Instructions

Create or update a short link on dub.co, asking the user which domain to use if creating

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesThe destination URL to shorten
keyNoOptional custom slug for the short link. If not provided, a random slug will be generated.
externalIdNoOptional external ID for the link
domainNoOptional domain slug to use. If not provided, the primary domain will be used.

Implementation Reference

  • The main handler function that implements the upsert_link tool logic, performing create-or-update of short links via Dub.co API.
    private async upsertLink(args: any): Promise<any> {
      if (!args.url) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'URL is required'
        );
      }
    
      try {
        // Determine which domain to use
        let domain: Domain;
        
        if (args.domain) {
          // If domain is specified, try to find it
          const foundDomain = await this.getDomainBySlug(args.domain);
          if (!foundDomain) {
            return {
              content: [
                {
                  type: 'text',
                  text: `Domain "${args.domain}" not found. Using primary domain instead.`,
                },
              ],
              isError: false,
            };
          }
          domain = foundDomain;
        } else {
          // Otherwise use the primary domain
          domain = await this.getPrimaryDomain();
        }
        
        // Upsert the link with the selected domain
        const upsertParams: CreateLinkParams = {
          url: args.url,
          domain: domain.slug,
        };
        
        if (args.key) {
          upsertParams.key = args.key;
        }
        
        if (args.externalId) {
          upsertParams.externalId = args.externalId;
        }
        
        const response = await this.axiosInstance.put('/links/upsert', upsertParams);
        const link = response.data;
        
        return {
          content: [
            {
              type: 'text',
              text: `Short link upserted: ${link.shortLink}\n\nDestination: ${link.url}\nID: ${link.id}`,
            },
          ],
        };
      } catch (error) {
        if (axios.isAxiosError(error)) {
          const axiosError = error as AxiosError<ApiErrorResponse>;
          const statusCode = axiosError.response?.status;
          const errorData = axiosError.response?.data;
          const errorMessage = errorData?.error || errorData?.message || axiosError.message;
          
          return {
            content: [
              {
                type: 'text',
                text: `Error upserting link: ${statusCode} - ${errorMessage}`,
              },
            ],
            isError: true,
          };
        }
        
        return {
          content: [
            {
              type: 'text',
              text: `Error upserting link: ${(error as Error).message}`,
            },
          ],
          isError: true,
        };
      }
    }
  • Input schema and metadata definition for the upsert_link tool, registered in the ListTools response.
      name: 'upsert_link',
      description: 'Create or update a short link on dub.co, asking the user which domain to use if creating',
      inputSchema: {
        type: 'object',
        properties: {
          url: {
            type: 'string',
            description: 'The destination URL to shorten',
          },
          key: {
            type: 'string',
            description: 'Optional custom slug for the short link. If not provided, a random slug will be generated.',
          },
          externalId: {
            type: 'string',
            description: 'Optional external ID for the link',
          },
          domain: {
            type: 'string',
            description: 'Optional domain slug to use. If not provided, the primary domain will be used.'
          }
        },
        required: ['url'],
      },
    },
  • src/index.ts:206-207 (registration)
    Dispatch case in the CallToolRequestSchema handler that routes upsert_link calls to the upsertLink method.
    case 'upsert_link':
      return await this.upsertLink(request.params.arguments);
Behavior3/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 reveals that the tool may prompt the user for domain selection during creation, which is valuable context beyond basic upsert functionality. However, it doesn't cover other important behavioral aspects like authentication requirements, rate limits, error conditions, or what happens during updates vs. creations, leaving significant gaps for a mutation tool.

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 ('Create or update a short link on dub.co') and adds only essential behavioral context ('asking the user which domain to use if creating'). There's no wasted verbiage, repetition, or unnecessary elaboration—every word serves a clear purpose.

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?

For a mutation tool with 4 parameters, no annotations, and no output schema, the description provides adequate basic purpose and some behavioral context (user prompting for domain). However, it lacks details on permissions, side effects, response format, or error handling, which are important for safe and effective use. The high schema coverage helps, but the description alone is insufficient for full contextual understanding.

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 fully documents all 4 parameters (url, key, externalId, domain). The description doesn't add any parameter-specific details beyond what the schema provides—it mentions domain selection generally but doesn't explain parameter interactions or semantics. This meets the baseline of 3 when schema coverage is high.

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 action ('Create or update'), the resource ('a short link on dub.co'), and distinguishes from siblings by specifying it handles both creation and updating (unlike create_link, delete_link, or update_link which are separate). The phrase 'asking the user which domain to use if creating' adds specific behavioral context that further differentiates it.

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

Usage Guidelines4/5

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

The description implies usage context by mentioning 'if creating' and referencing domain selection, which suggests this tool is for upsert operations where domain choice matters during creation. However, it doesn't explicitly state when to use this vs. the sibling tools (create_link, update_link) or provide clear alternatives or exclusions, leaving some ambiguity about the optimal choice between these tools.

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

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/Gitmaxd/dubco-mcp-server'

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