apipost_list
Browse and search API project lists with enhanced directory hierarchy navigation, filtering by type, and parent-child relationship tracking for efficient API documentation management.
Instructions
查看项目API列表,支持强化的目录层级搜索和父子关系定位
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| depth | No | 层级深度限制(配合recursive使用,限制搜索深度),默认无限制 | |
| group_by_folder | No | 是否按目录分组显示结果,默认false | |
| limit | No | 显示数量限制(默认50,最大200) | |
| parent_id | No | 父目录ID,精确查找某个目录下的子项目。使用"0"查看根目录,使用具体ID查看子目录 | |
| recursive | No | 是否递归搜索子目录(搜索指定目录及其所有子目录),默认false仅搜索当前层级 | |
| search | No | 搜索关键词(接口名称、URL、方法、ID、描述) | |
| show_all | No | 显示全部项目(忽略limit限制) | |
| show_path | No | 是否显示完整路径(从根目录到当前项目的完整路径),默认false | |
| show_structure | No | 是否显示层级结构(树形展示),默认false为列表模式 | |
| target_type | No | 项目类型筛选:api(仅接口)、folder(仅目录)、all(全部),默认all |
Implementation Reference
- src/index.ts:1420-1493 (handler)Handler for apipost_list tool: fetches API/project list from ApiPost, applies filters like search, parent_id, target_type, recursive, depth, limits results, and formats output using display helpers.case 'apipost_list': if (!checkSecurityPermission('read')) { throw new Error(`🔒 安全模式 "${APIPOST_SECURITY_MODE}" 不允许读取操作。`); } const searchKeyword = args.search; const parentId = args.parent_id; const targetType = args.target_type || 'all'; const showStructure = args.show_structure; const showPath = args.show_path; const recursive = args.recursive; const depth = args.depth; const groupByFolderFlag = args.group_by_folder; const limit = Math.min(args.limit || 50, 200); const showAll = args.show_all; const listResult = await apiClient.get('/open/apis/list', { params: { project_id: currentWorkspace.projectId } }); if (listResult.data.code !== 0) { throw new Error(`获取列表失败: ${listResult.data.msg}`); } let items = listResult.data.data.list; const totalCount = items.length; const allItems = [...items]; // 保存完整列表用于路径构建和分组 // 递归搜索或按目录过滤 if (recursive && parentId !== undefined) { // 递归搜索指定目录及其子目录 items = getChildrenRecursively(items, parentId, depth); } else if (parentId !== undefined) { // 仅搜索当前层级 items = items.filter((item) => item.parent_id === parentId); } // 按类型过滤 if (targetType !== 'all') { items = items.filter((item) => item.target_type === targetType); } // 搜索过滤 if (searchKeyword) { const keyword = searchKeyword.toLowerCase(); items = items.filter((item) => item.name?.toLowerCase().includes(keyword) || item.url?.toLowerCase().includes(keyword) || item.method?.toLowerCase().includes(keyword) || item.target_id?.toLowerCase().includes(keyword) || item.description?.toLowerCase().includes(keyword)); } // 分页处理 const filteredCount = items.length; let displayItems = items; let isLimited = false; if (!showAll && filteredCount > limit) { displayItems = items.slice(0, limit); isLimited = true; } // 构建显示文本 const listResult_display = buildListDisplay(displayItems, totalCount, filteredCount, showStructure, searchKeyword, parentId, targetType, isLimited, limit, showPath, recursive, depth, groupByFolderFlag, allItems); // 构建日志信息 const filterInfo = []; if (parentId !== undefined) filterInfo.push(`父目录: ${parentId}`); if (targetType !== 'all') filterInfo.push(`类型: ${targetType}`); if (searchKeyword) filterInfo.push(`搜索: "${searchKeyword}"`); if (recursive) filterInfo.push('递归搜索'); if (depth !== undefined) filterInfo.push(`深度限制: ${depth}`); const logInfo = filterInfo.length > 0 ? `\n筛选条件: ${filterInfo.join(', ')}` : ''; const limitInfo = isLimited ? `\n显示限制: 前${limit}条` : ''; return { content: [{ type: 'text', text: listResult_display }] }; case 'apipost_update':
- src/index.ts:908-921 (schema)Input schema for apipost_list tool defining optional parameters for filtering and display options.type: 'object', properties: { search: { type: 'string', description: '搜索关键词(接口名称、URL、方法、ID、描述)' }, parent_id: { type: 'string', description: '父目录ID,精确查找某个目录下的子项目。使用"0"查看根目录,使用具体ID查看子目录' }, target_type: { type: 'string', enum: ['api', 'folder', 'all'], description: '项目类型筛选:api(仅接口)、folder(仅目录)、all(全部),默认all' }, show_structure: { type: 'boolean', description: '是否显示层级结构(树形展示),默认false为列表模式' }, show_path: { type: 'boolean', description: '是否显示完整路径(从根目录到当前项目的完整路径),默认false' }, recursive: { type: 'boolean', description: '是否递归搜索子目录(搜索指定目录及其所有子目录),默认false仅搜索当前层级' }, depth: { type: 'number', description: '层级深度限制(配合recursive使用,限制搜索深度),默认无限制' }, group_by_folder: { type: 'boolean', description: '是否按目录分组显示结果,默认false' }, limit: { type: 'number', description: '显示数量限制(默认50,最大200)' }, show_all: { type: 'boolean', description: '显示全部项目(忽略limit限制)' } } }
- src/index.ts:904-922 (registration)Registration of apipost_list tool in the ListToolsRequestSchema handler's tools array.{ name: 'apipost_list', description: '查看项目API列表,支持强化的目录层级搜索和父子关系定位', inputSchema: { type: 'object', properties: { search: { type: 'string', description: '搜索关键词(接口名称、URL、方法、ID、描述)' }, parent_id: { type: 'string', description: '父目录ID,精确查找某个目录下的子项目。使用"0"查看根目录,使用具体ID查看子目录' }, target_type: { type: 'string', enum: ['api', 'folder', 'all'], description: '项目类型筛选:api(仅接口)、folder(仅目录)、all(全部),默认all' }, show_structure: { type: 'boolean', description: '是否显示层级结构(树形展示),默认false为列表模式' }, show_path: { type: 'boolean', description: '是否显示完整路径(从根目录到当前项目的完整路径),默认false' }, recursive: { type: 'boolean', description: '是否递归搜索子目录(搜索指定目录及其所有子目录),默认false仅搜索当前层级' }, depth: { type: 'number', description: '层级深度限制(配合recursive使用,限制搜索深度),默认无限制' }, group_by_folder: { type: 'boolean', description: '是否按目录分组显示结果,默认false' }, limit: { type: 'number', description: '显示数量限制(默认50,最大200)' }, show_all: { type: 'boolean', description: '显示全部项目(忽略limit限制)' } } } },
- src/index.ts:424-495 (helper)Key helper function called by handler to generate the formatted output text with various display modes (tree, list, grouped).function buildListDisplay(items, totalCount, filteredCount, showStructure, searchKeyword, parentId, targetType, isLimited, limit, showPath, recursive, depth, groupByFolderFlag, allItems) { let listText = ''; // 标题信息 if (recursive) { listText += `🌲 递归搜索视图`; if (depth !== undefined) listText += ` (深度限制: ${depth})`; listText += `\n`; } else if (parentId !== undefined) { listText += `📁 目录层级视图 (父目录ID: ${parentId})\n`; } else { listText += `📋 项目完整列表\n`; } listText += `总计: ${totalCount}项, 当前显示: ${items.length}项\n\n`; // 筛选信息 const filterInfo = []; if (searchKeyword) filterInfo.push(`搜索: "${searchKeyword}"`); if (parentId !== undefined) filterInfo.push(`父目录: ${parentId === '0' ? '根目录' : parentId}`); if (targetType && targetType !== 'all') filterInfo.push(`类型: ${targetType}`); if (recursive) filterInfo.push(`递归搜索: 是`); if (depth !== undefined) filterInfo.push(`深度限制: ${depth}`); if (filterInfo.length > 0) { listText += `🔍 筛选条件: ${filterInfo.join(' | ')}\n`; listText += `筛选结果: ${filteredCount}项\n\n`; } if (isLimited) { listText += `⚠️ 显示限制: 仅显示前${limit}项,如需查看更多请使用搜索过滤\n\n`; } if (items.length === 0) { listText += '📭 未找到匹配的项目\n\n'; listText += '💡 提示:\n'; listText += '• 尝试调整搜索关键词\n'; listText += '• 检查父目录ID是否正确\n'; listText += '• 使用不同的类型筛选\n'; listText += '• 尝试使用 recursive=true 递归搜索子目录\n'; return listText; } // 构建路径映射(如果需要显示路径) let pathMap; if (showPath && allItems) { pathMap = buildPathMap(allItems); } if (groupByFolderFlag && allItems) { // 按目录分组显示 listText += buildGroupedList(items, allItems, pathMap); } else if (showStructure) { // 树形结构显示 listText += buildTreeStructure(items, pathMap); } else { // 列表模式显示 listText += buildFlatList(items, pathMap); } // 操作提示 listText += '\n💡 使用提示:\n'; listText += '• 使用 parent_id 参数查看特定目录下的内容\n'; listText += '• 使用 target_type="folder" 仅查看目录\n'; listText += '• 使用 target_type="api" 仅查看接口\n'; listText += '• 使用 show_structure=true 查看树形结构\n'; listText += '• 使用 show_path=true 显示完整路径\n'; listText += '• 使用 recursive=true 递归搜索子目录\n'; listText += '• 使用 group_by_folder=true 按目录分组显示\n'; return listText; }
- src/index.ts:391-404 (helper)Helper for recursive retrieval of child items/folders used when recursive=true.// 递归获取子项目 function getChildrenRecursively(items, parentId, maxDepth, currentDepth = 0) { if (maxDepth !== undefined && currentDepth >= maxDepth) { return []; } const children = items.filter(item => item.parent_id === parentId); const result = [...children]; children.forEach(child => { if (child.target_type === 'folder') { result.push(...getChildrenRecursively(items, child.target_id, maxDepth, currentDepth + 1)); } }); return result; }