Get Work Item
get_work_itemFetch a GitLab work item by global ID to view its widgets, including epic hierarchy, health status, iteration, milestone, and dates.
Instructions
Fetch a GitLab work item (issue, task, epic, incident, OKR) by global ID. Returns the raw widgets array so epic hierarchy, health status, iteration, milestone, and dates are all visible. Accepts either a numeric id or a full gid (gid://gitlab/WorkItem/123).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | Work item ID — numeric (e.g. "123") or full gid (e.g. "gid://gitlab/WorkItem/123") | |
| userCredentials | No | Your GitLab credentials (optional — falls back to the configured env token if not provided) |
Implementation Reference
- src/tools.ts:1765-1786 (handler)The get_work_item tool handler: defines the tool with name 'get_work_item', input schema (accepts an id string), and handler logic that calls client.getWorkItem(id, credentials) and returns the work item with its widget types.
const getWorkItemTool: Tool = { name: 'get_work_item', title: 'Get Work Item', description: 'Fetch a GitLab work item (issue, task, epic, incident, OKR) by global ID. Returns the raw widgets array so epic hierarchy, health status, iteration, milestone, and dates are all visible. Accepts either a numeric id or a full gid (gid://gitlab/WorkItem/123).', requiresAuth: false, requiresWrite: false, annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true }, inputSchema: withUserAuth(z.object({ id: z.string().describe('Work item ID — numeric (e.g. "123") or full gid (e.g. "gid://gitlab/WorkItem/123")'), })), handler: async (input, client, userConfig) => { const credentials = input.userCredentials ? validateUserConfig(input.userCredentials) : userConfig; const result = await client.getWorkItem(input.id, credentials); const wi = result.workItem; if (!wi) return { workItem: null }; const widgetSummary = Array.isArray(wi.widgets) ? wi.widgets.map((w: any) => w.type).filter(Boolean) : []; return { workItem: wi, widgetTypes: widgetSummary }; }, }; - src/tools.ts:1773-1774 (schema)Input schema for get_work_item: accepts a single 'id' string parameter (numeric or full gid like 'gid://gitlab/WorkItem/123').
inputSchema: withUserAuth(z.object({ id: z.string().describe('Work item ID — numeric (e.g. "123") or full gid (e.g. "gid://gitlab/WorkItem/123")'), - src/tools.ts:2292-2292 (registration)getWorkItemTool is registered in the readOnlyTools array (line 2292), which is spread into the tools export array (line 2335).
getWorkItemTool, - src/gitlab-client.ts:519-570 (helper)The client.getWorkItem() helper method: builds a GraphQL query to fetch a work item by ID (converts numeric IDs to gid://gitlab/WorkItem/ format), requesting fields like title, state, author, namespace, and various widgets (assignees, labels, hierarchy, milestone, dates, notes).
async getWorkItem(id: string, userConfig?: UserConfig): Promise<any> { const gid = id.startsWith('gid://') ? id : `gid://gitlab/WorkItem/${id}`; const query = gql` query getWorkItem($id: WorkItemID!) { workItem(id: $id) { id iid title state confidential createdAt updatedAt closedAt webUrl workItemType { id name iconName } author { username name } namespace { id fullPath } widgets { type ... on WorkItemWidgetDescription { description descriptionHtml } ... on WorkItemWidgetAssignees { assignees { nodes { username name webUrl } } } ... on WorkItemWidgetLabels { labels { nodes { id title color description } } } ... on WorkItemWidgetHierarchy { hasChildren hasParent parent { id iid title workItemType { name } webUrl } children { nodes { id iid title state workItemType { name } webUrl } } } ... on WorkItemWidgetMilestone { milestone { id title state dueDate webPath } } ... on WorkItemWidgetStartAndDueDate { startDate dueDate } ... on WorkItemWidgetNotes { discussions(first: 5) { nodes { id notes { nodes { id body author { username } createdAt } } } } } } } } `; return this.query(query, { id: gid }, userConfig); }