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
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | The destination URL to shorten | |
| key | No | Optional custom slug for the short link. If not provided, a random slug will be generated. | |
| externalId | No | Optional external ID for the link | |
| domain | No | Optional domain slug to use. If not provided, the primary domain will be used. |
Implementation Reference
- src/index.ts:427-512 (handler)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, }; } }
- src/index.ts:157-181 (schema)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);