Skip to main content
Glama
Qihoo360

360 AI Cloud Drive MCP Server

by Qihoo360

file-list

Retrieve detailed file and folder listings from 360 AI Cloud Drive with pagination support, including file names, sizes, and timestamps.

Instructions

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

Input Schema

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

Implementation Reference

  • The registerGetFilesTool function registers the "file-list" MCP tool, defining its name, description, input schema, and inline execution handler that authenticates, fetches the file list from YunPan API, formats the results, and returns structured text content or error.
    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 }; } }, ); }
  • Zod input schema defining optional parameters for the file-list tool: page (default 0), page_size (default 50), path (default '/').
    { page: z.number().optional().default(0).describe("页码,默认从0开始。"), page_size: z.number().optional().default(50).describe("每页显示的条目数,默认50条。"), path: z.string().optional().default("/").describe("要查询的云盘路径,默认为根目录'/'"), },
  • Handler function for the file-list tool: retrieves authentication, calls the YunPan File.getList API, processes the response, formats file information (name, size, times, nid), counts dirs/files, and returns formatted text content or error response.
    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 }; } },
  • Top-level registration call to registerGetFilesTool within registerAllTools, including the file-list tool among others.
    registerGetFilesTool(server);
  • Helper function that performs the actual HTTP GET request to the YunPan API endpoint for File.getList, constructs URL params including method, auth tokens, qid, sign, and path/page params, parses JSON response.
    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; } }

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