Skip to main content
Glama
Qihoo360

360 AI Cloud Drive MCP Server

by Qihoo360

file-rename

Rename files and folders stored in 360 AI Cloud Drive by specifying original paths and new names for organized cloud storage management.

Instructions

重命名云盘中的文件或文件夹。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
src_nameYes原文件或文件夹的完整路径,例如:/我的知识库/111.doc 或 /我的知识库/
new_nameYes新的名称(仅文件名或文件夹名,不含父路径)。文件夹名需以/结尾,例如:222.doc 或 我的知识库/

Implementation Reference

  • The main execution handler for the 'file-rename' tool. It retrieves authentication info, calls the renameFile API helper, processes the response, and returns success or error messages.
    async ({ src_name, new_name }, mcpReq: any) => {
      const httpContext = gethttpContext(mcpReq, server);
      
      // 使用transport中的authInfo
      const transportAuthInfo = httpContext.authInfo;
      try {
        let authInfo: AuthInfo;
        const extraParams = {
          src_name: src_name,
          new_name: new_name
        };
        
        try {
          // 传入方法名和参数
          authInfo = await getAuthInfo({
            method: 'File.rename',
            extraParams: extraParams
          }, transportAuthInfo);
          
          authInfo.request_url = getConfig(transportAuthInfo?.ecsEnv).request_url
        } catch (authError) {
          console.error("自动获取鉴权信息失败:", authError);
          throw new Error("获取鉴权信息失败,请提供有效的API_KEY");
        }
        
        // 调用API重命名文件
        const apiResponse = await renameFile(authInfo, src_name, new_name);
        
        // 检查API响应是否成功
        if (apiResponse && apiResponse.errno === 0) {
          // 获取文件类型(通过判断src_name末尾是否有斜杠来确定是文件夹还是文件)
          const isFolder = src_name.endsWith('/');
          const fileType = isFolder ? "文件夹" : "文件";
          
          // 提取原文件/文件夹名(从路径中获取最后一部分)
          const srcParts = src_name.split('/').filter(part => part !== '');
          const oldName = srcParts.length > 0 ? srcParts[srcParts.length - 1] : src_name;
          
          // 返回重命名成功信息
          return {
            content: [
              {
                type: "text",
                text: `成功将${fileType}"${oldName}"重命名为"${new_name}"!`,
              },
              {
                type: "text",
                text: TOOL_LIMIT_NOTE,
              },
            ],
          };
        } else {
          const errorMsg = apiResponse?.errmsg || "API请求失败";
          throw new Error(errorMsg);
        }
      } catch (error: any) {
        console.error("重命名文件出错:", error);
        return {
          content: [
            {
              type: "text",
              text: `重命名文件时发生错误: ${error.message}`,
            },
            {
              type: "text",
              text: TOOL_LIMIT_NOTE,
            },
          ],
        };
      }
    },
  • Zod schema defining the input parameters for the 'file-rename' tool: src_name (full path) and new_name (new filename/foldername).
      src_name: z.string().describe("原文件或文件夹的完整路径,例如:/我的知识库/111.doc 或 /我的知识库/"),
      new_name: z.string().describe("新的名称(仅文件名或文件夹名,不含父路径)。文件夹名需以/结尾,例如:222.doc 或 我的知识库/"),
    },
  • The server.tool call that registers the 'file-rename' tool, including name, description, input schema, and handler function.
    server.tool(
      "file-rename",
      "重命名云盘中的文件或文件夹。",
      {
        src_name: z.string().describe("原文件或文件夹的完整路径,例如:/我的知识库/111.doc 或 /我的知识库/"),
        new_name: z.string().describe("新的名称(仅文件名或文件夹名,不含父路径)。文件夹名需以/结尾,例如:222.doc 或 我的知识库/"),
      },
      async ({ src_name, new_name }, mcpReq: any) => {
        const httpContext = gethttpContext(mcpReq, server);
        
        // 使用transport中的authInfo
        const transportAuthInfo = httpContext.authInfo;
        try {
          let authInfo: AuthInfo;
          const extraParams = {
            src_name: src_name,
            new_name: new_name
          };
          
          try {
            // 传入方法名和参数
            authInfo = await getAuthInfo({
              method: 'File.rename',
              extraParams: extraParams
            }, transportAuthInfo);
            
            authInfo.request_url = getConfig(transportAuthInfo?.ecsEnv).request_url
          } catch (authError) {
            console.error("自动获取鉴权信息失败:", authError);
            throw new Error("获取鉴权信息失败,请提供有效的API_KEY");
          }
          
          // 调用API重命名文件
          const apiResponse = await renameFile(authInfo, src_name, new_name);
          
          // 检查API响应是否成功
          if (apiResponse && apiResponse.errno === 0) {
            // 获取文件类型(通过判断src_name末尾是否有斜杠来确定是文件夹还是文件)
            const isFolder = src_name.endsWith('/');
            const fileType = isFolder ? "文件夹" : "文件";
            
            // 提取原文件/文件夹名(从路径中获取最后一部分)
            const srcParts = src_name.split('/').filter(part => part !== '');
            const oldName = srcParts.length > 0 ? srcParts[srcParts.length - 1] : src_name;
            
            // 返回重命名成功信息
            return {
              content: [
                {
                  type: "text",
                  text: `成功将${fileType}"${oldName}"重命名为"${new_name}"!`,
                },
                {
                  type: "text",
                  text: TOOL_LIMIT_NOTE,
                },
              ],
            };
          } else {
            const errorMsg = apiResponse?.errmsg || "API请求失败";
            throw new Error(errorMsg);
          }
        } catch (error: any) {
          console.error("重命名文件出错:", error);
          return {
            content: [
              {
                type: "text",
                text: `重命名文件时发生错误: ${error.message}`,
              },
              {
                type: "text",
                text: TOOL_LIMIT_NOTE,
              },
            ],
          };
        }
      },
    );
  • Helper function that performs the actual HTTP POST request to the cloud drive API to rename the file or folder.
    async function renameFile(authInfo: AuthInfo, src_name: string, new_name: string): Promise<any> {
      try {
        const url = new URL(authInfo.request_url || '');
        
        // 构建请求头
        const headers = {
          'Access-Token': authInfo.access_token || '',
          'Content-Type': 'application/x-www-form-urlencoded'
        };
    
        // 构建请求参数
        const baseParams: Record<string, string> = {
          'method': 'File.rename',
          'access_token': authInfo.access_token || '',
          'qid': authInfo.qid || '',
          'sign': authInfo.sign || '',
          'src_name': src_name,
          'new_name': new_name
        };
    
        // 构建表单数据
        const formData = new URLSearchParams();
        Object.entries(baseParams).forEach(([key, value]) => {
          formData.append(key, String(value));
        });
        
        const response = await fetch(url.toString(), {
          method: 'POST',
          headers: headers,
          body: formData
        });
        
        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;
      }
    }
  • Invocation of registerFileRenameTool within registerAllTools to register the tool on the MCP server.
    registerFileRenameTool(server);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It states the action ('rename') but doesn't disclose behavioral traits like whether it requires specific permissions, if it overwrites existing items with the new name, what happens on failure (e.g., if src_name doesn't exist), or if it's idempotent. This is a significant gap for a mutation tool with zero annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence in Chinese that directly states the tool's purpose without any fluff. It's front-loaded and appropriately sized for a simple rename operation, with every word contributing to clarity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (a mutation operation with no annotations and no output schema), the description is incomplete. It lacks information on behavioral aspects (e.g., error handling, permissions), output format (what is returned on success/failure), and usage context compared to siblings. This is inadequate for a tool that modifies data.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with clear descriptions for both parameters (src_name as original path, new_name as new name without parent path). The description adds no additional meaning beyond the schema, such as explaining path conventions or constraints (e.g., special characters allowed). Baseline 3 is appropriate since the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('重命名' meaning 'rename') and the resource ('云盘中的文件或文件夹' meaning 'files or folders in cloud storage'). It distinguishes from siblings like file-move (which likely moves files) and file-save (which likely saves content), but doesn't explicitly differentiate from tools like make-dir (which creates directories) in terms of when to use rename vs create new.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. For example, it doesn't mention when to use file-rename versus file-move (which might handle path changes) or make-dir (for creating new folders with different names). There's no context about prerequisites, such as needing existing files/folders to rename.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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