Skip to main content
Glama
Tiberriver256

Azure DevOps MCP Server

list_work_items

Retrieve work items from Azure DevOps projects using queries, filters, or saved queries to track tasks, bugs, and features.

Instructions

List work items in a project

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectIdNoThe ID or name of the project (Default: MyProject)
organizationIdNoThe ID or name of the organization (Default: mycompany)
teamIdNoThe ID of the team
queryIdNoID of a saved work item query
wiqlNoWork Item Query Language (WIQL) query
topNoMaximum number of work items to return
skipNoNumber of work items to skip

Implementation Reference

  • The core handler function implementing the list_work_items tool. It queries Azure DevOps work items using WIQL or a saved query ID, applies pagination, retrieves details for specified fields, and handles errors.
    export async function listWorkItems(
      connection: WebApi,
      options: ListWorkItemsOptions,
    ): Promise<WorkItemType[]> {
      try {
        const witApi = await connection.getWorkItemTrackingApi();
        const { projectId, teamId, queryId, wiql } = options;
    
        let workItemRefs: WorkItemReference[] = [];
    
        if (queryId) {
          const teamContext: TeamContext = {
            project: projectId,
            team: teamId,
          };
          const queryResult = await witApi.queryById(queryId, teamContext);
          workItemRefs = queryResult.workItems || [];
        } else {
          const query = wiql || constructDefaultWiql(projectId, teamId);
          const teamContext: TeamContext = {
            project: projectId,
            team: teamId,
          };
          const queryResult = await witApi.queryByWiql({ query }, teamContext);
          workItemRefs = queryResult.workItems || [];
        }
    
        // Apply pagination in memory
        const { top = 200, skip } = options;
        if (skip !== undefined) {
          workItemRefs = workItemRefs.slice(skip);
        }
        if (top !== undefined) {
          workItemRefs = workItemRefs.slice(0, top);
        }
    
        const workItemIds = workItemRefs
          .map((ref) => ref.id)
          .filter((id): id is number => id !== undefined);
    
        if (workItemIds.length === 0) {
          return [];
        }
    
        const fields = [
          'System.Id',
          'System.Title',
          'System.State',
          'System.AssignedTo',
        ];
        const workItems = await witApi.getWorkItems(
          workItemIds,
          fields,
          undefined,
          undefined,
        );
    
        if (!workItems) {
          return [];
        }
    
        return workItems.filter((wi): wi is WorkItem => wi !== undefined);
      } catch (error) {
        if (error instanceof AzureDevOpsError) {
          throw error;
        }
    
        // Check for specific error types and convert to appropriate Azure DevOps errors
        if (error instanceof Error) {
          if (
            error.message.includes('Authentication') ||
            error.message.includes('Unauthorized')
          ) {
            throw new AzureDevOpsAuthenticationError(
              `Failed to authenticate: ${error.message}`,
            );
          }
    
          if (
            error.message.includes('not found') ||
            error.message.includes('does not exist')
          ) {
            throw new AzureDevOpsResourceNotFoundError(
              `Resource not found: ${error.message}`,
            );
          }
        }
    
        throw new AzureDevOpsError(
          `Failed to list work items: ${error instanceof Error ? error.message : String(error)}`,
        );
      }
    }
  • Zod schema defining the input validation for list_work_items tool parameters.
    export const ListWorkItemsSchema = z.object({
      projectId: z
        .string()
        .optional()
        .describe(`The ID or name of the project (Default: ${defaultProject})`),
      organizationId: z
        .string()
        .optional()
        .describe(`The ID or name of the organization (Default: ${defaultOrg})`),
      teamId: z.string().optional().describe('The ID of the team'),
      queryId: z.string().optional().describe('ID of a saved work item query'),
      wiql: z.string().optional().describe('Work Item Query Language (WIQL) query'),
      top: z.number().optional().describe('Maximum number of work items to return'),
      skip: z.number().optional().describe('Number of work items to skip'),
    });
  • Tool definition object registering the list_work_items tool with name, description, and JSON schema.
    {
      name: 'list_work_items',
      description: 'List work items in a project',
      inputSchema: zodToJsonSchema(ListWorkItemsSchema),
    },
  • Dispatch handler case for list_work_items that validates input with schema and invokes the handler function.
    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) }],
      };
  • TypeScript interface defining options for the listWorkItems handler function, matching the schema.
    export interface ListWorkItemsOptions {
      projectId: string;
      teamId?: string;
      queryId?: string;
      wiql?: string;
      top?: number;
      skip?: number;
    }

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