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), },

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