Skip to main content
Glama
aliyun

AlibabaCloud DevOps MCP Server

Official
by aliyun

update_file

Modify existing files in Codeup repositories by providing new content, commit messages, and branch specifications for version-controlled code updates.

Instructions

[Code Management] Update an existing file in a Codeup repository

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
organizationIdYesOrganization ID, can be found in the basic information page of the organization admin console
repositoryIdYesRepository ID or a combination of organization ID and repository name, for example: 2835387 or organizationId%2Frepo-name (Note: slashes need to be URL encoded as %2F)
filePathYesFile path, needs to be URL encoded, for example: /src/main/java/com/aliyun/test.java
contentYesFile content
commitMessageYesCommit message, not empty, no more than 102400 characters
branchYesBranch name
encodingNoEncoding rule, options {text, base64}, default is texttext

Implementation Reference

  • Handler case for 'update_file' tool that parses arguments with UpdateFileSchema and calls the updateFileFunc helper.
    case "update_file": {
      const args = types.UpdateFileSchema.parse(request.params.arguments);
      const result = await files.updateFileFunc(
        args.organizationId,
        args.repositoryId,
        args.filePath,
        args.content,
        args.commitMessage,
        args.branch,
        args.encoding
      );
      return {
        content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
      };
  • Core implementation of updateFileFunc that performs the PUT request to update the file content in Codeup repository.
    export async function updateFileFunc(
      organizationId: string,
      repositoryId: string,
      filePath: string,
      content: string,
      commitMessage: string,
      branch: string,
      encoding?: string
    ): Promise<z.infer<typeof CreateFileResponseSchema>> {
      //const { encodedRepoId, encodedFilePath } = handlePathEncoding(repositoryId, filePath);
      let encodedRepoId = repositoryId;
      let encodedFilePath = filePath;
    
      // 自动处理repositoryId中未编码的斜杠
      if (repositoryId.includes("/")) {
        // 发现未编码的斜杠,自动进行URL编码
        const parts = repositoryId.split("/", 2);
        if (parts.length === 2) {
          const encodedRepoName = encodeURIComponent(parts[1]);
          // 移除编码中的+号(空格被编码为+,但我们需要%20)
          const formattedEncodedName = encodedRepoName.replace(/\+/g, "%20");
          encodedRepoId = `${parts[0]}%2F${formattedEncodedName}`;
        }
      }
    
      // 确保filePath已被URL编码
      if (filePath.includes("/")) {
        const pathToEncode = filePath.startsWith("/") ? filePath.substring(1) : filePath;
        encodedFilePath = encodeURIComponent(pathToEncode);
      }
    
      const url = `/oapi/v1/codeup/organizations/${organizationId}/repositories/${encodedRepoId}/files/${encodedFilePath}`;
    
      const body = {
        branch: branch,
        commitMessage: commitMessage,
        content: content,
        encoding: encoding || "text"  // 默认使用text编码
      };
    
      const response = await yunxiaoRequest(url, {
        method: "PUT",
        body: body
      });
    
      return CreateFileResponseSchema.parse(response);
    }
  • Zod schema definition for UpdateFileSchema used for input validation of the update_file tool.
    export const UpdateFileSchema = z.object({
      organizationId: z.string().describe("Organization ID, can be found in the basic information page of the organization admin console"),
      repositoryId: z.string().describe("Repository ID or a combination of organization ID and repository name, for example: 2835387 or organizationId%2Frepo-name (Note: slashes need to be URL encoded as %2F)"),
      filePath: z.string().describe("File path, needs to be URL encoded, for example: /src/main/java/com/aliyun/test.java"),
      content: z.string().describe("File content"),
      commitMessage: z.string().describe("Commit message, not empty, no more than 102400 characters"),
      branch: z.string().describe("Branch name"),
      encoding: z.string().default("text").optional().describe("Encoding rule, options {text, base64}, default is text"),
    });
  • Tool registration for 'update_file' including name, description, and input schema reference.
    {
      name: "update_file",
      description: "[Code Management] Update an existing file in a Codeup repository",
      inputSchema: zodToJsonSchema(types.UpdateFileSchema),
    },
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It states the tool updates a file but doesn't disclose critical behaviors like whether this overwrites existing content, requires specific permissions, creates a commit history, or has rate limits. The '[Code Management]' tag adds some context but is insufficient for a mutation tool.

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 with zero wasted words. It's front-loaded with the core purpose and includes a relevant contextual tag ('[Code Management]'). Every element earns its place.

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?

For a mutation tool with 7 parameters, no annotations, and no output schema, the description is incomplete. It lacks behavioral details (e.g., commit creation, error conditions), doesn't explain the update's effect on repository state, and provides no guidance on usage versus siblings. The high parameter count and mutation nature demand more context.

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%, providing detailed documentation for all 7 parameters. The description adds no additional parameter semantics beyond what's in the schema, so it meets the baseline of 3 where 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 ('Update') and resource ('an existing file in a Codeup repository'), distinguishing it from sibling tools like 'create_file' and 'delete_file'. However, it doesn't explicitly differentiate from other update tools like 'update_work_item' or 'update_sprint' beyond the resource type.

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?

No guidance is provided on when to use this tool versus alternatives. The description doesn't mention prerequisites (e.g., file must exist), compare with similar tools like 'create_file', or specify contexts where this is appropriate versus other update operations.

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/aliyun/alibabacloud-devops-mcp-server'

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