Skip to content

Commit efefecf

Browse files
committed
Add support to run wiql queries in the work items tool.
modified: src/tools/workitems.ts
1 parent 3d969ea commit efefecf

File tree

3 files changed

+123
-2
lines changed

3 files changed

+123
-2
lines changed

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,9 @@ dist
135135
.yarn/unplugged
136136
.yarn/build-state.yml
137137
.yarn/install-state.gz
138-
.pnp.*
138+
.pnp.*
139+
140+
# Claude code
141+
.mcp.json
142+
.claude/
143+

CLAUDE.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
This is an Azure DevOps MCP (Model Context Protocol) Server that provides access to Azure DevOps services through standardized tools. The server enables AI agents to interact with Azure DevOps APIs for managing projects, work items, builds, releases, repositories, and more.
8+
9+
## Development Commands
10+
11+
### Building and Development
12+
- `npm run build` - Compile TypeScript to JavaScript in `dist/` directory
13+
- `npm run watch` - Watch mode for continuous compilation during development
14+
- `npm run prepare` - Runs build automatically (used by npm lifecycle)
15+
- `npm run clean` - Remove the `dist/` directory
16+
- `npm run validate-tools` - Validate tool names and TypeScript compilation
17+
18+
### Code Quality
19+
- `npm run eslint` - Run ESLint linter
20+
- `npm run eslint-fix` - Run ESLint with automatic fixes
21+
- `npm run format` - Format code with Prettier
22+
- `npm run format-check` - Check code formatting without making changes
23+
24+
### Testing
25+
- `npm test` - Run Jest test suite
26+
- Coverage thresholds are set to 40% for branches, functions, lines, and statements
27+
- Test files are located in `test/` directory and follow the pattern `**/?(*.)+(spec|test).[jt]s?(x)`
28+
29+
### Running the Server
30+
- `npm start` - Start the MCP server (requires Azure DevOps organization name as argument)
31+
- `npm run inspect` - Run the server with MCP inspector for debugging
32+
33+
### Local Development Setup
34+
For source installation (development mode):
35+
1. Clone repository and run `npm install`
36+
2. Configure `.vscode/mcp.json` with local command: `"mcp-server-azuredevops"`
37+
3. The server requires an Azure DevOps organization name as the first argument
38+
39+
## Architecture
40+
41+
### Core Components
42+
- **Entry Point**: `src/index.ts` - Main server initialization, Azure authentication, and MCP server setup
43+
- **Tool Configuration**: `src/tools.ts` - Aggregates all tool modules and configures them with the MCP server
44+
- **Authentication**: Uses `@azure/identity` with `DefaultAzureCredential` for Azure DevOps API access
45+
- **Client Setup**: Creates Azure DevOps WebApi clients with proper user agent and authentication
46+
47+
### Tool Organization
48+
Tools are organized by Azure DevOps service area in `src/tools/`:
49+
- `core.ts` - Projects and teams management
50+
- `work.ts` - Iterations and team work management
51+
- `workitems.ts` - Work item CRUD operations and queries
52+
- `repos.ts` - Repository and pull request management
53+
- `builds.ts` - Build pipelines and execution
54+
- `releases.ts` - Release management
55+
- `testplans.ts` - Test planning and execution
56+
- `wiki.ts` - Wiki content management
57+
- `search.ts` - Search across code, wiki, and work items
58+
- `advsec.ts` - Advanced Security alerts management
59+
- `auth.ts` - Authentication utilities
60+
61+
### Key Patterns
62+
- Each tool module follows the pattern: `configure[ServiceName]Tools(server, tokenProvider, connectionProvider, ...)`
63+
- All tools use Zod schemas for input validation and JSON schema generation
64+
- Authentication is handled centrally through token and connection providers
65+
- User agent composition includes package version and MCP client information
66+
67+
### Environment Variables
68+
- `ADO_MCP_AZURE_TOKEN_CREDENTIALS` - Optional override for Azure token credentials
69+
- Falls back to `AZURE_TOKEN_CREDENTIALS = "dev"` for development
70+
71+
### Project Structure
72+
- `src/` - TypeScript source code
73+
- `dist/` - Compiled JavaScript output (created by build)
74+
- `test/` - Jest test files with mocks in `test/mocks/`
75+
- `docs/` - Documentation files (FAQ, HOWTO, TROUBLESHOOTING)
76+
77+
## Important Notes
78+
79+
### Adding New Tools
80+
- Follow existing patterns in tool modules under `src/tools/`
81+
- Use Azure DevOps TypeScript clients when available, fall back to direct API calls only when necessary
82+
- Add tool configuration to `configureAllTools()` in `src/tools.ts`
83+
- Include comprehensive input validation with Zod schemas
84+
- Follow the established naming convention: `[service]_[action]_[object]`
85+
86+
### Testing
87+
- Mock Azure DevOps API responses in `test/mocks/`
88+
- Test files mirror the source structure in `test/src/`
89+
- Use Jest with ts-jest preset for TypeScript support
90+
91+
### Code Quality Standards
92+
- TypeScript with strict mode enabled
93+
- ESLint configuration with Prettier integration
94+
- All files must include Microsoft copyright headers
95+
- Follow existing code patterns for consistency

src/tools/workitems.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { AccessToken } from "@azure/identity";
55
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
66
import { WebApi } from "azure-devops-node-api";
7-
import { WorkItemExpand, WorkItemRelation } from "azure-devops-node-api/interfaces/WorkItemTrackingInterfaces.js";
7+
import { WorkItemExpand, WorkItemRelation, Wiql } from "azure-devops-node-api/interfaces/WorkItemTrackingInterfaces.js";
88
import { QueryExpand } from "azure-devops-node-api/interfaces/WorkItemTrackingInterfaces.js";
99
import { z } from "zod";
1010
import { batchApiVersion, markdownCommentsApiVersion, getEnumKeys, safeEnumConvert } from "../utils.js";
@@ -25,6 +25,7 @@ const WORKITEM_TOOLS = {
2525
get_work_item_type: "wit_get_work_item_type",
2626
get_query: "wit_get_query",
2727
get_query_results_by_id: "wit_get_query_results_by_id",
28+
query_by_wiql: "wit_query_by_wiql",
2829
update_work_items_batch: "wit_update_work_items_batch",
2930
work_items_link: "wit_work_items_link",
3031
work_item_unlink: "wit_work_item_unlink",
@@ -633,6 +634,26 @@ function configureWorkItemTools(server: McpServer, tokenProvider: () => Promise<
633634
}
634635
);
635636

637+
server.tool(
638+
WORKITEM_TOOLS.query_by_wiql,
639+
"Execute a WIQL query to retrieve work items.",
640+
{
641+
wiql: z.string().describe("The WIQL query string to execute."),
642+
top: z.number().optional().describe("The maximum number of results to return."),
643+
},
644+
async ({ wiql, top }) => {
645+
const connection = await connectionProvider();
646+
const workItemApi = await connection.getWorkItemTrackingApi();
647+
648+
const wiqlObject: Wiql = { query: wiql };
649+
const queryResult = await workItemApi.queryByWiql(wiqlObject, undefined, undefined, top);
650+
651+
return {
652+
content: [{ type: "text", text: JSON.stringify(queryResult, null, 2) }],
653+
};
654+
}
655+
);
656+
636657
server.tool(
637658
WORKITEM_TOOLS.update_work_items_batch,
638659
"Update work items in batch",

0 commit comments

Comments
 (0)