Skip to main content
Glama
mmruesch12
by mmruesch12

list_work_items

Retrieve and filter work items in an Azure DevOps project by type, state, or assigned user to streamline project management and task tracking.

Instructions

List work items in a project

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
assignedToNoFilter by assigned user
projectYesName of the Azure DevOps project
statesNoFilter by states
typesNoFilter by work item types

Implementation Reference

  • The handler function that implements the core logic for listing work items using Azure DevOps WIQL query, fetching details, and returning formatted response.
    export async function listWorkItems(rawParams: any) {
      // Parse arguments with defaults from environment variables
      const params = listWorkItemsSchema.parse({
        project: rawParams.project || DEFAULT_PROJECT,
        types: rawParams.types,
        states: rawParams.states,
        assignedTo: rawParams.assignedTo,
      });
    
      console.error("[API] Listing work items:", params);
    
      try {
        // Get the Work Item Tracking API client
        const witClient = await getWorkItemClient();
    
        // Build WIQL query
        let wiql = `SELECT [System.Id], [System.Title], [System.State], [System.WorkItemType], [System.AssignedTo] FROM WorkItems WHERE [System.TeamProject] = '${params.project}'`;
    
        if (params.types && params.types.length > 0) {
          wiql += ` AND [System.WorkItemType] IN ('${params.types.join("','")}')`;
        }
    
        if (params.states && params.states.length > 0) {
          wiql += ` AND [System.State] IN ('${params.states.join("','")}')`;
        }
    
        if (params.assignedTo) {
          wiql += ` AND [System.AssignedTo] = '${params.assignedTo}'`;
        }
    
        // Execute the query
        const queryResult = await witClient.queryByWiql({ query: wiql });
    
        if (!queryResult.workItems) {
          return {
            content: [{ type: "text", text: JSON.stringify([], null, 2) }],
          };
        }
    
        // Get full work item details
        const workItems = await witClient.getWorkItems(
          queryResult.workItems.map(
            (wi: WorkItemInterfaces.WorkItemReference) => wi.id!
          ),
          undefined,
          undefined
        );
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(workItems, null, 2),
            },
          ],
        };
      } catch (error) {
        logError("Error listing work items", error);
        throw error;
      }
    }
  • Zod schema for validating input parameters to listWorkItems function, with project required and others optional.
    export const listWorkItemsSchema = z.object({
      project: z.string(),
      types: z.array(z.string()).optional(),
      states: z.array(z.string()).optional(),
      assignedTo: z.string().optional(),
    });
    
    export type ListWorkItemsParams = z.infer<typeof listWorkItemsSchema>;
  • src/index.ts:69-70 (registration)
    Registration of the tool handler in the MCP server's CallToolRequestSchema switch statement.
    case "list_work_items":
      return await listWorkItems(request.params.arguments || {});
  • Tool definition object exported in workItemTools array, used for MCP ListTools response defining the tool's name, description, and input schema.
    {
      name: "list_work_items",
      description: "List work items in a project",
      inputSchema: {
        type: "object",
        properties: {
          project: {
            type: "string",
            description: "Name of the Azure DevOps project",
          },
          types: {
            type: "array",
            items: { type: "string" },
            description: "Filter by work item types",
          },
          states: {
            type: "array",
            items: { type: "string" },
            description: "Filter by states",
          },
          assignedTo: {
            type: "string",
            description: "Filter by assigned user",
          },
        },
        required: ["project"],
      },
    },
  • src/index.ts:50-63 (registration)
    MCP server handler for ListToolsRequestSchema that includes workItemTools in the tools list for registration.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          // Work Items
          ...workItemTools,
          // Pull Requests
          ...pullRequestTools,
          // Wiki
          ...wikiTools,
          // Projects
          ...projectTools,
        ],
      };
    });

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/mmruesch12/azdo-mcp'

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