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

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