@ryancardin/azuredevops-mcp-server
Version:
MCP server for Azure DevOps integration - provides seamless access to work items, repositories, projects, boards, and sprints
137 lines • 6.18 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.AzureDevOpsService = void 0;
const azdev = __importStar(require("azure-devops-node-api"));
const WebApi_1 = require("azure-devops-node-api/WebApi");
class AzureDevOpsService {
constructor(config) {
this.config = config;
// Get the appropriate authentication handler
if (config.auth?.type === "entra") {
if (config.isOnPremises) {
throw new Error("Azure Identity (DefaultAzureCredential) authentication is not supported for on-premises Azure DevOps.");
}
if (!config.entraAuthHandler) {
throw new Error("Entra authentication requires an instance of EntraAuthHandler.");
}
this.authHandler = config.entraAuthHandler;
}
else if (config.isOnPremises && config.auth) {
switch (config.auth.type) {
case 'ntlm':
if (!config.auth.username || !config.auth.password) {
throw new Error("NTLM authentication requires username and password");
}
this.authHandler = (0, WebApi_1.getNtlmHandler)(config.auth.username, config.auth.password, config.auth.domain);
break;
case 'basic':
if (!config.auth.username || !config.auth.password) {
throw new Error("Basic authentication requires username and password");
}
this.authHandler = (0, WebApi_1.getBasicHandler)(config.auth.username, config.auth.password);
break;
case 'pat':
default: // Default to PAT for on-premises if auth type is missing or unrecognized
if (!config.personalAccessToken) {
throw new Error("PAT authentication requires a personal access token for on-premises if specified or as fallback.");
}
this.authHandler = (0, WebApi_1.getPersonalAccessTokenHandler)(config.personalAccessToken);
}
}
else {
// Cloud environment, and not 'entra'
if (config.auth?.type === "pat" || !config.auth) {
// Explicitly PAT or no auth specified (defaults to PAT for cloud)
if (!config.personalAccessToken) {
throw new Error("Personal Access Token is required for cloud authentication when auth type is PAT or not specified.");
}
this.authHandler = (0, WebApi_1.getPersonalAccessTokenHandler)(config.personalAccessToken);
}
else {
// This case should ideally not be reached if config is validated correctly
throw new Error(`Unsupported authentication type "${config.auth?.type}" for Azure DevOps cloud.`);
}
}
// Create the connection with the appropriate base URL
let baseUrl = config.orgUrl;
if (config.isOnPremises && config.collection) {
// For on-premises, ensure the collection is included in the URL
baseUrl = `${config.orgUrl}/${config.collection}`;
}
// Create options for the WebApi
const requestOptions = {};
// For on-premises with API version specification, we'll add it to request headers
if (config.isOnPremises && config.apiVersion) {
requestOptions.headers = {
Accept: `application/json;api-version=${config.apiVersion}`,
};
}
// Create the WebApi instance
// At this point, authHandler is guaranteed to be defined or an error would have been thrown.
this.connection = new azdev.WebApi(baseUrl, this.authHandler, requestOptions);
}
/**
* Get the WorkItemTracking API client
*/
async getWorkItemTrackingApi() {
return await this.connection.getWorkItemTrackingApi();
}
/**
* List work items based on a WIQL query
*/
async listWorkItems(wiqlQuery) {
try {
const witApi = await this.getWorkItemTrackingApi();
// Execute the WIQL query
const queryResult = await witApi.queryByWiql({
query: wiqlQuery,
}, {
project: this.config.project,
});
// Return the work items
return {
workItems: queryResult.workItems || [],
count: queryResult.workItems?.length || 0,
};
}
catch (error) {
console.error("Error listing work items:", error);
throw error;
}
}
}
exports.AzureDevOpsService = AzureDevOpsService;
//# sourceMappingURL=AzureDevOpsService.js.map