@ryancardin/azuredevops-mcp-server
Version:
MCP server for Azure DevOps integration - provides seamless access to work items, repositories, projects, boards, and sprints
149 lines • 6.23 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAzureDevOpsConfig = getAzureDevOpsConfig;
exports.getAllowedTools = getAllowedTools;
const dotenv_1 = __importDefault(require("dotenv"));
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
const AIAssistedDevelopmentTools_1 = require("./Tools/AIAssistedDevelopmentTools");
const ArtifactManagementTools_1 = require("./Tools/ArtifactManagementTools");
const BoardsSprintsTools_1 = require("./Tools/BoardsSprintsTools");
const DevSecOpsTools_1 = require("./Tools/DevSecOpsTools");
const GitTools_1 = require("./Tools/GitTools");
const ProjectTools_1 = require("./Tools/ProjectTools");
const TestingCapabilitiesTools_1 = require("./Tools/TestingCapabilitiesTools");
const WorkItemTools_1 = require("./Tools/WorkItemTools");
// Try to load environment variables from .env file with multiple possible locations
function loadEnvFile() {
// First try the current directory
if (fs_1.default.existsSync('.env')) {
dotenv_1.default.config();
return;
}
// Try the directory of the running script
const scriptDir = __dirname;
const envPath = path_1.default.join(scriptDir, '..', '.env');
if (fs_1.default.existsSync(envPath)) {
dotenv_1.default.config({ path: envPath });
return;
}
// If we still haven't loaded env vars, try a few other common locations
const possiblePaths = [
// One level above the dist directory
path_1.default.join(process.cwd(), '.env'),
// User's home directory
path_1.default.join(process.env.HOME || '', '.azuredevops.env')
];
for (const p of possiblePaths) {
if (fs_1.default.existsSync(p)) {
dotenv_1.default.config({ path: p });
return;
}
}
}
// Load environment variables
loadEnvFile();
/**
* Get Azure DevOps configuration from environment variables
*/
function getAzureDevOpsConfig() {
const orgUrl = process.env.AZURE_DEVOPS_ORG_URL;
const project = process.env.AZURE_DEVOPS_PROJECT;
const personalAccessToken = process.env.AZURE_DEVOPS_PERSONAL_ACCESS_TOKEN || '';
const isOnPremises = process.env.AZURE_DEVOPS_IS_ON_PREMISES === 'true';
const collection = process.env.AZURE_DEVOPS_COLLECTION;
const apiVersion = process.env.AZURE_DEVOPS_API_VERSION;
// Basic validation
if (!orgUrl || !project) {
throw new Error('Missing required Azure DevOps configuration. Please check .env file or environment variables.');
}
// Authentication configuration
const authTypeInput = process.env.AZURE_DEVOPS_AUTH_TYPE || 'pat';
const authType = (authTypeInput === 'ntlm' || authTypeInput === 'basic' || authTypeInput === 'pat' || authTypeInput === 'entra')
? authTypeInput
: 'pat';
let auth;
if (authType === 'entra') {
if (isOnPremises) {
throw new Error('Azure Identity (DefaultAzureCredential) authentication is not supported for on-premises Azure DevOps.');
}
auth = { type: 'entra' };
}
else if (isOnPremises) {
switch (authType) {
case 'ntlm':
if (!process.env.AZURE_DEVOPS_USERNAME || !process.env.AZURE_DEVOPS_PASSWORD) {
throw new Error('NTLM authentication requires username and password.');
}
auth = {
type: 'ntlm',
username: process.env.AZURE_DEVOPS_USERNAME,
password: process.env.AZURE_DEVOPS_PASSWORD,
domain: process.env.AZURE_DEVOPS_DOMAIN
};
break;
case 'basic':
if (!process.env.AZURE_DEVOPS_USERNAME || !process.env.AZURE_DEVOPS_PASSWORD) {
throw new Error('Basic authentication requires username and password.');
}
auth = {
type: 'basic',
username: process.env.AZURE_DEVOPS_USERNAME,
password: process.env.AZURE_DEVOPS_PASSWORD
};
break;
case 'pat':
default:
if (!personalAccessToken) {
throw new Error('PAT authentication requires a personal access token.');
}
auth = {
type: 'pat'
};
}
}
else { // Cloud environment
if (authType === 'pat') {
if (!personalAccessToken) {
throw new Error('PAT authentication requires a personal access token for Azure DevOps cloud unless AZURE_DEVOPS_AUTH_TYPE is set to entra.');
}
auth = { type: 'pat' };
}
else { // If not 'pat' and not 'entra' (already handled), then it's an unsupported type for cloud
throw new Error(`Unsupported auth type "${authType}" for Azure DevOps cloud. Must be 'pat' or 'entra'.`);
}
}
return {
orgUrl,
project,
personalAccessToken,
isOnPremises,
collection,
apiVersion,
...(auth && { auth })
};
}
const ALL_ALLOWED_TOOLS = AIAssistedDevelopmentTools_1.AIAssistedDevelopmentToolMethods
.concat(ArtifactManagementTools_1.ArtifactManagementToolMethods)
.concat(BoardsSprintsTools_1.BoardsSprintsToolMethods)
.concat(DevSecOpsTools_1.DevSecOpsToolMethods)
.concat(GitTools_1.GitToolMethods)
.concat(ProjectTools_1.ProjectToolMethods)
.concat(TestingCapabilitiesTools_1.TestingCapabilitiesToolMethods)
.concat(WorkItemTools_1.WorkItemToolMethods);
/**
* Get allowed tools from `process.env.ALLOWED_TOOLS`.
*
* For backward compatibility, if `process.env.ALLOWED_TOOLS` is `undefined`, all tools are allowed.
*/
function getAllowedTools() {
const ALLOWED_TOOLS = process.env.ALLOWED_TOOLS;
if (!ALLOWED_TOOLS)
return new Set(ALL_ALLOWED_TOOLS);
const allowedTools = ALLOWED_TOOLS.split(',');
return new Set(allowedTools);
}
//# sourceMappingURL=config.js.map