get_work_item
Retrieve Azure DevOps work items by ID to access details like title, state, and fields. Specify IDs, fields to include, and expansion options for comprehensive data retrieval.
Instructions
Get work items by IDs
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ids | Yes | Work item IDs | |
| fields | No | Fields to include (e.g., "System.Title", "System.State") | |
| asOf | No | As of a specific date (ISO 8601) | |
| $expand | No | Expand options (None=0, Relations=1, Fields=2, Links=3, All=4) | |
| errorPolicy | No | Error policy (Fail=1, Omit=2) |
Implementation Reference
- src/tools/work-item/get.ts:6-31 (handler)The main handler function that executes the tool: validates input, initializes connection, calls Azure DevOps WorkItemTrackingApi.getWorkItems, formats response as MCP content.export async function getWorkItem(args: WorkItemBatchGetRequest, config: AzureDevOpsConfig) { if (!args.ids || !args.ids.length) { throw new McpError(ErrorCode.InvalidParams, 'Invalid work item ID'); } AzureDevOpsConnection.initialize(config); const connection = AzureDevOpsConnection.getInstance(); const workItemTrackingApi = await connection.getWorkItemTrackingApi(); const workItems = await workItemTrackingApi.getWorkItems( args.ids, args.fields || ['System.Id', 'System.Title', 'System.State', 'System.Description'], args.asOf, WorkItemExpand.All, args.errorPolicy, config.project ); return { content: [ { type: 'text', text: JSON.stringify(workItems, null, 2), }, ], }; }
- src/tools/work-item/index.ts:10-48 (schema)MCP input schema definition for the 'get_work_item' tool, specifying parameters like ids (required array of numbers), optional fields, asOf date, expand enum, errorPolicy enum.{ name: 'get_work_item', description: 'Get work items by IDs', inputSchema: { type: 'object', properties: { ids: { type: 'array', items: { type: 'number' }, description: 'Work item IDs', }, fields: { type: 'array', items: { type: 'string' }, description: 'Fields to include (e.g., "System.Title", "System.State")', }, asOf: { type: 'string', format: 'date-time', description: 'As of a specific date (ISO 8601)', }, $expand: { type: 'number', enum: [0, 1, 2, 3, 4], description: 'Expand options (None=0, Relations=1, Fields=2, Links=3, All=4)', }, errorPolicy: { type: 'number', enum: [1, 2], description: 'Error policy (Fail=1, Omit=2)', } }, required: ['ids'], }, },
- src/tools/work-item/index.ts:137-145 (registration)Registers the getWorkItem handler (along with others) in the workItemTools.initialize function, binding the config parameter and exporting tool definitions.export const workItemTools = { initialize: (config: AzureDevOpsConfig) => ({ getWorkItem: (args: WorkItemBatchGetRequest) => getWorkItem(args, config), listWorkItems: (args: Wiql) => listWorkItems(args, config), createWorkItem: (args: { type: string; document: JsonPatchOperation[] }) => createWorkItem(args, config), updateWorkItem: (args: { id: number; document: JsonPatchOperation[] }) => updateWorkItem(args, config), definitions, }), definitions,
- src/index.ts:126-128 (registration)Top-level dispatch/registration in the MCP server request handler switch statement, routing 'get_work_item' calls to tools.workItem.getWorkItem.case 'get_work_item': result = await tools.workItem.getWorkItem(request.params.arguments); break;