get_url_info
Retrieve detailed information about a short URL, including the original link, click statistics, and creation date, by providing its unique ID.
Instructions
根据短网址ID获取详细信息,包括原始URL、点击统计、创建时间等。
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | 短网址的唯一标识ID |
Implementation Reference
- src/mcp/tools/getUrlInfo.js:15-68 (handler)Primary MCP tool implementation for 'get_url_info', including the handler function that executes the tool logic by calling the short link service and formatting the response. Also includes the input schema definition.export const getUrlInfoTool = { name: 'get_url_info', description: '根据短网址ID获取详细信息,包括原始URL、点击统计、创建时间等。', inputSchema: { type: 'object', properties: { id: { type: 'integer', description: '短网址的唯一标识ID', minimum: 1, examples: [1, 123, 456], }, }, required: ['id'], }, /** * 处理工具调用 * @param {Object} args - 工具参数 * @returns {Promise<Object>} 工具执行结果 */ handler: async function (args) { logger.info('MCP工具调用: get_url_info', { args }); return ErrorHandler.asyncWrapper(async () => { // 调用服务层获取短链接信息 const result = await defaultShortLinkService.getUrlInfo(args.id); // 格式化返回结果 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: 'get_url_info', timestamp: new Date().toISOString(), }, }; })(); }, };
- src/mcp/server.js:72-88 (registration)Registration of the getUrlInfoTool in the MCP server's tools map during server initialization.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} 个工具`); }
- Helper service method that performs the actual API call to retrieve short URL information by ID, including validation and error handling.async getUrlInfo(id) { try { // 验证参数 validateOrThrow('getUrlInfo', { id }); logger.info('获取短链接信息:', { id }); // 发送请求 const response = await this.httpClient.get( getApiUrl(`/short_links/${id}`) ); // 处理响应 const result = this.handleApiResponse(response, '获取短链接信息'); logger.info('获取短链接信息成功:', { id: result.id, short_code: result.short_code, original_url: result.original_url, }); return result; } catch (error) { logger.error('获取短链接信息失败:', error); const handledError = ErrorHandler.handle(error); throw ErrorHandler.createMcpErrorResponse(handledError, error); } }
- src/utils/validation.js:116-118 (schema)Joi validation schema for 'getUrlInfo' input parameters used in the service layer.getUrlInfo: Joi.object({ id: commonRules.id, }),