Skip to main content
Glama
Qihoo360

360 AI Cloud Drive MCP Server

by Qihoo360

file-save

Save files to your cloud drive via URL or text content using the 360 AI Cloud Drive MCP Server. Manage and store documents efficiently with direct uploads from specified sources.

Instructions

通过URL或文本内容保存文件到云盘

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentNo文件内容(md格式),url或content必传1个,需要传用户指定的完整内容,不能省略任何部分
urlNo文件下载地址,url或content必传1个

Implementation Reference

  • Executes the file-save tool: validates inputs, retrieves auth, calls saveFile API, polls task status until complete or timeout, formats success/error response with cloud disk links.
    async ({ url, content }, mcpReq: any) => { // 参数验证 if (!url && !content) { return { content: [{ type: "text", text: "❌ 参数错误: 必须提供url或content参数" }] }; } const httpContext = gethttpContext(mcpReq, server); const transportAuthInfo = httpContext.authInfo; try { let authInfo: AuthInfo; try { // 获取鉴权信息 authInfo = await getAuthInfo({ method: 'MCP.saveFile' }, transportAuthInfo); authInfo.request_url = getConfig(transportAuthInfo?.ecsEnv).request_url; } catch (authError) { console.error("获取鉴权信息失败:", authError); throw new Error("获取鉴权信息失败"); } // 调用保存文件API const saveResult = await saveFile(authInfo, { url, content }); if (saveResult && saveResult.errno === 0) { const taskId = saveResult.data?.task_id; if (!taskId) { return { content: [{ type: "text", text: "❌ 保存文件失败: 未获取到任务ID" }] }; } // 轮询任务状态 try { const finalResult = await pollTaskStatus(authInfo, taskId); const resultData = finalResult.data; let resultText = `✅ 文件保存成功!\n\n`; resultText += `🆔 任务ID: ${taskId}\n`; const fileInfo: any = { taskId }; if (resultData) { const qid = resultData.qid || authInfo.qid; const path = resultData.file_path; const nid = resultData.nid; const size = resultData.file_size; fileInfo.path = path; fileInfo.nid = nid; fileInfo.size = size; fileInfo.qid = qid; if (path) { resultText += `📂 云盘路径: ${path}\n`; } if (size) { resultText += `📦 文件大小: ${formatBytes(size)}\n`; } if (path && nid && qid) { const dirPath = path.substring(0, path.lastIndexOf('/') + 1); const href = `https://www.yunpan.com/file/index#/fileManage/my/file/${encodeURIComponent(dirPath)}?focus_nid=${nid}&owner_qid=${qid}`; resultText += `🔗 [点击查看云盘文件](${href})\n`; fileInfo.href = href; } } return { content: [ { type: "text", name: "x-save-result-json", text: JSON.stringify({ status: 'success', file: fileInfo }) }, { type: "text", name: "x-save-result-display", text: resultText } ] }; } catch (pollError: any) { const isTimeout = pollError.message.includes('轮询超时'); const status = isTimeout ? 'timeout' : 'failed'; const resultText = isTimeout ? `⏳ 文件保存轮询超时\n\n- 任务ID: ${taskId}\n- 请稍后检查云盘或使用任务ID查询状态。` : `❌ 文件保存失败\n\n- 任务ID: ${taskId}\n- 错误信息: ${pollError.message}`; return { content: [ { type: "text", name: "x-save-result-json", text: JSON.stringify({ status: status, taskId: taskId, error: pollError.message }) }, { type: "text", name: "x-save-result-display", text: resultText } ] }; } } else { throw new Error(saveResult?.errmsg || "API请求失败"); } } catch (error: any) { return { content: [ { type: "text", text: `保存文件时发生错误: ${error.message}`, } ], }; } },
  • Zod schema for tool inputs: optional url (download link) or content (file text), at least one required (validated in handler).
    { url: z.string().optional().describe("文件下载地址,url或content必传1个"), content: z.string().optional().describe("文件内容(md格式),url或content必传1个,需要传用户指定的完整内容,不能省略任何部分"), // upload_path: z.string() // .default('/来自mcp_server/') // .describe("云盘存储路径,必须以/开头和结尾。如不指定,默认为'/来自mcp_server/'。\n- 支持自动创建不存在的一级目录\n- 不支持不存在的多级目录") // .refine((path) => path.endsWith('/'), { // message: "路径必须以/结尾" // }) // .refine((path) => path.startsWith('/'), { // message: "路径必须以/开头" // }) },
  • registerFileSaveTool function that calls server.tool('file-save', description, schema, handler) to register the tool on the MCP server.
    export function registerFileSaveTool(server: McpServer) { server.tool( "file-save", "通过URL或文本内容保存文件到云盘", { url: z.string().optional().describe("文件下载地址,url或content必传1个"), content: z.string().optional().describe("文件内容(md格式),url或content必传1个,需要传用户指定的完整内容,不能省略任何部分"), // upload_path: z.string() // .default('/来自mcp_server/') // .describe("云盘存储路径,必须以/开头和结尾。如不指定,默认为'/来自mcp_server/'。\n- 支持自动创建不存在的一级目录\n- 不支持不存在的多级目录") // .refine((path) => path.endsWith('/'), { // message: "路径必须以/结尾" // }) // .refine((path) => path.startsWith('/'), { // message: "路径必须以/开头" // }) }, async ({ url, content }, mcpReq: any) => { // 参数验证 if (!url && !content) { return { content: [{ type: "text", text: "❌ 参数错误: 必须提供url或content参数" }] }; } const httpContext = gethttpContext(mcpReq, server); const transportAuthInfo = httpContext.authInfo; try { let authInfo: AuthInfo; try { // 获取鉴权信息 authInfo = await getAuthInfo({ method: 'MCP.saveFile' }, transportAuthInfo); authInfo.request_url = getConfig(transportAuthInfo?.ecsEnv).request_url; } catch (authError) { console.error("获取鉴权信息失败:", authError); throw new Error("获取鉴权信息失败"); } // 调用保存文件API const saveResult = await saveFile(authInfo, { url, content }); if (saveResult && saveResult.errno === 0) { const taskId = saveResult.data?.task_id; if (!taskId) { return { content: [{ type: "text", text: "❌ 保存文件失败: 未获取到任务ID" }] }; } // 轮询任务状态 try { const finalResult = await pollTaskStatus(authInfo, taskId); const resultData = finalResult.data; let resultText = `✅ 文件保存成功!\n\n`; resultText += `🆔 任务ID: ${taskId}\n`; const fileInfo: any = { taskId }; if (resultData) { const qid = resultData.qid || authInfo.qid; const path = resultData.file_path; const nid = resultData.nid; const size = resultData.file_size; fileInfo.path = path; fileInfo.nid = nid; fileInfo.size = size; fileInfo.qid = qid; if (path) { resultText += `📂 云盘路径: ${path}\n`; } if (size) { resultText += `📦 文件大小: ${formatBytes(size)}\n`; } if (path && nid && qid) { const dirPath = path.substring(0, path.lastIndexOf('/') + 1); const href = `https://www.yunpan.com/file/index#/fileManage/my/file/${encodeURIComponent(dirPath)}?focus_nid=${nid}&owner_qid=${qid}`; resultText += `🔗 [点击查看云盘文件](${href})\n`; fileInfo.href = href; } } return { content: [ { type: "text", name: "x-save-result-json", text: JSON.stringify({ status: 'success', file: fileInfo }) }, { type: "text", name: "x-save-result-display", text: resultText } ] }; } catch (pollError: any) { const isTimeout = pollError.message.includes('轮询超时'); const status = isTimeout ? 'timeout' : 'failed'; const resultText = isTimeout ? `⏳ 文件保存轮询超时\n\n- 任务ID: ${taskId}\n- 请稍后检查云盘或使用任务ID查询状态。` : `❌ 文件保存失败\n\n- 任务ID: ${taskId}\n- 错误信息: ${pollError.message}`; return { content: [ { type: "text", name: "x-save-result-json", text: JSON.stringify({ status: status, taskId: taskId, error: pollError.message }) }, { type: "text", name: "x-save-result-display", text: resultText } ] }; } } else { throw new Error(saveResult?.errmsg || "API请求失败"); } } catch (error: any) { return { content: [ { type: "text", text: `保存文件时发生错误: ${error.message}`, } ], }; } }, ); }
  • Calls registerFileSaveTool(server) within registerAllTools to register the file-save tool among others.
    registerFileSaveTool(server);
  • pollTaskStatus: Polls the cloud API for task completion (status 2), failure (3), or timeout after 120 attempts, used by handler for async file save.
    async function pollTaskStatus(authInfo: AuthInfo, taskId: string, interval = 1000, maxAttempts = 120): Promise<any> { let attempts = 0; let result; while (attempts < maxAttempts) { attempts++; result = await queryTaskStatus(authInfo, taskId); if (result.errno !== 0) { throw new Error(result.errmsg || '查询任务状态失败'); } const status = result.data?.status; if (status === 2) { // 处理完成 return result; } else if (status === 3) { // 处理失败 throw new Error(result.data?.error || '文件保存失败'); } // 等待下一次轮询 await new Promise(resolve => setTimeout(resolve, interval)); } // throw new Error('轮询超时,文件保存未完成'); return { content: [ { type: "text", text: `🚀 正在保存文件到云盘中,请稍后在"${result.data?.file_path}"目录查看\n` + `📦 文件大小:${result.data?.file_size}` } ] }; }

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