@mcp-apps/azure-devops-mcp-server
Version:
A Model Context Protocol (MCP) server for Azure DevOps integration
115 lines (113 loc) • 5.51 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.cloneRepositoryTool = void 0;
const zod_1 = require("zod");
const azure_devops_client_1 = require("../utils/azure-devops-client");
const child_process = __importStar(require("child_process"));
const util = __importStar(require("util"));
const execPromise = util.promisify(child_process.exec);
// Tool to clone a repository
exports.cloneRepositoryTool = {
name: "git-clone-repository",
description: `
Clones an Azure DevOps Git repository to a local directory.
This tool clones the specified repository from Azure DevOps to a local directory,
allowing you to work with the code locally.
Parameters:
- organizationUrl: The Azure DevOps organization URL in the format https://dev.azure.com/{organization}
Example: https://dev.azure.com/fabrikam
- project: The exact name of the Azure DevOps project containing the repository
Example: "FabrikamFiber"
- repositoryName: The exact name of the Git repository to clone
Example: "FabrikamFiber-Web"
- localPath: The local path where the repository should be cloned
Example: "C:\\projects\\my-repo" or "/home/user/projects/my-repo"
- branch: Optional branch name to check out after cloning (default: repository's default branch)
Example: "main", "develop", "feature/new-feature"
`,
parameters: {
organizationUrl: zod_1.z.string().describe("Azure DevOps organization URL (e.g., https://dev.azure.com/organization)"),
project: zod_1.z.string().describe("Project name"),
repositoryName: zod_1.z.string().describe("Repository name"),
localPath: zod_1.z.string().describe("Local path where the repository should be cloned"),
branch: zod_1.z.string().optional().describe("Branch name to check out (default: repository's default branch)"),
},
handler: async ({ organizationUrl, project, repositoryName, localPath, branch }) => {
try {
const gitApi = await (0, azure_devops_client_1.getGitApi)(organizationUrl);
// Get the repository
const repositories = await gitApi.getRepositories(project);
const repository = repositories.find((repo) => repo.name && repo.name.toLowerCase() === repositoryName.toLowerCase());
if (!repository || !repository.webUrl) {
return {
content: [{ type: "text", text: `Repository "${repositoryName}" not found in project "${project}".` }],
};
}
// Construct clone URL (HTTPS)
const cloneUrl = repository.webUrl;
// Build the clone command
let cloneCommand = `git clone "${cloneUrl}" "${localPath}"`;
if (branch) {
cloneCommand += ` --branch "${branch}"`;
}
// Execute the clone command
const { stdout, stderr } = await execPromise(cloneCommand);
if (stderr && !stderr.includes("Cloning into")) {
// Git sends progress info to stderr, so we need to check if it contains real errors
return {
content: [{
type: "text",
text: `Warning during clone:\n${stderr}\n\nRepository was cloned to ${localPath}`
}],
};
}
return {
content: [{
type: "text",
text: `Repository "${repositoryName}" successfully cloned to "${localPath}"${branch ? ` with branch "${branch}" checked out` : ''}.`
}],
};
}
catch (error) {
console.error("Error cloning repository:", error);
const errorMessage = error instanceof Error ? error.message : String(error);
return {
content: [{ type: "text", text: `Error cloning repository: ${errorMessage}` }],
};
}
}
};
//# sourceMappingURL=git-clone-repository.js.map