Skip to main content
Glama
muleiwu

DWZ Short URL MCP Server

by muleiwu

create_short_url

Create custom short URLs from long links using specified domains, titles, and optional codes with expiration settings for efficient link management.

Instructions

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

Input Schema

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

Implementation Reference

  • The handler function for the 'create_short_url' MCP tool. It logs the arguments, uses ErrorHandler.asyncWrapper to safely call the short link service's createShortUrl method, formats the successful response with data and meta, and returns it.
    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(), }, }; })(); },
  • The inputSchema for the 'create_short_url' tool, defining the structure, types, descriptions, validation patterns, examples, and required fields for the tool parameters.
    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 in McpShortLinkServer that imports and registers the createShortUrlTool (along with others) by name 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} 个工具`); }
  • The helper/service function createShortUrl in ShortLinkService class. Validates input, normalizes URL, POSTs to remote API /short_links, processes response, handles errors, and returns the created short link data.
    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