UNPKG

rework-mcp-server

Version:

Rework MCP Server - Integrate rework tasks with AI through Model Context Protocol

162 lines (161 loc) 4.97 kB
/** * Rework API Fetcher utility * * A reusable utility for making API calls to the Rework API with shared credentials */ import axios from 'axios'; import qs from 'qs'; import config from '../../config.js'; export class ReworkFetcher { constructor() { this.baseUrl = 'https://apis.rework.com'; this.accessToken = config.reworkProjectAccessToken; this.password = config.reworkProjectPassword; if (!this.accessToken || !this.password) { throw new Error('Rework API credentials not found in configuration'); } } /** * Make a request to the Rework API * * @param options Request options * @returns Promise with the API response */ async request(options) { const { endpoint, method = 'post', params = {}, data = {}, headers = {}, includeAuth = true } = options; // Add authentication to data if needed const requestData = { ...data }; if (includeAuth) { requestData.access_token = this.accessToken; requestData.password = this.password; } const requestConfig = { method, url: `${this.baseUrl}${endpoint}`, headers: { 'Content-Type': 'application/x-www-form-urlencoded', ...headers }, params, data: qs.stringify(requestData), maxBodyLength: Infinity }; try { const response = await axios.request(requestConfig); return response.data; } catch (error) { if (axios.isAxiosError(error) && error.response) { throw new Error(`Rework API Error (${error.response.status}): ${JSON.stringify(error.response.data)}`); } throw error; } } /** * List tasks with optional filters * * @param boardId Board ID * @param options Additional options like deadline_from, etc. * @returns Promise with the task list response */ async listTasks(boardId, options = {}) { return this.request({ endpoint: '/projects/v1/task/list', data: { board_id: boardId, ...options } }); } /** * Create a new task * * @param taskData Task data including board_id and name * @returns Promise with the created task */ async createTask(taskData) { return this.request({ endpoint: '/projects/v1/task/create', data: taskData }); } /** * Update an existing task * * @param taskId Task ID * @param taskData Task data to update * @returns Promise with the updated task */ async updateTask(taskId, taskData) { return this.request({ endpoint: '/projects/v1/task/update', data: { task_id: taskId, ...taskData } }); } /** * Get task details * * @param taskId Task ID * @returns Promise with the task details */ async getTask(taskId) { return this.request({ endpoint: '/projects/v1/task/get', data: { task_id: taskId } }); } /** * Generic method to make any API call to Rework * * @param endpoint API endpoint (e.g., '/projects/v1/task/list') * @param data Request data * @returns Promise with the API response */ async call(endpoint, data = {}) { return this.request({ endpoint, data }); } } /** * ReworkAccountFetcher utility * * Similar to ReworkFetcher but uses account credentials instead of project credentials */ export class ReworkAccountFetcher extends ReworkFetcher { constructor() { super(); this.accessToken = config.reworkAccountAccessToken; this.password = config.reworkAccountPassword; if (!this.accessToken || !this.password) { throw new Error('Rework Account API credentials not found in configuration'); } } } /** * ReworkWorkflowFetcher utility * * Similar to ReworkFetcher but uses account credentials instead of project credentials */ export class ReworkWorkflowFetcher extends ReworkFetcher { constructor() { super(); this.accessToken = config.reworkWorkflowAccessToken; this.password = config.reworkWorkflowPassword; if (!this.accessToken || !this.password) { throw new Error('Rework Workflow API credentials not found in configuration'); } } } // Export singleton instances for easy import and use export const reworkProjectFetcher = new ReworkFetcher(); export const reworkWorkflowFetcher = new ReworkWorkflowFetcher(); export const reworkAccountFetcher = new ReworkAccountFetcher(); // Export default for convenience export default reworkProjectFetcher;