Skip to main content
Glama
aliyun

AlibabaCloud DevOps MCP Server

Official
by aliyun

delete_file

Remove files from Alibaba Cloud Codeup repositories to manage code changes and maintain repository organization.

Instructions

[Code Management] Delete a file from 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
commitMessageYesCommit message
branchYesBranch name

Implementation Reference

  • Handler for the 'delete_file' tool: parses input arguments using DeleteFileSchema and calls the deleteFileFunc helper to perform the deletion, then returns the result as JSON.
    case "delete_file": {
      const args = types.DeleteFileSchema.parse(request.params.arguments);
      const result = await files.deleteFileFunc(
        args.organizationId,
        args.repositoryId,
        args.filePath,
        args.commitMessage,
        args.branch
      );
      return {
        content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
      };
    }
  • Registers the 'delete_file' tool in the code management tools array, specifying name, description, and input schema.
    {
      name: "delete_file",
      description: "[Code Management] Delete a file from a Codeup repository",
      inputSchema: zodToJsonSchema(types.DeleteFileSchema),
    },
  • Core helper function that encodes parameters, constructs the API URL, sends DELETE request to Codeup API to delete the file, and parses the response.
    export async function deleteFileFunc(
      organizationId: string,
      repositoryId: string,
      filePath: string,
      commitMessage: string,
      branch: string
    ): Promise<z.infer<typeof DeleteFileResponseSchema>> {
      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 = encodeURIComponent(filePath);
      }
    
      const baseUrl = `/oapi/v1/codeup/organizations/${organizationId}/repositories/${encodedRepoId}/files/${encodedFilePath}`;
      
      // 构建查询参数
      const queryParams: Record<string, string | number | undefined> = {
        branch: branch,
        commitMessage: commitMessage
      };
    
      // 使用buildUrl函数构建包含查询参数的URL
      const url = buildUrl(baseUrl, queryParams);
    
      const response = await yunxiaoRequest(url, {
        method: "DELETE",
      });
    
      return DeleteFileResponseSchema.parse(response);
    }
  • Zod schema defining the input parameters for the delete_file tool: organizationId, repositoryId, filePath, commitMessage, branch.
    export const DeleteFileSchema = 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"),
      commitMessage: z.string().describe("Commit message"),
      branch: z.string().describe("Branch name"),
    });

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