Skip to main content
Glama
Qihoo360

360 AI Cloud Drive MCP Server

by Qihoo360

file-list

Retrieve a detailed list of files and folders from a specified path in the cloud drive, including names, sizes, and timestamps. Supports pagination for efficient browsing.

Instructions

获取云盘指定路径下的文件和文件夹列表,支持分页查询。返回文件名、大小、创建时间、修改时间等详细信息。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pageNo页码,默认从0开始。
page_sizeNo每页显示的条目数,默认50条。
pathNo要查询的云盘路径,默认为根目录'/'/

Implementation Reference

  • The core handler function for the 'file-list' tool. It handles authentication, calls the cloud storage API to fetch the file list, formats the file information (name, size, dates, etc.), and returns a formatted text response or error.
    async ({ page, page_size, path }, mcpReq: any) => { const httpContext = gethttpContext(mcpReq, server); const transportAuthInfo = httpContext.authInfo; try { let authInfo: AuthInfo; const extraParams = { path: path || '/', page: page || 0, page_size: page_size || 100, } try { authInfo = await getAuthInfo({ method: 'File.getList', extraParams: extraParams }, transportAuthInfo); authInfo.request_url = getConfig(transportAuthInfo?.ecsEnv).request_url } catch (authError) { return { content: [{ type: "text", text: "获取鉴权信息失败,请提供有效的API_KEY" }], isError: true }; } const apiResponse = await fetchFileList(authInfo, extraParams); if (apiResponse && apiResponse.errno === 0) { const files = (apiResponse.data && apiResponse.data.node_list) || []; if (files.length === 0) { return { content: [{ type: "text", text: "没有找到符合条件的文件" }] }; } const dirCount = files.filter((file: YunPanFile) => file.type === "1").length; const fileCount = files.length - dirCount; const filesText = [ `云盘文件列表 (路径: ${path})`, `共 ${files.length} 项 (${dirCount} 个文件夹, ${fileCount} 个文件)`, "", ...files.map(formatFileInfo) ].join("\n"); return { content: [ { type: "text", text: filesText }, { type: "text", text: TOOL_LIMIT_NOTE } ] }; } else { return { content: [{ type: "text", text: apiResponse?.errmsg || "API请求失败" }], isError: true }; } } catch (error: any) { return { content: [ { type: "text", text: `获取文件列表出错: ${error.message || "未知错误"}`, }, { type: "text", text: TOOL_LIMIT_NOTE, } ], isError: true }; } },
  • Zod schema defining the input parameters for the 'file-list' tool: page (number, optional, default 0), page_size (number, optional, default 50), path (string, optional, default '/').
    page: z.number().optional().default(0).describe("页码,默认从0开始。"), page_size: z.number().optional().default(50).describe("每页显示的条目数,默认50条。"), path: z.string().optional().default("/").describe("要查询的云盘路径,默认为根目录'/'"), },
  • The registration function for the 'file-list' tool, which calls server.tool() to register the tool name, description, schema, and handler with the MCP server.
    export function registerGetFilesTool(server: McpServer) { server.tool( "file-list", "获取云盘指定路径下的文件和文件夹列表,支持分页查询。返回文件名、大小、创建时间、修改时间等详细信息。", { page: z.number().optional().default(0).describe("页码,默认从0开始。"), page_size: z.number().optional().default(50).describe("每页显示的条目数,默认50条。"), path: z.string().optional().default("/").describe("要查询的云盘路径,默认为根目录'/'"), }, async ({ page, page_size, path }, mcpReq: any) => { const httpContext = gethttpContext(mcpReq, server); const transportAuthInfo = httpContext.authInfo; try { let authInfo: AuthInfo; const extraParams = { path: path || '/', page: page || 0, page_size: page_size || 100, } try { authInfo = await getAuthInfo({ method: 'File.getList', extraParams: extraParams }, transportAuthInfo); authInfo.request_url = getConfig(transportAuthInfo?.ecsEnv).request_url } catch (authError) { return { content: [{ type: "text", text: "获取鉴权信息失败,请提供有效的API_KEY" }], isError: true }; } const apiResponse = await fetchFileList(authInfo, extraParams); if (apiResponse && apiResponse.errno === 0) { const files = (apiResponse.data && apiResponse.data.node_list) || []; if (files.length === 0) { return { content: [{ type: "text", text: "没有找到符合条件的文件" }] }; } const dirCount = files.filter((file: YunPanFile) => file.type === "1").length; const fileCount = files.length - dirCount; const filesText = [ `云盘文件列表 (路径: ${path})`, `共 ${files.length} 项 (${dirCount} 个文件夹, ${fileCount} 个文件)`, "", ...files.map(formatFileInfo) ].join("\n"); return { content: [ { type: "text", text: filesText }, { type: "text", text: TOOL_LIMIT_NOTE } ] }; } else { return { content: [{ type: "text", text: apiResponse?.errmsg || "API请求失败" }], isError: true }; } } catch (error: any) { return { content: [ { type: "text", text: `获取文件列表出错: ${error.message || "未知错误"}`, }, { type: "text", text: TOOL_LIMIT_NOTE, } ], isError: true }; } }, ); }
  • Invocation of the registerGetFilesTool function within registerAllTools to register the 'file-list' tool as part of all tools registration.
    registerGetFilesTool(server);
  • Helper function that makes the actual HTTP request to the cloud storage API to retrieve the file list.
    async function fetchFileList(authInfo: AuthInfo, extraParams: Record<string|number, string|number>): Promise<any> { try { const url = new URL(authInfo.request_url || ''); // 构建请求头 const headers = { 'Access-Token': authInfo.access_token || '' }; // 确保所有参数都是字符串 const stringifiedParams: Record<string, string> = {}; for (const [key, value] of Object.entries(extraParams)) { // 去除 access_token if (key !== 'access_token') { stringifiedParams[String(key)] = String(value); } } const baseParams: Record<string, string> = { 'method': 'File.getList', 'access_token': authInfo.access_token || '', 'qid': authInfo.qid || '', 'sign': authInfo.sign || '', ...stringifiedParams }; // 确保所有参数被正确添加 Object.entries(baseParams).forEach(([key, value]) => { url.searchParams.append(key, String(value)); }); const response = await fetch(url.toString(), { method: 'GET', headers: headers }); if (!response.ok) { throw new Error(`API 请求失败,状态码: ${response.status}`); } // 先获取原始响应文本 const responseText = await response.text(); try { // 尝试解析为JSON const data = JSON.parse(responseText); return data; } catch (jsonError) { console.error("JSON解析错误:", jsonError); throw new Error(`无法解析API响应: ${responseText.substring(0, 100)}...`); } } catch (error) { console.error('获取文件列表失败:', error); throw error; } }

Other Tools

Related 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/Qihoo360/ecs_mcp_server'

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