UNPKG

@edicarlos.lds/businessmap-mcp

Version:

Model Context Protocol server for BusinessMap (Kanbanize) integration

308 lines 11.3 kB
import axios from 'axios'; import { BoardClient, CardClient, CustomFieldClient, UserClient, UtilityClient, WorkflowClient, WorkspaceClient, } from './modules/index.js'; export class BusinessMapClient { http; config; isInitialized = false; // Client modules workspaceClient; boardClient; cardClient; userClient; customFieldClient; utilityClient; workflowClient; constructor(config) { this.config = config; this.http = axios.create({ baseURL: config.apiUrl, headers: { apikey: config.apiToken, 'Content-Type': 'application/json', Accept: 'application/json', }, timeout: 30000, }); // Add response interceptor for error handling this.http.interceptors.response.use((response) => response, (error) => { throw this.transformError(error); }); // Initialize client modules this.workspaceClient = new WorkspaceClient(); this.boardClient = new BoardClient(); this.cardClient = new CardClient(); this.userClient = new UserClient(); this.customFieldClient = new CustomFieldClient(); this.utilityClient = new UtilityClient(); this.workflowClient = new WorkflowClient(); // Initialize all modules with http client and config [ this.workspaceClient, this.boardClient, this.cardClient, this.userClient, this.customFieldClient, this.utilityClient, this.workflowClient, ].forEach((module) => { module.initialize(this.http, this.config); }); } /** * Initialize the client by verifying the connection to the BusinessMap API */ async initialize() { if (this.isInitialized) { return; } try { // Verify configuration first if (!this.config.apiUrl) { throw new Error('API URL is not configured. Please set BUSINESSMAP_API_URL environment variable.'); } if (!this.config.apiToken) { throw new Error('API Token is not configured. Please set BUSINESSMAP_API_TOKEN environment variable.'); } // Try to perform a health check first const isHealthy = await this.utilityClient.healthCheck(); if (!isHealthy) { throw new Error('API connection failed - please check your API URL and token'); } // Try to fetch API info to verify authentication try { await this.utilityClient.getApiInfo(); } catch (error) { if (error instanceof Error && error.message.includes('401')) { throw new Error('Authentication failed - please verify your API token has the correct permissions'); } throw new Error(`API verification failed: ${error instanceof Error ? error.message : 'Unknown error'}`); } this.isInitialized = true; } catch (error) { const message = error instanceof Error ? error.message : 'Unknown error'; throw new Error(`Failed to initialize BusinessMap client: ${message}`); } } /** * Check if the client has been initialized */ get initialized() { return this.isInitialized; } transformError(error) { if (error.response) { const data = error.response.data; const apiMessage = data !== null && typeof data === 'object' && 'error' in data && data.error !== null && typeof data.error === 'object' && 'message' in data.error && typeof data.error.message === 'string' ? data.error.message : null; return new Error(`BusinessMap API Error: ${apiMessage ?? error.message}`); } return new Error(`Network Error: ${error.message}`); } // Workspace Management - Delegated to WorkspaceClient async getWorkspaces() { return this.workspaceClient.getWorkspaces(); } async getWorkspace(workspaceId) { return this.workspaceClient.getWorkspace(workspaceId); } async createWorkspace(params) { return this.workspaceClient.createWorkspace(params); } async updateWorkspace(workspaceId, params) { return this.workspaceClient.updateWorkspace(workspaceId, params); } async deleteWorkspace(workspaceId) { return this.workspaceClient.deleteWorkspace(workspaceId); } // Board Management - Delegated to BoardClient async getBoards(filters) { return this.boardClient.getBoards(filters); } async getBoard(boardId) { return this.boardClient.getBoard(boardId); } async createBoard(params) { return this.boardClient.createBoard(params); } async updateBoard(boardId, params) { return this.boardClient.updateBoard(boardId, params); } async deleteBoard(boardId) { return this.boardClient.deleteBoard(boardId); } async getBoardStructure(boardId) { return this.boardClient.getBoardStructure(boardId); } async getColumns(boardId) { return this.boardClient.getColumns(boardId); } async getLanes(boardId) { return this.boardClient.getLanes(boardId); } async getLane(laneId) { return this.boardClient.getLane(laneId); } async createLane(params) { return this.boardClient.createLane(params); } async getCurrentBoardStructure(boardId) { return this.boardClient.getCurrentBoardStructure(boardId); } async createColumn(boardId, params) { return this.boardClient.createColumn(boardId, params); } async updateColumn(boardId, columnId, params) { return this.boardClient.updateColumn(boardId, columnId, params); } async deleteColumn(boardId, columnId) { return this.boardClient.deleteColumn(boardId, columnId); } // Card Management - Delegated to CardClient async getCards(boardId, filters) { return this.cardClient.getCards(boardId, filters); } async getCard(cardId) { return this.cardClient.getCard(cardId); } async createCard(params) { return this.cardClient.createCard(params); } async updateCard(params) { return this.cardClient.updateCard(params); } async moveCard(cardId, columnId, laneId, position) { return this.cardClient.moveCard(cardId, columnId, laneId, position); } async deleteCard(cardId) { return this.cardClient.deleteCard(cardId); } async getCardComments(cardId) { return this.cardClient.getCardComments(cardId); } async getCardComment(cardId, commentId) { return this.cardClient.getCardComment(cardId, commentId); } async getCardCustomFields(cardId) { return this.cardClient.getCardCustomFields(cardId); } async getCardTypes() { return this.cardClient.getCardTypes(); } async getCardHistory(cardId, outcomeId) { return this.cardClient.getCardHistory(cardId, outcomeId); } async getCardOutcomes(cardId) { return this.cardClient.getCardOutcomes(cardId); } async getCardLinkedCards(cardId) { return this.cardClient.getCardLinkedCards(cardId); } async getCardSubtasks(cardId) { return this.cardClient.getCardSubtasks(cardId); } async getCardSubtask(cardId, subtaskId) { return this.cardClient.getCardSubtask(cardId, subtaskId); } async createCardSubtask(cardId, params) { return this.cardClient.createCardSubtask(cardId, params); } async getCardParents(cardId) { return this.cardClient.getCardParents(cardId); } async getCardParent(cardId, parentCardId) { return this.cardClient.getCardParent(cardId, parentCardId); } async addCardParent(cardId, parentCardId) { return this.cardClient.addCardParent(cardId, parentCardId); } async removeCardParent(cardId, parentCardId) { return this.cardClient.removeCardParent(cardId, parentCardId); } async getCardParentGraph(cardId) { return this.cardClient.getCardParentGraph(cardId); } async getCardChildren(cardId) { return this.cardClient.getCardChildren(cardId); } // Block / Unblock - Delegated to CardClient async blockCard(cardId, reason) { return this.cardClient.blockCard(cardId, reason); } async unblockCard(cardId) { return this.cardClient.unblockCard(cardId); } // Comments - Delegated to CardClient async createCardComment(cardId, params) { return this.cardClient.createCardComment(cardId, params); } async updateCardComment(cardId, commentId, params) { return this.cardClient.updateCardComment(cardId, commentId, params); } async deleteCardComment(cardId, commentId) { return this.cardClient.deleteCardComment(cardId, commentId); } // Tags - Delegated to CardClient async createTag(params) { return this.cardClient.createTag(params); } async addTagToCard(cardId, tagId) { return this.cardClient.addTagToCard(cardId, tagId); } async removeTagFromCard(cardId, tagId) { return this.cardClient.removeTagFromCard(cardId, tagId); } // Stickers - Delegated to CardClient async addStickerToCard(cardId, stickerId) { return this.cardClient.addStickerToCard(cardId, stickerId); } async removeStickerFromCard(cardId, stickerCardId) { return this.cardClient.removeStickerFromCard(cardId, stickerCardId); } async addPredecessor(cardId, predecessorCardId, params) { return this.cardClient.addPredecessor(cardId, predecessorCardId, params); } async removePredecessor(cardId, predecessorCardId) { return this.cardClient.removePredecessor(cardId, predecessorCardId); } // User Management - Delegated to UserClient async getUsers() { return this.userClient.getUsers(); } async getUser(userId) { return this.userClient.getUser(userId); } async getCurrentUser() { return this.userClient.getCurrentUser(); } async inviteUser(params) { return this.userClient.inviteUser(params); } // Custom Fields - Delegated to CustomFieldClient async getCustomField(customFieldId) { return this.customFieldClient.getCustomField(customFieldId); } // Workflow Management - Delegated to WorkflowClient async getWorkflowCycleTimeColumns(boardId, workflowId) { return this.workflowClient.getWorkflowCycleTimeColumns(boardId, workflowId); } async getWorkflowEffectiveCycleTimeColumns(boardId, workflowId) { return this.workflowClient.getWorkflowEffectiveCycleTimeColumns(boardId, workflowId); } // Utility Methods - Delegated to UtilityClient async healthCheck() { return this.utilityClient.healthCheck(); } async getApiInfo() { return this.utilityClient.getApiInfo(); } } //# sourceMappingURL=businessmap-client.js.map