Skip to main content
Glama

get-work-items

Retrieve Azure DevOps work items using WIQL queries, specific IDs, or custom fields to track and manage development tasks across projects.

Instructions

Get work items from Azure DevOps

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
wiqlNoWork Item Query Language (WIQL) query
idsNoSpecific work item IDs to retrieve
fieldsNoFields to include in the response

Implementation Reference

  • The core handler function that executes the 'get-work-items' tool logic. Supports WIQL queries, specific IDs, or default recent work items from the project using Azure DevOps Work Item Tracking API.
    private async getWorkItems(args: any): Promise<any> { try { let result; if (args.wiql) { // Query using WIQL const wiqlResult = await this.makeApiRequest('/wit/wiql?api-version=7.1', 'POST', { query: args.wiql }); if (wiqlResult.workItems && wiqlResult.workItems.length > 0) { const ids = wiqlResult.workItems.map((wi: any) => wi.id); const fields = args.fields ? args.fields.join(',') : undefined; const fieldsParam = fields ? `&fields=${encodeURIComponent(fields)}` : ''; result = await this.makeApiRequest( `/wit/workitems?ids=${ids.join(',')}${fieldsParam}&api-version=7.1` ); } else { result = { value: [] }; } } else if (args.ids && args.ids.length > 0) { // Get specific work items by ID const fields = args.fields ? args.fields.join(',') : undefined; const fieldsParam = fields ? `&fields=${encodeURIComponent(fields)}` : ''; result = await this.makeApiRequest( `/wit/workitems?ids=${args.ids.join(',')}${fieldsParam}&api-version=7.1` ); } else { // Default query for recent work items const defaultWiql = `SELECT [System.Id], [System.Title], [System.State], [System.AssignedTo] FROM WorkItems WHERE [System.TeamProject] = '${this.currentConfig!.project}' ORDER BY [System.ChangedDate] DESC`; const wiqlResult = await this.makeApiRequest('/wit/wiql?api-version=7.1', 'POST', { query: defaultWiql }); if (wiqlResult.workItems && wiqlResult.workItems.length > 0) { const ids = wiqlResult.workItems.slice(0, 20).map((wi: any) => wi.id); // Limit to 20 items result = await this.makeApiRequest( `/wit/workitems?ids=${ids.join(',')}&api-version=7.1` ); } else { result = { value: [] }; } } return { content: [{ type: 'text', text: JSON.stringify(result, null, 2), }], }; } catch (error) { throw new Error(`Failed to get work items: ${error instanceof Error ? error.message : 'Unknown error'}`); } }
  • Defines the input schema, description, and name for the 'get-work-items' tool, used in the MCP listTools response.
    { name: 'get-work-items', description: 'Get work items from Azure DevOps', inputSchema: { type: 'object', properties: { wiql: { type: 'string', description: 'Work Item Query Language (WIQL) query', }, ids: { type: 'array', items: { type: 'number' }, description: 'Specific work item IDs to retrieve', }, fields: { type: 'array', items: { type: 'string' }, description: 'Fields to include in the response', }, }, }, },
  • The switch statement in handleToolCall that registers and dispatches 'get-work-items' to its handler function.
    switch (name) { case 'get-work-items': return await this.getWorkItems(args || {}); case 'create-work-item': return await this.createWorkItem(args || {}); case 'update-work-item': return await this.updateWorkItem(args || {}); case 'add-work-item-comment': return await this.addWorkItemComment(args || {}); case 'get-repositories': return await this.getRepositories(args || {}); case 'get-builds': return await this.getBuilds(args || {}); case 'get-pull-requests': return await this.getPullRequests(args || {}); case 'trigger-pipeline': return await this.triggerPipeline(args || {}); case 'get-pipeline-status': return await this.getPipelineStatus(args || {}); default: throw new Error(`Unknown tool: ${name}`); }
  • Supporting utility method for making authenticated HTTPS requests to Azure DevOps APIs, heavily used by the get-work-items handler.
    private async makeApiRequest(endpoint: string, method: string = 'GET', body?: any): Promise<any> { if (!this.currentConfig) { throw new Error('No configuration available'); } const { organizationUrl, pat, project } = this.currentConfig; const baseUrl = `${organizationUrl}/${project}/_apis`; const requestUrl = `${baseUrl}${endpoint}`; return new Promise((resolve, reject) => { const urlParts = new url.URL(requestUrl); const postData = body ? JSON.stringify(body) : undefined; const options = { hostname: urlParts.hostname, port: urlParts.port || 443, path: urlParts.pathname + urlParts.search, method, headers: { 'Authorization': `Basic ${Buffer.from(`:${pat}`).toString('base64')}`, 'Content-Type': method === 'PATCH' && endpoint.includes('/wit/workitems/') ? 'application/json-patch+json' : 'application/json', 'Accept': 'application/json', // For preview APIs, we need to properly handle the API version in the URL, not headers ...(postData && { 'Content-Length': Buffer.byteLength(postData) }), }, }; const req = https.request(options, (res) => { let data = ''; res.on('data', (chunk) => { data += chunk; }); res.on('end', () => { try { if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) { const result = data ? JSON.parse(data) : {}; resolve(result); } else { reject(new Error(`HTTP ${res.statusCode}: ${data}`)); } } catch (error) { reject(new Error(`Failed to parse response: ${error}`)); } }); }); req.on('error', (error) => { reject(new Error(`Request failed: ${error.message}`)); }); if (postData) { req.write(postData); } req.end(); }); }

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/wangkanai/devops-enhanced-mcp'

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