Skip to main content
Glama
aliyun

AlibabaCloud DevOps MCP Server

Official
by aliyun

create_file

Create and commit new files to Codeup repositories for managing code changes in Alibaba Cloud DevOps workflows.

Instructions

[Code Management] Create a new 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 text

Implementation Reference

  • Core handler function createFileFunc that implements the logic to create a file in Codeup repository via API call, including path encoding, request body preparation, and response parsing.
    export async function createFileFunc(
      organizationId: string,
      repositoryId: string,
      filePath: string,
      content: string,
      commitMessage: string,
      branch: string,
      encoding?: string
    ): Promise<z.infer<typeof CreateFileResponseSchema>> {
      let encodedRepoId = repositoryId;
      let encodedFilePath = filePath;
    
      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("/")) {
        encodedFilePath = pathEscape(filePath);
      }
    
      const url = `/oapi/v1/codeup/organizations/${organizationId}/repositories/${encodedRepoId}/files`;
    
      const body = {
        branch: branch,
        filePath: encodedFilePath,
        content: content,
        commitMessage: commitMessage,
        encoding: encoding || "text"  // 默认使用text编码
      };
    
      const response = await yunxiaoRequest(url, {
        method: "POST",
        body: body
      });
    
      return CreateFileResponseSchema.parse(response);
    }
  • Registers the 'create_file' tool with its name, description, and input schema in the getCodeManagementTools array.
    name: "create_file",
    description: "[Code Management] Create a new file in a Codeup repository",
    inputSchema: zodToJsonSchema(types.CreateFileSchema),
  • Zod schema definition for CreateFileSchema used as input validation for the create_file tool.
    export const CreateFileSchema = 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().optional().describe("Encoding rule, options {text, base64}, default is text"),
    });
  • Zod schema for CreateFileResponseSchema used to parse the API response.
    export const CreateFileResponseSchema = z.object({
      filePath: z.string().optional().describe("File path"),
      branch: z.string().optional().describe("Branch name"),
      newOid: z.string().optional().describe("Git Object ID"),
    });
  • Dispatch handler in handleCodeManagementTools that parses input arguments and delegates to createFileFunc, formats response for MCP.
    case "create_file": {
      const args = types.CreateFileSchema.parse(request.params.arguments);
      const result = await files.createFileFunc(
        args.organizationId,
        args.repositoryId,
        args.filePath,
        args.content,
        args.commitMessage,
        args.branch,
        args.encoding
      );
      return {
        content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
      };
    }

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