minimal-my-items-server
Version:
Minimal Monday.com My Items MCP Server
97 lines (96 loc) • 3.79 kB
JavaScript
;
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.addTask = addTask;
const mondayClient_1 = require("../utils/mondayClient");
/**
* Adds a new task (item) to a Monday.com board.
* @param boardId - The board ID to add the item to.
* @param groupId - The group ID to add the item to.
* @param itemName - The name of the new item.
* @param columnValues - Optional object mapping column IDs to values.
* @returns An object with a 'content' array containing a text result.
*/
function addTask(_a) {
return __awaiter(this, arguments, void 0, function* ({ boardId, groupId, itemName, columnValues = {}, }) {
// Auto-assign task to current user
try {
// Get current user ID
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." },
],
};
}
const userId = me.id;
// For the people column, using the simple format with just the user ID as a string
// This is the most reliable format according to Monday.com API documentation
columnValues.task_owner = userId.toString();
}
catch (error) {
console.error("Error setting up task owner assignment:", error);
// Continue with item creation even if user assignment fails
}
const mutation = `
mutation ($boardId: ID!, $groupId: String!, $itemName: String!, $columnValues: JSON) {
create_item(
board_id: $boardId,
group_id: $groupId,
item_name: $itemName,
column_values: $columnValues
) {
id
name
}
}
`;
try {
const variables = {
boardId: Number(boardId),
groupId,
itemName,
columnValues: Object.keys(columnValues).length
? JSON.stringify(columnValues)
: null,
};
const data = yield (0, mondayClient_1.mondayGraphQL)(mutation, variables);
const item = data.create_item;
if (!item || !item.id) {
return {
content: [
{ type: "text", text: "Failed to create item on the board." },
],
};
}
return {
content: [
{
type: "text",
text: `Created item '${item.name}' (ID: ${item.id}) on board ${boardId}.`,
},
],
};
}
catch (error) {
return {
content: [
{
type: "text",
text: `Error creating item: ${error.message || error}`,
},
],
};
}
});
}