Skip to main content
Glama
mrchris2000

MCP DevOps Plan Server

by mrchris2000

get_work_items

Retrieve work items for applications and projects, with options to filter by work item type or specific owner.

Instructions

Retrieves all work items for a given application, can filter by work item type and specific owner

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
applicationNameYesName of the application
projectNameYesName of the project
workitemTypeNoType of the work item to filter by, if any
ownerNoFilter the workitems by owner, if any

Implementation Reference

  • Implementation of the "get_work_items" tool. It retrieves work items from a given Plan application, filtered by project, optional work item type, and optional owner. It performs a POST query to get a result set and then a GET request to retrieve the items.
    server.tool(
        "get_work_items",
        "Retrieves all work items for a given application, can filter by work item type and specific owner",
        {
            applicationName: z.string().describe("Name of the application"),
            projectId: z.string().describe("ID of the project"),
            workitemType: z.string().optional().describe("Type of the work item to filter by, if any"),
            owner: z.string().optional().describe("Filter the workitems by owner, if any")
        },
        async ({ applicationName, projectId, workitemType, owner }) => {
            try {
                if (!globalCookies) {
                    globalCookies = await getCookiesFromServer(serverURL);
                    if (!globalCookies) {
                        console.error("Failed to retrieve cookies from server.");
                        return { error: "Failed to retrieve cookies." };
                    }
                    console.log("Received Cookies:", globalCookies); // Print cookies after receiving
                } else {
                    console.log("Reusing Stored Cookies:", globalCookies); // Print when reusing stored cookies
                }
                console.log(`${serverURL}/ccmweb/rest/repos/${teamspaceID}/databases/${applicationName}/query`);
                // First API call to get result_set_id
                const queryPayload = {
                    queryDef: {
                        primaryEntityDefName: "WorkItem",
                        stateDriven: true,
                        showWipLimits: true,
                        backlogStateName:"Backlog",
                        laneQueryDef: {
                            pageCounterQueryField: "State",
                            pageCounterQueryFieldPath: "State",
                            wipLimitFilterQueryField: "Project"
                        },
                        primaryEntityDefName: "WorkItem",
                        queryFieldDefs: [
                            { fieldPathName: "dbid", isShown: true },
                            { fieldPathName: "State", isShown: true },
                            { fieldPathName: "id", isShown: true },
                            { fieldPathName: "Title", isShown: true },
                            { fieldPathName: "Owner.fullname", isShown: true },
                            { fieldPathName: "Owner", isShown: true },
                            { fieldPathName: "Priority", isShown: true },
                            { fieldPathName: "Parent.Title", isShown: true },
                            { fieldPathName: "Parent", isShown: true },
                            { fieldPathName: "Parent.record_type", isShown: true },
                            { fieldPathName: "Tags", isShown: true },
                            { fieldPathName: "WIType", isShown: true },
                            { fieldPathName: "State", isShown: true }
                        ],
                        filterNode: {
                            boolOp: "BOOL_OP_AND",
                            fieldFilters: [
                                { fieldPath: "Project", compOp: "COMP_OP_EQ", values: [projectId] },
                                ...(owner ? [{ fieldPath: "Owner", compOp: "COMP_OP_EQ", values: ["[CURRENT_USER]"] }] : []),
                                ...(workitemType ? [{ fieldPath: "WIType", compOp: "COMP_OP_EQ", values: [workitemType] }] : [])
                            ]
                        }
                    },
                    resultSetOptions: {
                        pageSize: 300,
                        convertToLocalTime: true
                    }
                };
    
                const queryResponse = await fetch(`${serverURL}/ccmweb/rest/repos/${teamspaceID}/databases/${applicationName}/query`, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                        'Authorization': `Basic ${personal_access_token_string}`,
                        'Cookie': globalCookies
                    },
                    body: JSON.stringify(queryPayload)
                });
    
                const queryData = await queryResponse.json();
                const resultSetId = queryData.result_set_id;
    
                if (!resultSetId) {
                    throw new Error("Failed to retrieve result set ID");
                }
    
                // Second API call to fetch work items
                const workItemsResponse = await fetch(`${serverURL}/ccmweb/rest/repos/${teamspaceID}/databases/${applicationName}/query/${resultSetId}?pageNumber=1`, {
                    method: 'GET',
                    headers: {
                        'Content-Type': 'application/json',
                        'Authorization': `Basic ${personal_access_token_string}`,
                        'Cookie': globalCookies
                    }
                });
    
                const workItemsData = await workItemsResponse.json();
    
                if (workItemsData) {
                    return {
                        content: [{ type: 'text', text: `Work items retrieved: ${JSON.stringify(workItemsData)}` }]
                    };
                } else {
                    throw new Error("Failed to retrieve work items");
                }
            } catch (e) {
                return {
                    content: [{ type: 'text', text: `Error retrieving work items: ${e.message}` }]
                };
            }
        }
    );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mrchris2000/mcp-devops-plan'

If you have feedback or need assistance with the MCP directory API, please join our Discord server