Skip to main content
Glama

get_work_item

Retrieve detailed information about a specific Azure DevOps work item using its ID, including fields, relations, and links for project tracking.

Instructions

Get details of a specific work item

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
workItemIdYesThe ID of the work item
expandNoThe level of detail to include in the response. Defaults to "all" if not specified.

Implementation Reference

  • The core handler function that retrieves a work item by ID from Azure DevOps, fetches additional field definitions to enhance the response with all possible fields set to null if missing, and handles caching and errors.
    export async function getWorkItem( connection: WebApi, workItemId: number, expand: string = 'all', ): Promise<WorkItem> { try { const witApi = await connection.getWorkItemTrackingApi(); const workItem = await witApi.getWorkItem( workItemId, undefined, undefined, expandMap[expand.toLowerCase()], ); if (!workItem) { throw new AzureDevOpsResourceNotFoundError( `Work item '${workItemId}' not found`, ); } // Extract project and work item type to get all possible fields const projectName = workItem.fields?.['System.TeamProject']; const workItemType = workItem.fields?.['System.WorkItemType']; if (!projectName || !workItemType) { // If we can't determine the project or type, return the original work item return workItem; } // Get all possible fields for this work item type const allFields = workItemTypeFieldsCache[projectName.toString()]?.[ workItemType.toString() ] ?? (await witApi.getWorkItemTypeFieldsWithReferences( projectName.toString(), workItemType.toString(), WorkItemTypeFieldsExpandLevel.All, )); workItemTypeFieldsCache[projectName.toString()] = { ...workItemTypeFieldsCache[projectName.toString()], [workItemType.toString()]: allFields, }; // Create a new work item object with all fields const enhancedWorkItem = { ...workItem }; // Initialize fields object if it doesn't exist if (!enhancedWorkItem.fields) { enhancedWorkItem.fields = {}; } // Set null for all potential fields that don't have values for (const field of allFields) { if ( field.referenceName && !(field.referenceName in enhancedWorkItem.fields) ) { enhancedWorkItem.fields[field.referenceName] = field.defaultValue; } } return enhancedWorkItem; } catch (error) { if (error instanceof AzureDevOpsError) { throw error; } throw new Error( `Failed to get work item: ${error instanceof Error ? error.message : String(error)}`, ); }
  • Zod schema for validating input arguments to the get_work_item tool: requires workItemId (number), optional expand (enum for expansion level).
    export const GetWorkItemSchema = z.object({ workItemId: z.number().describe('The ID of the work item'), expand: z .enum(['none', 'relations', 'fields', 'links', 'all']) .optional() .describe( 'The level of detail to include in the response. Defaults to "all" if not specified.', ), });
  • Tool registration definition including the tool name 'get_work_item', description, and input schema converted to JSON schema for MCP.
    { name: 'get_work_item', description: 'Get details of a specific work item', inputSchema: zodToJsonSchema(GetWorkItemSchema), },
  • Runtime dispatching/handling of the 'get_work_item' tool request: parses arguments with schema, calls the handler, and formats response.
    case 'get_work_item': { const args = GetWorkItemSchema.parse(request.params.arguments); const result = await getWorkItem( connection, args.workItemId, args.expand, ); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], }; }

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/Tiberriver256/mcp-server-azure-devops'

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