update_link
Modify an existing Dub.co short link by changing its destination URL, domain, or slug to keep links current and functional.
Instructions
Update an existing short link on dub.co
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| linkId | Yes | The ID of the link to update | |
| url | No | The new destination URL | |
| domain | No | The new domain for the short link | |
| key | No | The new slug for the short link |
Implementation Reference
- src/index.ts:385-470 (handler)The primary handler function for the 'update_link' tool. It validates the linkId and update parameters, constructs the update payload, makes a PATCH request to the Dub.co API, and returns a formatted response or handles errors appropriately.private async updateLink(args: any): Promise<any> { if (!args.linkId) { throw new McpError( ErrorCode.InvalidParams, 'Link ID is required' ); } // Prepare update parameters const updateParams: UpdateLinkParams = {}; if (args.url) { updateParams.url = args.url; } if (args.domain) { updateParams.domain = args.domain; } if (args.key) { updateParams.key = args.key; } if (Object.keys(updateParams).length === 0) { throw new McpError( ErrorCode.InvalidParams, 'At least one parameter to update is required' ); } try { const response = await this.axiosInstance.patch(`/links/${args.linkId}`, updateParams); const link = response.data; return { content: [ { type: 'text', text: `Link updated: ${link.shortLink}\n\nDestination: ${link.url}\nID: ${link.id}`, }, ], }; } catch (error) { if (axios.isAxiosError(error)) { const axiosError = error as AxiosError<any>; const statusCode = axiosError.response?.status; const errorData = axiosError.response?.data; // Debug logging console.error('Error data:', JSON.stringify(errorData)); // Try to extract error message in different ways let errorMessage = 'Unknown error'; if (errorData) { if (typeof errorData === 'string') { errorMessage = errorData; } else if (errorData.error) { // Handle nested error object from Dub.co API if (typeof errorData.error === 'object' && errorData.error.message) { errorMessage = errorData.error.message; } else { errorMessage = errorData.error; } } else if (errorData.message) { errorMessage = errorData.message; } else { errorMessage = JSON.stringify(errorData); } } else { errorMessage = axiosError.message; } return { content: [ { type: 'text', text: `Error updating link: ${statusCode} - ${errorMessage}`, }, ], isError: true, }; } throw error; } }
- src/index.ts:134-159 (registration)Registration of the 'update_link' tool in the ListTools response, including name, description, and input schema definition.{ name: 'update_link', description: 'Update an existing short link on dub.co', inputSchema: { type: 'object', properties: { linkId: { type: 'string', description: 'The ID of the link to update', }, url: { type: 'string', description: 'The new destination URL', }, domain: { type: 'string', description: 'The new domain for the short link', }, key: { type: 'string', description: 'The new slug for the short link', }, }, required: ['linkId'], }, },
- src/index.ts:53-59 (schema)TypeScript interface defining the parameters for updating a link, used within the handler to type the update payload.interface UpdateLinkParams { url?: string; domain?: string; key?: string; externalId?: string; // ... other optional parameters }
- src/index.ts:182-183 (registration)Dispatcher case in the CallToolRequest handler that routes 'update_link' calls to the updateLink method.case 'update_link': return await this.updateLink(request.params.arguments);