Skip to main content
Glama
Tiberriver256

Azure DevOps MCP Server

get_work_item

Retrieve full details of an Azure DevOps work item including its fields, relations, links, and attachments. Specify the work item ID and optionally choose the level of detail.

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

  • Core handler function that fetches a work item by ID from Azure DevOps API, optionally expands fields, and enriches the result with all possible fields for the work item type.
    /**
     * Maps string-based expansion options to the WorkItemExpand enum
     */
    const expandMap: Record<string, WorkItemExpand> = {
      none: WorkItemExpand.None,
      relations: WorkItemExpand.Relations,
      fields: WorkItemExpand.Fields,
      links: WorkItemExpand.Links,
      all: WorkItemExpand.All,
    };
    
    /**
     * Get a work item by ID
     *
     * @param connection The Azure DevOps WebApi connection
     * @param workItemId The ID of the work item
     * @param expand Optional expansion options (defaults to 'all')
     * @returns The work item details
     * @throws {AzureDevOpsResourceNotFoundError} If the work item is not found
     */
    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 defining input validation for get_work_item: workItemId (number) and expand (optional enum).
    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 for 'get_work_item', linking the name and description to the schema.
    export const workItemsTools: ToolDefinition[] = [
      {
        name: 'list_work_items',
        description: 'List work items in a project',
        inputSchema: zodToJsonSchema(ListWorkItemsSchema),
      },
      {
        name: 'get_work_item',
        description: 'Get details of a specific work item',
        inputSchema: zodToJsonSchema(GetWorkItemSchema),
      },
      {
        name: 'create_work_item',
        description: 'Create a new work item',
        inputSchema: zodToJsonSchema(CreateWorkItemSchema),
      },
      {
        name: 'update_work_item',
        description: 'Update an existing work item',
        inputSchema: zodToJsonSchema(UpdateWorkItemSchema),
      },
      {
        name: 'manage_work_item_link',
        description: 'Add or remove links between work items',
        inputSchema: zodToJsonSchema(ManageWorkItemLinkSchema),
      },
    ];
  • Request dispatch handler that routes 'get_work_item' calls to the getWorkItem function with parsed arguments.
    export const handleWorkItemsRequest: RequestHandler = async (
      connection: WebApi,
      request: CallToolRequest,
    ): Promise<CallToolResponse> => {
      switch (request.params.name) {
        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) }],
          };
        }
        case 'list_work_items': {
          const args = ListWorkItemsSchema.parse(request.params.arguments);
          const result = await listWorkItems(connection, {
            projectId: args.projectId ?? defaultProject,
            teamId: args.teamId,
            queryId: args.queryId,
            wiql: args.wiql,
            top: args.top,
            skip: args.skip,
          });
          return {
            content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
          };
        }
        case 'create_work_item': {
          const args = CreateWorkItemSchema.parse(request.params.arguments);
          const result = await createWorkItem(
            connection,
            args.projectId ?? defaultProject,
            args.workItemType,
            {
              title: args.title,
              description: args.description,
              assignedTo: args.assignedTo,
              areaPath: args.areaPath,
              iterationPath: args.iterationPath,
              priority: args.priority,
              parentId: args.parentId,
              additionalFields: args.additionalFields,
            },
          );
          return {
            content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
          };
        }
        case 'update_work_item': {
          const args = UpdateWorkItemSchema.parse(request.params.arguments);
          const result = await updateWorkItem(connection, args.workItemId, {
            title: args.title,
            description: args.description,
            assignedTo: args.assignedTo,
            areaPath: args.areaPath,
            iterationPath: args.iterationPath,
            priority: args.priority,
            state: args.state,
            additionalFields: args.additionalFields,
          });
          return {
            content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
          };
        }
        case 'manage_work_item_link': {
          const args = ManageWorkItemLinkSchema.parse(request.params.arguments);
          const result = await manageWorkItemLink(
            connection,
            args.projectId ?? defaultProject,
            {
              sourceWorkItemId: args.sourceWorkItemId,
              targetWorkItemId: args.targetWorkItemId,
              operation: args.operation,
              relationType: args.relationType,
              newRelationType: args.newRelationType,
              comment: args.comment,
            },
          );
          return {
            content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
          };
        }
        default:
          throw new Error(`Unknown work items tool: ${request.params.name}`);
      }
    };
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description must convey behavioral details. 'Get details' implies a read-only operation, but it lacks specifics on permissions, error handling (e.g., missing ID), or side effects. The minimal description does not compensate for the absence of annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence with no redundancy. It is front-loaded and efficient, containing only the essential information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no output schema, the description should specify what 'details' includes (e.g., fields, relations). It fails to explain the return value, making it less useful for selection among similar tools like 'get_work_item' vs 'get_pull_request'. The context signals show siblings that return details, but this tool lacks specificity.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% coverage for both parameters ('workItemId' and 'expand'). The description adds no additional meaning beyond the schema, so a baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'get' and resource 'work item', indicating a retrieval operation for a specific item. It differentiates from sibling tools like 'list_work_items' (multiple items) and 'search_work_items' (search), but does not explicitly distinguish from other 'get' tools like 'get_pull_request'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives (e.g., 'search_work_items' or 'list_work_items'). There is no mention of prerequisites, context, or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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