UNPKG

minimal-my-items-server

Version:

Minimal Monday.com My Items MCP Server

118 lines (117 loc) 4.83 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getMyItems = getMyItems; const mondayClient_1 = require("../utils/mondayClient"); /** * Gets items assigned to a user for a specific Monday.com board. * @param boardId - The board ID to fetch items from. * @param limit - Maximum number of items to return (default 25) * @param userIdOverride - Optionally override the user ID (for testing) * @returns An object with a 'content' array containing a text result. */ function getMyItems(_a) { return __awaiter(this, arguments, void 0, function* ({ boardId, limit = 25, userIdOverride, }) { var _b; // 1. Get current user ID (unless overridden) let userId = userIdOverride; if (!userId) { const meQuery = `query { me { id } }`; const { me } = yield (0, mondayClient_1.mondayGraphQL)(meQuery, {}); if (!me || !me.id) { return { content: [ { type: "text", text: "Could not determine current user ID." }, ], }; } userId = me.id; } // 2. Get people/person column ID const columnsQuery = `query ($boardId: [ID!]) { boards(ids: $boardId) { columns { id title type } } }`; const { boards } = yield (0, mondayClient_1.mondayGraphQL)(columnsQuery, { boardId: [Number(boardId)], }); if (!boards || !boards[0] || !boards[0].columns) { return { content: [ { type: "text", text: `Could not fetch columns for board ${boardId}.`, }, ], }; } const peopleColumn = boards[0].columns.find((col) => col.type === "people" || col.type === "person"); if (!peopleColumn) { return { content: [ { type: "text", text: `No people/person column found on board ${boardId}.`, }, ], }; } const peopleColumnId = peopleColumn.id; // 3. Query items assigned to the user using items_page_by_column_values const itemsQuery = ` query ($boardId: ID!, $columnId: String!, $userId: String!, $limit: Int) { items_page_by_column_values( board_id: $boardId, columns: [ { column_id: $columnId, column_values: [$userId] } ], limit: $limit ) { items { id name column_values { id type value text } } } } `; const data = yield (0, mondayClient_1.mondayGraphQL)(itemsQuery, { boardId: String(boardId), columnId: peopleColumnId, userId: String(userId), limit, }); const items = ((_b = data.items_page_by_column_values) === null || _b === void 0 ? void 0 : _b.items) || []; // For each item, fetch description if needed const results = yield Promise.all(items.map((i) => __awaiter(this, void 0, void 0, function* () { var _a; const status = ((_a = i.column_values.find((c) => c.id === "task_status")) === null || _a === void 0 ? void 0 : _a.text) || ""; let aiDescription = ""; const aiDescCol = i.column_values.find((c) => c.id === "long_text_mkqr330y"); if (aiDescCol && aiDescCol.text && aiDescCol.text.trim()) { aiDescription = aiDescCol.text.trim(); } return `- ${i.name} (ID: ${i.id})\n Status: ${status}${aiDescription ? `\n AI Description: ${aiDescription}` : ""}`; }))); return { content: [ { type: "text", text: results.length ? results.join("\n\n") : `No items assigned to you found on board ${boardId}.`, }, ], }; }); }