Skip to main content
Glama
Gitmaxd

Unofficial dubco-mcp-server

create_link

Shorten URLs into Dub.co links by specifying destination URLs, custom slugs, and domain preferences for streamlined sharing.

Instructions

Create a new short link on dub.co, asking the user which domain to use

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 core handler function that implements the create_link tool logic. It handles domain selection (specified or primary), constructs API params, calls Dub.co /links POST endpoint, and formats the response or error.
    private async createLink(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(); } // Create the link with the selected domain const createParams: CreateLinkParams = { url: args.url, domain: domain.slug, }; if (args.key) { createParams.key = args.key; } if (args.externalId) { createParams.externalId = args.externalId; } const response = await this.axiosInstance.post('/links', createParams); const link = response.data; return { content: [ { type: 'text', text: `Short link created: ${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 creating link: ${statusCode} - ${errorMessage}`, }, ], isError: true, }; } return { content: [ { type: 'text', text: `Error creating link: ${(error as Error).message}`, }, ], isError: true, }; } }
  • src/index.ts:108-133 (registration)
    Tool registration in ListToolsRequestHandler, defining name, description, and input schema for create_link.
    { name: 'create_link', description: 'Create a new short link on dub.co, asking the user which domain to use', 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'], }, },
  • TypeScript interface defining parameters for creating a link, used internally in the handler.
    interface CreateLinkParams { url: string; domain?: string; key?: string; externalId?: string; // ... other optional parameters }
  • src/index.ts:180-181 (registration)
    Dispatcher routing in CallToolRequestHandler that invokes the createLink handler for 'create_link' tool calls.
    case 'create_link': return await this.createLink(request.params.arguments);
  • Helper function to retrieve the primary domain, used by createLink when no domain is specified.
    private async getPrimaryDomain(): Promise<Domain> { const domains = await this.getDomains(); if (domains.length === 0) { throw new McpError( ErrorCode.InvalidRequest, 'No domains available in your workspace' ); } // Find the primary domain or use the first one const primaryDomain = domains.find(domain => domain.primary) || domains[0]; return primaryDomain; }
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-npm'

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