@pavi_thran_7/jira-mcp-server
Version:
MCP server for Jira integration with ticket creation and time logging
118 lines (104 loc) • 2.94 kB
JavaScript
/**
* @fileoverview Configuration tool for Jira MCP server
*/
import { JiraClient } from '../jira-client.js';
import { setJiraClient } from '../index.js';
/**
* @typedef {import('../types/jira.js').JiraConfig} JiraConfig
* @typedef {import('../types/jira.js').McpToolResult} McpToolResult
*/
/**
* Configure Jira connection with credentials
* @param {JiraConfig} config - Jira configuration
* @returns {Promise<McpToolResult>} Configuration result
*/
export async function configureJira(config) {
try {
// Validate required parameters
if (!config.baseUrl || !config.email || !config.apiToken) {
return {
content: [
{
type: 'text',
text: 'Error: Missing required parameters. Please provide baseUrl, email, and apiToken.',
},
],
isError: true,
};
}
// Validate base URL format
try {
new URL(config.baseUrl);
} catch {
return {
content: [
{
type: 'text',
text: 'Error: Invalid baseUrl format. Please provide a valid URL (e.g., https://company.atlassian.net).',
},
],
isError: true,
};
}
// Validate email format
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(config.email)) {
return {
content: [
{
type: 'text',
text: 'Error: Invalid email format. Please provide a valid email address.',
},
],
isError: true,
};
}
// Create Jira client
const jiraClient = new JiraClient({
baseUrl: config.baseUrl.replace(/\/$/, ''), // Remove trailing slash
email: config.email,
apiToken: config.apiToken,
});
// Test authentication
const authResult = await jiraClient.testAuth();
if (!authResult.success) {
return {
content: [
{
type: 'text',
text: `Authentication failed: ${authResult.error}`,
},
],
isError: true,
};
}
// Set global client instance
setJiraClient(jiraClient);
// Get user info for confirmation
const userInfo = authResult.data;
return {
content: [
{
type: 'text',
text: `✅ Successfully configured Jira connection!
**Connection Details:**
- Base URL: ${config.baseUrl}
- User: ${userInfo.displayName} (${userInfo.emailAddress})
- Account ID: ${userInfo.accountId}
You can now use other Jira tools like create_ticket, log_work, list_projects, etc.`,
},
],
isError: false,
};
} catch (error) {
return {
content: [
{
type: 'text',
text: `Error configuring Jira: ${error.message}`,
},
],
isError: true,
};
}
}