@iflow-mcp/alibabacloud-devops-mcp-server
Version:
MCP Server for using the alibabacloud-devops API: allows AI assistants to directly participate in development collaboration, helping teams optimize development processes and improve efficiency.
861 lines • 70.6 kB
JavaScript
#!/usr/bin/env node
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
import { z } from 'zod';
import { zodToJsonSchema } from 'zod-to-json-schema';
import * as branches from './operations/codeup/branches.js';
import * as files from './operations/codeup/files.js';
import * as repositories from './operations/codeup/repositories.js';
import * as changeRequests from './operations/codeup/changeRequests.js';
import * as changeRequestComments from './operations/codeup/changeRequestComments.js';
import * as organization from './operations/organization/organization.js';
import * as members from './operations/organization/members.js';
import * as project from './operations/projex/project.js';
import * as workitem from './operations/projex/workitem.js';
import * as compare from './operations/codeup/compare.js';
import * as pipeline from './operations/flow/pipeline.js';
import * as pipelineJob from './operations/flow/pipelineJob.js';
import * as serviceConnection from './operations/flow/serviceConnection.js';
import * as packageRepositories from './operations/packages/repositories.js';
import * as artifacts from './operations/packages/artifacts.js';
import { isYunxiaoError, YunxiaoValidationError } from "./common/errors.js";
import { VERSION } from "./common/version.js";
import { config } from "dotenv";
import * as types from "./common/types.js";
const server = new Server({
name: "alibabacloud-devops-mcp-server",
version: VERSION,
}, {
capabilities: {
tools: {},
},
});
function formatYunxiaoError(error) {
let message = `Yunxiao API Error: ${error.message}`;
if (error instanceof YunxiaoValidationError) {
message = `Parameter validation failed: ${error.message}`;
if (error.response) {
message += `\n errorMessage: ${JSON.stringify(error.response, null, 2)}`;
}
// 添加常见参数错误的提示
if (error.message.includes('name')) {
message += `\n Suggestion: Please check whether the pipeline name meets the requirements.`;
}
if (error.message.includes('content') || error.message.includes('yaml')) {
message += `\n Suggestion: Please check whether the generated YAML format is correct.`;
}
}
else {
// 处理通用的Yunxiao错误
message = `Yunxiao API error (${error.status}): ${error.message}`;
if (error.response) {
const response = error.response;
if (response.errorCode) {
message += `\n errorCode: ${response.errorCode}`;
}
if (response.errorMessage && response.errorMessage !== error.message) {
message += `\n errorMessage: ${response.errorMessage}`;
}
if (response.data && typeof response.data === 'object') {
message += `\n data: ${JSON.stringify(response.data, null, 2)}`;
}
}
// 根据状态码提供通用建议
switch (error.status) {
case 400:
message += `\n Suggestion: Please check whether the request parameters are correct, especially whether all required parameters have been provided.`;
break;
case 500:
message += `\n Suggestion: Internal server error. Please try again later or contact technical support.`;
break;
case 502:
case 503:
case 504:
message += `\n Suggestion: The service is temporarily unavailable. Please try again later.`;
break;
}
}
return message;
}
server.setRequestHandler(ListToolsRequestSchema, async () => {
return {
tools: [
// Branch Operations
{
name: "create_branch",
description: "[Code Management] Create a new branch in a Codeup repository",
inputSchema: zodToJsonSchema(types.CreateBranchSchema),
},
{
name: "get_branch",
description: "[Code Management] Get information about a branch in a Codeup repository",
inputSchema: zodToJsonSchema(types.GetBranchSchema),
},
{
name: "delete_branch",
description: "[Code Management] Delete a branch from a Codeup repository",
inputSchema: zodToJsonSchema(types.DeleteBranchSchema),
},
{
name: "list_branches",
description: "[Code Management] List branches in a Codeup repository",
inputSchema: zodToJsonSchema(types.ListBranchesSchema),
},
// File Operations
{
name: "get_file_blobs",
description: "[Code Management] Get file content from a Codeup repository",
inputSchema: zodToJsonSchema(types.GetFileBlobsSchema),
},
{
name: "create_file",
description: "[Code Management] Create a new file in a Codeup repository",
inputSchema: zodToJsonSchema(types.CreateFileSchema),
},
{
name: "update_file",
description: "[Code Management] Update an existing file in a Codeup repository",
inputSchema: zodToJsonSchema(types.UpdateFileSchema),
},
{
name: "delete_file",
description: "[Code Management] Delete a file from a Codeup repository",
inputSchema: zodToJsonSchema(types.DeleteFileSchema),
},
{
name: "list_files",
description: "[Code Management] List file tree from a Codeup repository",
inputSchema: zodToJsonSchema(types.ListFilesSchema),
},
{
name: "compare",
description: "[Code Management] Query code to compare content",
inputSchema: zodToJsonSchema(types.GetCompareSchema),
},
// Repository Operations
{
name: "get_repository",
description: "[Code Management] Get information about a Codeup repository",
inputSchema: zodToJsonSchema(types.GetRepositorySchema),
},
{
name: "list_repositories",
description: "[Code Management] Get the CodeUp Repository List.\n" +
"\n" +
"A Repository serves as a unit for managing source code and is distinct from a Project.\n" +
"\n" +
"Use Case:\n" +
"\n" +
"View my repositories",
inputSchema: zodToJsonSchema(types.ListRepositoriesSchema),
},
// Change Request Operations
{
name: "get_change_request",
description: "[Code Management] Get information about a change request",
inputSchema: zodToJsonSchema(types.GetChangeRequestSchema),
},
{
name: "list_change_requests",
description: "[Code Management] List change requests",
inputSchema: zodToJsonSchema(types.ListChangeRequestsSchema),
},
{
name: "create_change_request",
description: "[Code Management] Create a new change request",
inputSchema: zodToJsonSchema(types.CreateChangeRequestSchema),
},
{
name: "create_change_request_comment",
description: "[Code Management] Create a comment on a change request",
inputSchema: zodToJsonSchema(types.CreateChangeRequestCommentSchema),
},
{
name: "list_change_request_comments",
description: "[Code Management] List comments on a change request",
inputSchema: zodToJsonSchema(types.ListChangeRequestCommentsSchema),
},
{
name: "list_change_request_patch_sets",
description: "[Code Management] List patch sets for a change request",
inputSchema: zodToJsonSchema(types.ListChangeRequestPatchSetsSchema),
},
// Organization Operations
{
name: "get_current_organization_info",
description: "Get information about the current user and organization based on the token. In the absence of an explicitly specified organization ID, this result will take precedence.",
inputSchema: zodToJsonSchema(z.object({})),
},
{
name: "get_user_organizations",
description: "Get the list of organizations the current user belongs to",
inputSchema: zodToJsonSchema(z.object({})),
},
{
name: "get_current_user",
description: "Get information about the current user based on the token. In the absence of an explicitly specified user ID, this result will take precedence.",
inputSchema: zodToJsonSchema(z.object({})),
},
{
name: "list_organization_departments",
description: "Get the list of departments in an organization",
inputSchema: zodToJsonSchema(types.GetOrganizationDepartmentsSchema),
},
{
name: "get_organization_department_info",
description: "Get information about a department in an organization",
inputSchema: zodToJsonSchema(types.GetOrganizationDepartmentInfoSchema),
},
{
name: "get_organization_department_ancestors",
description: "Get the ancestors of a department in an organization",
inputSchema: zodToJsonSchema(types.GetOrganizationDepartmentAncestorsSchema),
},
{
name: "list_organization_members",
description: "list user members in an organization",
inputSchema: zodToJsonSchema(types.GetOrganizationMembersSchema),
},
{
name: "get_organization_member_info",
description: "Get information about a member in an organization",
inputSchema: zodToJsonSchema(types.GetOrganizationMemberInfoSchema),
},
{
name: "get_organization_member_info_by_user_id",
description: "Get information about a member in an organization by user ID",
inputSchema: zodToJsonSchema(types.GetOrganizationMemberByUserIdInfoSchema),
},
{
name: "search_organization_members",
description: "[Organization Management] Search for organization members",
inputSchema: zodToJsonSchema(types.SearchOrganizationMembersSchema),
},
{
name: "list_organization_roles",
description: "[Organization Management] List organization roles",
inputSchema: zodToJsonSchema(types.ListOrganizationRolesSchema),
},
{
name: "get_organization_role",
description: "[Organization Management] Get information about an organization role",
inputSchema: zodToJsonSchema(types.GetOrganizationRoleSchema),
},
// Project Operations
{
name: "get_project",
description: "[Project Management] Get information about a Yunxiao project",
inputSchema: zodToJsonSchema(types.GetProjectSchema),
},
{
name: "search_projects",
description: "[Project Management] Search for Yunxiao Project List. A Project is a project management unit that includes work items and sprints, and it is different from a code repository (Repository).\n" +
"\n" +
"Use Cases:\n" +
"\n" +
"Query projects I am involved in\n" +
"Query projects I have created",
inputSchema: zodToJsonSchema(types.SearchProjectsSchema),
},
// Sprint Operations
// {
// name: "get_sprint",
// description: "Get information about a sprint",
// inputSchema: zodToJsonSchema(sprint.GetSprintSchema),
// },
// {
// name: "list_sprints",
// description: "List sprints in a project",
// inputSchema: zodToJsonSchema(sprint.ListSprintsSchema),
// },
// Work Item Operations
{
name: "get_work_item",
description: "[Project Management] Get information about a work item",
inputSchema: zodToJsonSchema(types.GetWorkItemSchema),
},
{
name: "create_work_item",
description: "[Project Management] Create a work item",
inputSchema: zodToJsonSchema(types.CreateWorkItemSchema),
},
{
name: "search_workitems",
description: "[Project Management] Search work items with various filter conditions",
inputSchema: zodToJsonSchema(types.SearchWorkitemsSchema),
},
{
name: "get_work_item_types",
description: "[Project Management] Get the list of work item types for a project",
inputSchema: zodToJsonSchema(z.object({
organizationId: z.string().describe("Organization ID"),
id: z.string().describe("Project unique identifier"),
category: z.string().describe("Work item type category, optional values: Req, Bug, Task, etc.")
})),
},
// Pipeline Operations
{
name: "get_pipeline",
description: "[Pipeline Management] Get details of a specific pipeline in an organization",
inputSchema: zodToJsonSchema(types.GetPipelineSchema),
},
{
name: "list_pipelines",
description: "[Pipeline Management] Get a list of pipelines in an organization with filtering options",
inputSchema: zodToJsonSchema(types.ListPipelinesSchema),
},
{
name: "generate_pipeline_yaml",
description: "[Pipeline Management] Generate only the YAML configuration for a pipeline without creating it.\n\n" +
"**📋 Use Cases:**\n" +
"- Preview YAML before creating pipeline\n" +
"- Generate YAML for manual deployment\n" +
"- Debug pipeline configuration\n\n" +
"**📖 Recommended Workflow:**\n" +
"1. 🎯 Parse user description for explicit parameters\n" +
"2. 🔍 If missing context, prefer IDE detection (terminal + file reading) over API calls\n" +
"3. 🚀 Call this tool with collected parameters\n\n" +
"**💡 Parameter Collection Strategy:**\n" +
"- For QUICK pipeline creation: Use IDE detection (git config, file reading)\n" +
"- For PRECISE parameter selection: Consider list_repositories, list_service_connections when needed\n" +
"- Balance efficiency vs. accuracy based on user intent\n\n" +
"**⚡ Built-in capabilities:** Handles default service connections internally, auto-extracts project name from repo URL",
inputSchema: zodToJsonSchema(types.CreatePipelineFromDescriptionSchema),
},
{
name: "create_pipeline_from_description",
description: "[Pipeline Management] Create a pipeline using structured parameters extracted from user descriptions and environment context.\n\n" +
"**🔧 Built-in Capabilities:**\n" +
"- ✅ Automatically retrieves default service connection IDs when not specified\n" +
"- ✅ Handles repository and service connection logic internally\n" +
"- ✅ Auto-extracts project name from repository URL (git@host:org/repo.git → repo)\n" +
"- ✅ Supports both IDE detection and explicit parameter specification\n\n" +
"**📖 Recommended Workflow:**\n" +
"1. 🎯 PARSE user description for explicit parameters\n" +
"2. 🔍 DETECT missing info from IDE environment FIRST:\n" +
" - Run `git config --get remote.origin.url` → repoUrl\n" +
" - Run `git branch --show-current` → branch\n" +
" - Auto-extract serviceName from repoUrl\n" +
" - Check project files for tech stack:\n" +
" * pom.xml → buildLanguage='java', buildTool='maven'\n" +
" * build.gradle → buildLanguage='java', buildTool='gradle'\n" +
" * package.json + package-lock.json → buildLanguage='nodejs', buildTool='npm'\n" +
" * package.json + yarn.lock → buildLanguage='nodejs', buildTool='yarn'\n" +
" * requirements.txt → buildLanguage='python', buildTool='pip'\n" +
" * go.mod → buildLanguage='go', buildTool='go'\n" +
" * *.csproj → buildLanguage='dotnet', buildTool='dotnet'\n" +
"3. 🚀 CALL this tool with collected parameters\n\n" +
"**⚠️ Important Guidelines:**\n" +
"- DO NOT call list_repositories unless user explicitly asks to choose from available repositories\n" +
"- DO NOT call list_service_connections unless user explicitly asks to choose from available connections\n" +
"- ALWAYS try IDE detection first before making any API calls\n" +
"- If IDE detection fails, THEN consider API calls as fallback\n\n" +
"**🎯 Parameter Priority:**\n" +
"1. 👤 USER EXPLICIT (highest) - buildLanguage, buildTool, versions, deployTarget\n" +
"2. 🔍 IDE DETECTION (preferred) - repoUrl, branch, serviceName, tech stack\n" +
"3. 🤖 TOOL DEFAULTS (automatic) - serviceConnectionId, organizationId\n\n" +
"**🔍 IDE Detection Rules (MUST TRY FIRST):**\n" +
"- 📂 Repository: `git config --get remote.origin.url` → repoUrl\n" +
"- 🌿 Branch: `git branch --show-current` → branch\n" +
"- 🏷️ Service Name: Auto-extracted from repoUrl (git@host:org/repo.git → repo)\n" +
"- ☕ Java Maven: pom.xml exists → buildLanguage='java', buildTool='maven'\n" +
"- 🏗️ Java Gradle: build.gradle exists → buildLanguage='java', buildTool='gradle'\n" +
"- 🟢 Node npm: package.json + package-lock.json → buildLanguage='nodejs', buildTool='npm'\n" +
"- 🧶 Node yarn: package.json + yarn.lock → buildLanguage='nodejs', buildTool='yarn'\n" +
"- 🐍 Python: requirements.txt → buildLanguage='python', buildTool='pip'\n" +
"- 🐹 Go: go.mod → buildLanguage='go', buildTool='go'\n" +
"- 💙 .NET: *.csproj → buildLanguage='dotnet', buildTool='dotnet'\n\n" +
"**📝 Version Detection (from project files):**\n" +
"- ☕ JDK: Read pom.xml <maven.compiler.source> → jdkVersion\n" +
"- 🟢 Node: Read package.json engines.node → nodeVersion\n" +
"- 🐍 Python: Read .python-version, pyproject.toml → pythonVersion\n" +
"- 🐹 Go: Read go.mod go directive → goVersion\n\n" +
"**🎯 Deployment Parsing:**\n" +
"- '部署到主机/VM/虚拟机' → deployTarget='vm'\n" +
"- '部署到Kubernetes/K8s' → deployTarget='k8s'\n" +
"- '只构建/构建制品' → deployTarget='none'\n\n" +
"**🔗 Service Connection Strategy (3 scenarios):**\n" +
"1. **User specifies ID explicitly** (e.g., '使用服务连接ID abc123')\n" +
" → ✅ Pass serviceConnectionId=abc123 directly, NO list_service_connections call needed\n" +
"2. **User doesn't specify any ID** (most common case)\n" +
" → ✅ Pass serviceConnectionId=null, tool will auto-retrieve default ID internally\n" +
"3. **User wants to choose from available options** (e.g., '显示可用的服务连接让我选择')\n" +
" → 🔍 Call list_service_connections first, then let user choose, then create pipeline\n\n" +
"**🤔 When to Use Other Tools:**\n" +
"- User asks to \"select from available repositories\" → use list_repositories first\n" +
"- User wants to \"choose from service connections\" → use list_service_connections first\n" +
"- User wants to see options before deciding → gather info first, then create\n" +
"- For quick creation with current repo → directly use IDE detection\n\n" +
"**✅ Required:** organizationId, name, buildLanguage, buildTool",
inputSchema: zodToJsonSchema(types.CreatePipelineFromDescriptionSchema),
},
{
name: "smart_list_pipelines",
description: "[Pipeline Management] Intelligently search pipelines with natural language time references (e.g., 'today', 'this week')",
inputSchema: zodToJsonSchema(z.object({
organizationId: z.string().describe("Organization ID"),
timeReference: z.string().optional().describe("Natural language time reference such as 'today', 'yesterday', 'this week', 'last month', etc."),
pipelineName: z.string().optional().describe("Pipeline name filter"),
statusList: z.string().optional().describe("Pipeline status list, comma separated (SUCCESS,RUNNING,FAIL,CANCELED,WAITING)"),
perPage: z.number().int().min(1).max(30).default(10).optional().describe("Number of items per page"),
page: z.number().int().min(1).default(1).optional().describe("Page number")
})),
},
{
name: "create_pipeline_run",
description: "[Pipeline Management] Run a pipeline with optional parameters",
inputSchema: zodToJsonSchema(types.CreatePipelineRunSchema),
},
{
name: "get_latest_pipeline_run",
description: "[Pipeline Management] Get information about the latest pipeline run",
inputSchema: zodToJsonSchema(types.GetLatestPipelineRunSchema),
},
{
name: "get_pipeline_run",
description: "[Pipeline Management] Get details of a specific pipeline run instance",
inputSchema: zodToJsonSchema(types.GetPipelineRunSchema),
},
{
name: "list_pipeline_runs",
description: "[Pipeline Management] Get a list of pipeline run instances with filtering options",
inputSchema: zodToJsonSchema(types.ListPipelineRunsSchema),
},
{
name: "list_pipeline_jobs_by_category",
description: "[Pipeline Management] Get pipeline execution tasks by category. Currently only supports DEPLOY category.",
inputSchema: zodToJsonSchema(types.ListPipelineJobsByCategorySchema),
},
{
name: "list_pipeline_job_historys",
description: "[Pipeline Management] Get the execution history of a pipeline task. Retrieve all execution records for a specific task in a pipeline.",
inputSchema: zodToJsonSchema(types.ListPipelineJobHistorysSchema),
},
{
name: "execute_pipeline_job_run",
description: "[Pipeline Management] Manually run a pipeline task. Start a specific job in a pipeline run instance.",
inputSchema: zodToJsonSchema(types.ExecutePipelineJobRunSchema),
},
{
name: "get_pipeline_job_run_log",
description: "[Pipeline Management] Get the execution logs of a pipeline job. Retrieve the log content for a specific job in a pipeline run.",
inputSchema: zodToJsonSchema(types.GetPipelineJobRunLogSchema),
},
{
name: "update_pipeline",
description: "[Pipeline Management] Update an existing pipeline in Yunxiao by pipelineId. Use this to update pipeline YAML, stages, jobs, etc.",
inputSchema: zodToJsonSchema(types.UpdatePipelineSchema),
},
// Package Repository Operations
{
name: "list_package_repositories",
description: "[Packages Management] List package repositories in an organization with filtering options",
inputSchema: zodToJsonSchema(types.ListPackageRepositoriesSchema),
},
// Package Artifact Operations
{
name: "list_artifacts",
description: "[Packages Management] List artifacts in a package repository with filtering options",
inputSchema: zodToJsonSchema(types.ListArtifactsSchema),
},
{
name: "get_artifact",
description: "[Packages Management] Get information about a single artifact in a package repository",
inputSchema: zodToJsonSchema(types.GetArtifactSchema),
},
// Service Connection Operations
{
name: "list_service_connections",
description: "[Service Connection Management] List service connections in an organization with filtering options",
inputSchema: zodToJsonSchema(types.ListServiceConnectionsSchema),
},
// Work Item Type Operations
{
name: "list_all_work_item_types",
description: "[Project Management] List all work item types in an organization",
inputSchema: zodToJsonSchema(types.ListAllWorkItemTypesSchema),
},
{
name: "list_work_item_types",
description: "[Project Management] List work item types in a project space",
inputSchema: zodToJsonSchema(types.ListWorkItemTypesSchema),
},
{
name: "get_work_item_type",
description: "[Project Management] Get details of a specific work item type",
inputSchema: zodToJsonSchema(types.GetWorkItemTypeSchema),
},
{
name: "list_work_item_relation_work_item_types",
description: "[Project Management] List work item types that can be related to a specific work item",
inputSchema: zodToJsonSchema(types.ListWorkItemRelationWorkItemTypesSchema),
},
{
name: "get_work_item_type_field_config",
description: "[Project Management] Get field configuration for a specific work item type",
inputSchema: zodToJsonSchema(types.GetWorkItemTypeFieldConfigSchema),
},
{
name: "get_work_item_workflow",
description: "[Project Management] Get workflow information for a specific work item type",
inputSchema: zodToJsonSchema(types.GetWorkItemWorkflowSchema),
},
{
name: "list_work_item_comments",
description: "[Project Management] List comments for a specific work item",
inputSchema: zodToJsonSchema(types.ListWorkItemCommentsSchema),
},
{
name: "create_work_item_comment",
description: "[Project Management] Create a comment for a specific work item",
inputSchema: zodToJsonSchema(types.CreateWorkItemCommentSchema),
}
],
};
});
server.setRequestHandler(CallToolRequestSchema, async (request) => {
try {
if (!request.params.arguments) {
throw new Error("Arguments are required");
}
switch (request.params.name) {
// Branch Operations
case "create_branch": {
const args = types.CreateBranchSchema.parse(request.params.arguments);
const branch = await branches.createBranchFunc(args.organizationId, args.repositoryId, args.branch, args.ref);
return {
content: [{ type: "text", text: JSON.stringify(branch, null, 2) }],
};
}
case "get_branch": {
const args = types.GetBranchSchema.parse(request.params.arguments);
const branch = await branches.getBranchFunc(args.organizationId, args.repositoryId, args.branchName);
return {
content: [{ type: "text", text: JSON.stringify(branch, null, 2) }],
};
}
case "delete_branch": {
const args = types.DeleteBranchSchema.parse(request.params.arguments);
const result = await branches.deleteBranchFunc(args.organizationId, args.repositoryId, args.branchName);
return {
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
};
}
case "list_branches": {
const args = types.ListBranchesSchema.parse(request.params.arguments);
const branchList = await branches.listBranchesFunc(args.organizationId, args.repositoryId, args.page, args.perPage, args.sort, args.search ?? undefined);
return {
content: [{ type: "text", text: JSON.stringify(branchList, null, 2) }],
};
}
// File Operations
case "get_file_blobs": {
const args = types.GetFileBlobsSchema.parse(request.params.arguments);
const fileContent = await files.getFileBlobsFunc(args.organizationId, args.repositoryId, args.filePath, args.ref);
return {
content: [{ type: "text", text: JSON.stringify(fileContent, null, 2) }],
};
}
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) }],
};
}
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) }],
};
}
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) }],
};
}
case "list_files": {
const args = types.ListFilesSchema.parse(request.params.arguments);
const fileList = await files.listFilesFunc(args.organizationId, args.repositoryId, args.path, args.ref, args.type);
return {
content: [{ type: "text", text: JSON.stringify(fileList, null, 2) }],
};
}
case "compare": {
const args = types.GetCompareSchema.parse(request.params.arguments);
const compareResult = await compare.getCompareFunc(args.organizationId, args.repositoryId, args.from, args.to, args.sourceType ?? undefined, args.targetType ?? undefined, args.straight ?? undefined);
return {
content: [{ type: "text", text: JSON.stringify(compareResult, null, 2) }],
};
}
// Repository Operations
case "get_repository": {
const args = types.GetRepositorySchema.parse(request.params.arguments);
const repository = await repositories.getRepositoryFunc(args.organizationId, args.repositoryId);
return {
content: [{ type: "text", text: JSON.stringify(repository, null, 2) }],
};
}
case "list_repositories": {
const args = types.ListRepositoriesSchema.parse(request.params.arguments);
const repositoryList = await repositories.listRepositoriesFunc(args.organizationId, args.page, args.perPage, args.orderBy, args.sort, args.search ?? undefined, args.archived);
return {
content: [{ type: "text", text: JSON.stringify(repositoryList, null, 2) }],
};
}
// Change Request Operations
case "get_change_request": {
const args = types.GetChangeRequestSchema.parse(request.params.arguments);
const changeRequest = await changeRequests.getChangeRequestFunc(args.organizationId, args.repositoryId, args.localId);
return {
content: [{ type: "text", text: JSON.stringify(changeRequest, null, 2) }],
};
}
case "list_change_requests": {
const args = types.ListChangeRequestsSchema.parse(request.params.arguments);
const changeRequestList = await changeRequests.listChangeRequestsFunc(args.organizationId, args.page, args.perPage, args.projectIds ?? undefined, args.authorIds ?? undefined, args.reviewerIds ?? undefined, args.state ?? undefined, args.search ?? undefined, args.orderBy, args.sort, args.createdBefore ?? undefined, args.createdAfter ?? undefined);
return {
content: [{ type: "text", text: JSON.stringify(changeRequestList, null, 2) }],
};
}
case "create_change_request": {
const args = types.CreateChangeRequestSchema.parse(request.params.arguments);
const changeRequest = await changeRequests.createChangeRequestFunc(args.organizationId, args.repositoryId, args.title, args.sourceBranch, args.targetBranch, args.description ?? undefined, args.sourceProjectId, args.targetProjectId, args.reviewerUserIds ?? undefined, args.workItemIds ?? undefined, args.createFrom);
return {
content: [{ type: "text", text: JSON.stringify(changeRequest, null, 2) }],
};
}
case "create_change_request_comment": {
const args = types.CreateChangeRequestCommentSchema.parse(request.params.arguments);
const comment = await changeRequestComments.createChangeRequestCommentFunc(args.organizationId, args.repositoryId, args.localId, args.comment_type, args.content, args.draft, args.resolved, args.patchset_biz_id, args.file_path ?? undefined, args.line_number ?? undefined, args.from_patchset_biz_id ?? undefined, args.to_patchset_biz_id ?? undefined, args.parent_comment_biz_id ?? undefined);
return {
content: [{ type: "text", text: JSON.stringify(comment, null, 2) }],
};
}
case "list_change_request_comments": {
const args = types.ListChangeRequestCommentsSchema.parse(request.params.arguments);
const comments = await changeRequestComments.listChangeRequestCommentsFunc(args.organizationId, args.repositoryId, args.localId, args.patchSetBizIds ?? undefined, args.commentType, args.state, args.resolved, args.filePath ?? undefined);
return {
content: [{ type: "text", text: JSON.stringify(comments, null, 2) }],
};
}
case "list_change_request_patch_sets": {
const args = types.ListChangeRequestPatchSetsSchema.parse(request.params.arguments);
const patchSets = await changeRequests.listChangeRequestPatchSetsFunc(args.organizationId, args.repositoryId, args.localId);
return {
content: [{ type: "text", text: JSON.stringify(patchSets, null, 2) }],
};
}
// Organization Operations
case "get_current_organization_info": {
const currentOrgInfo = await organization.getCurrentOrganizationInfoFunc();
return {
content: [{ type: "text", text: JSON.stringify(currentOrgInfo, null, 2) }],
};
}
case "get_user_organizations": {
const userOrgs = await organization.getUserOrganizationsFunc();
return {
content: [{ type: "text", text: JSON.stringify(userOrgs, null, 2) }],
};
}
case "get_current_user": {
const currentUserInfo = await organization.getCurrentUserFunc();
return {
content: [{ type: "text", text: JSON.stringify(currentUserInfo, null, 2) }],
};
}
case "list_organization_departments": {
const args = types.GetOrganizationDepartmentsSchema.parse(request.params.arguments);
const departments = await organization.getOrganizationDepartmentsFunc(args.organizationId, args.parentId ?? undefined);
return {
content: [{ type: "text", text: JSON.stringify(departments, null, 2) }],
};
}
case "get_organization_department_info": {
const args = types.GetOrganizationDepartmentInfoSchema.parse(request.params.arguments);
const departmentInfo = await organization.getOrganizationDepartmentInfoFunc(args.organizationId, args.id);
return {
content: [{ type: "text", text: JSON.stringify(departmentInfo, null, 2) }],
};
}
case "get_organization_department_ancestors": {
const args = types.GetOrganizationDepartmentAncestorsSchema.parse(request.params.arguments);
const ancestors = await organization.getOrganizationDepartmentAncestorsFunc(args.organizationId, args.id);
return {
content: [{ type: "text", text: JSON.stringify(ancestors, null, 2) }],
};
}
case "list_organization_members": {
const args = types.GetOrganizationMembersSchema.parse(request.params.arguments);
const orgMembers = await members.getOrganizationMembersFunc(args.organizationId, args.page ?? 1, args.perPage ?? 100);
return {
content: [{ type: "text", text: JSON.stringify(orgMembers, null, 2) }]
};
}
case "get_organization_member_info": {
const args = types.GetOrganizationMemberInfoSchema.parse(request.params.arguments);
const memberInfo = await members.getOrganizationMemberInfoFunc(args.organizationId, args.memberId);
return {
content: [{ type: "text", text: JSON.stringify(memberInfo, null, 2) }]
};
}
case "get_organization_member_info_by_user_id": {
const args = types.GetOrganizationMemberByUserIdInfoSchema.parse(request.params.arguments);
const memberInfo = await members.getOrganizationMemberByUserIdInfoFunc(args.organizationId, args.userId);
return {
content: [{ type: "text", text: JSON.stringify(memberInfo, null, 2) }]
};
}
case "search_organization_members": {
const args = types.SearchOrganizationMembersSchema.parse(request.params.arguments);
const membersResult = await members.searchOrganizationMembersFunc(args.organizationId, args.includeChildren ?? false, args.page ?? 1, args.perPage ?? 100, args.deptIds ?? undefined, args.nextToken ?? undefined, args.query ?? undefined, args.roleIds ?? undefined, args.statuses ?? undefined);
return {
content: [{ type: "text", text: JSON.stringify(membersResult, null, 2) }]
};
}
case "list_organization_roles": {
const args = types.ListOrganizationRolesSchema.parse(request.params.arguments);
const roles = await organization.listOrganizationRolesFunc(args.organizationId);
return {
content: [{ type: "text", text: JSON.stringify(roles, null, 2) }]
};
}
case "get_organization_role": {
const args = types.GetOrganizationRoleSchema.parse(request.params.arguments);
const role = await organization.getOrganizationRoleFunc(args.organizationId, args.roleId);
return {
content: [{ type: "text", text: JSON.stringify(role, null, 2) }]
};
}
// Project Operations
case "get_project": {
const args = types.GetProjectSchema.parse(request.params.arguments);
const projectInfo = await project.getProjectFunc(args.organizationId, args.id);
return {
content: [{ type: "text", text: JSON.stringify(projectInfo, null, 2) }],
};
}
case "search_projects": {
const args = types.SearchProjectsSchema.parse(request.params.arguments);
const projects = await project.searchProjectsFunc(args.organizationId, args.name ?? undefined, args.status ?? undefined, args.createdAfter ?? undefined, args.createdBefore ?? undefined, args.creator ?? undefined, args.adminUserId ?? undefined, args.logicalStatus ?? undefined, args.advancedConditions ?? undefined, args.extraConditions ?? undefined, args.orderBy, args.page, args.perPage, args.sort, args.scenarioFilter ?? undefined, args.userId ?? undefined);
return {
content: [{ type: "text", text: JSON.stringify(projects, null, 2) }],
};
}
// Sprint Operations
// case "get_sprint": {
// const args = sprint.GetSprintSchema.parse(request.params.arguments);
// const sprintInfo = await sprint.getSprintFunc(
// args.organizationId,
// args.projectId,
// args.id
// );
// return {
// content: [{ type: "text", text: JSON.stringify(sprintInfo, null, 2) }],
// };
// }
// case "list_sprints": {
// const args = sprint.ListSprintsSchema.parse(request.params.arguments);
// const sprints = await sprint.listSprintsFunc(
// args.organizationId,
// args.id,
// args.status,
// args.page,
// args.perPage
// );
// return {
// content: [{ type: "text", text: JSON.stringify(sprints, null, 2) }],
// };
// }
// Work Item Operations
case "get_work_item": {
const args = types.GetWorkItemSchema.parse(request.params.arguments);
const workItemInfo = await workitem.getWorkItemFunc(args.organizationId, args.workItemId);
return {
content: [{ type: "text", text: JSON.stringify(workItemInfo, null, 2) }],
};
}
case "create_work_item": {
const args = types.CreateWorkItemSchema.parse(request.params.arguments);
const workItemInfo = await workitem.createWorkItemFunc(args.organizationId, args.assignedTo, args.spaceId, args.subject, args.workitemTypeId, args.customFieldValues, args.description, args.labels, args.parentId, args.participants, args.sprint, args.trackers, args.verifier, args.versions);
return {
content: [{ type: "text", text: JSON.stringify(workItemInfo, null, 2) }],
};
}
case "search_workitems": {
const args = types.SearchWorkitemsSchema.parse(request.params.arguments);
const workItems = await workitem.searchWorkitemsFunc(args.organizationId, args.category, args.spaceId, args.subject ?? undefined, args.status ?? undefined, args.createdAfter ?? undefined, args.createdBefore ?? undefined, args.updatedAfter ?? undefined, args.updatedBefore ?? undefined, args.creator ?? undefined, args.assignedTo ?? undefined, args.advancedConditions ?? undefined, args.orderBy ?? "gmtCreate", args.includeDetails ?? false);
return {
content: [{ type: "text", text: JSON.stringify(workItems, null, 2) }],
};
}
case "get_work_item_types": {
const args = z.object({
organizationId: z.string().describe("organization id"),
id: z.string().describe("project id or space id"),
category: z.string().describe("Req、Task、Bug etc.")
}).parse(request.params.arguments);
const workItemTypes = await workitem.getWorkItemTypesFunc(args.organizationId, args.id, args.category);
return {
content: [{ type: "text", text: JSON.stringify(workItemTypes, null, 2) }],
};
}
// Pipeline Operations
case "get_pipeline": {
const args = types.GetPipelineSchema.parse(request.params.arguments);
const pipelineInfo = await pipeline.getPipelineFunc(args.organizationId, args.pipelineId);
return {
content: [{ type: "text", text: JSON.stringify(pipelineInfo, null, 2) }],
};
}
case "list_pipelines": {
const args = types.ListPipelinesSchema.parse(request.params.arguments);
const pipelines = await pipeline.listPipelinesFunc(args.organizationId, {
createStartTime: args.createStartTime,
createEndTime: args.createEndTime,
executeStartTime: args.executeStartTime,
executeEndTime: args.executeEndTime,
pipelineName: args.pipelineName,
statusList: args.statusList,
perPage: args.perPage,
page: args.page
});
return {
content: [{ type: "text", text: JSON.stringify(pipelines, null, 2) }],
};
}
case "generate_pipeline_yaml": {
try {
const args = types.CreatePipelineFromDescriptionSchema.parse(request.params.arguments);
// 检查必需的参数
if (!args.buildLanguage) {
throw new Error("The build language parameter is missing.");
}
if (!args.buildTool) {
throw new Error("The build tool parameter is missing.");
}
const yamlContent = await pipeline.generatePipelineYamlFunc({
buildLanguage: args.buildLanguage,
buildTool: args.buildTool,
deployTarget: args.deployTarget,
// Repository configuration
repoUrl: args.repoUrl,
branch: args.branch,
serviceName: args.serviceName,
serviceConnectionId: args.serviceConnectionId,
// Version configuration
jdkVersion: args.jdkVersion,
mavenVersion: args.mavenVersion,
nodeVersion: args.nodeVersion,
pythonVersion: args.pythonVersion,
goVersion: args.goVersion,
// Build configuration
buildCommand: args.buildCommand,
testCommand: args.testCommand,
// Artifac