Skip to main content
Glama
muleiwu

DWZ Short URL MCP Server

by muleiwu

create_short_url

Create shortened URLs with custom domains and codes to simplify long links for sharing and tracking purposes.

Instructions

创建一个新的短网址。支持自定义域名、短代码、标题和描述信息。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
original_urlYes原始URL地址(要缩短的长链接)
domainYes短网址使用的域名(必填)
custom_codeNo自定义短代码(可选,如果不提供将自动生成)
titleYes短网址的标题(必填)
descriptionNo短网址的描述信息(可选)
expire_atNo过期时间(可选,ISO 8601格式,不填表示永不过期)

Implementation Reference

  • The handler function for the 'create_short_url' MCP tool. It logs the call, invokes the short link service to create the URL, formats the response with success status, data, and metadata.
    handler: async function (args) { logger.info('MCP工具调用: create_short_url', { args }); return ErrorHandler.asyncWrapper(async () => { // 调用服务层创建短链接 const result = await defaultShortLinkService.createShortUrl(args); // 格式化返回结果 return { success: true, message: '短网址创建成功', data: { id: result.id, short_code: result.short_code, short_url: result.short_url, original_url: result.original_url, title: result.title, description: result.description, domain: result.domain, expire_at: result.expire_at, is_active: result.is_active, click_count: result.click_count, created_at: result.created_at, updated_at: result.updated_at, }, meta: { operation: 'create_short_url', timestamp: new Date().toISOString(), }, }; })(); },
  • JSON Schema defining the input parameters for the 'create_short_url' tool, including properties, descriptions, constraints, and required fields.
    inputSchema: { type: 'object', properties: { original_url: { type: 'string', description: '原始URL地址(要缩短的长链接)', format: 'uri', examples: ['https://www.example.com/very/long/path', 'https://github.com/user/repo'], }, domain: { type: 'string', description: '短网址使用的域名(必填)', pattern: '^[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$', examples: ['dwz.test', 'link.example.com'], }, custom_code: { type: 'string', description: '自定义短代码(可选,如果不提供将自动生成)', pattern: '^[a-zA-Z0-9]{3,50}$', examples: ['abc123', 'mylink', 'promo2024'], }, title: { type: 'string', description: '短网址的标题(必填)', minLength: 1, maxLength: 200, examples: ['产品官网', '活动页面', '技术文档'], }, description: { type: 'string', description: '短网址的描述信息(可选)', maxLength: 500, examples: ['这是我们的新产品页面', '2024年春节促销活动'], }, expire_at: { type: 'string', description: '过期时间(可选,ISO 8601格式,不填表示永不过期)', format: 'date-time', examples: ['2024-12-31T23:59:59Z', '2025-01-01T00:00:00+08:00'], }, }, required: ['original_url', 'domain', 'title'], },
  • The registerTools method registers the 'create_short_url' tool (imported as createShortUrlTool) along with others into the server's tools Map, making it available for MCP requests.
    registerTools() { const tools = [ createShortUrlTool, getUrlInfoTool, listShortUrlsTool, deleteShortUrlTool, batchCreateShortUrlsTool, listDomainsTool, ]; for (const tool of tools) { this.tools.set(tool.name, tool); logger.debug(`注册工具: ${tool.name}`); } logger.info(`已注册 ${tools.length} 个工具`); }
  • Core helper function in the ShortLinkService that performs parameter validation, URL normalization, HTTP POST to the backend API to create the short URL, and handles the response or errors.
    async createShortUrl(params) { try { // 验证参数 const validatedParams = validateOrThrow('createShortUrl', params); // 标准化 URL validatedParams.original_url = normalizeUrl(validatedParams.original_url); logger.info('开始创建短链接:', { original_url: validatedParams.original_url, domain: validatedParams.domain, custom_code: validatedParams.custom_code, }); // 发送请求 const response = await this.httpClient.post( getApiUrl('/short_links'), validatedParams ); // 处理响应 const result = this.handleApiResponse(response, '创建短链接'); logger.info('短链接创建成功:', { id: result.id, short_code: result.short_code, short_url: result.short_url, }); return result; } catch (error) { logger.error('创建短链接失败:', error); const handledError = ErrorHandler.handle(error); throw ErrorHandler.createMcpErrorResponse(handledError, error); } }

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/muleiwu/dwz-mcp'

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