import { getWorkItem } from './get.js';
import { listWorkItems, WorkItemListArgs } from './list.js';
import { createWorkItem } from './create.js';
import { updateWorkItem } from './update.js';
import { searchWorkItems, SearchWorkItemsArgs } from './search.js';
import { addWorkItemComment } from './add-comment.js';
import { getWorkItemComments } from './get-comments.js';
import { AzureDevOpsConfig } from '../../config/environment.js';
import type { WorkItem, WorkItemBatchGetRequest, Wiql } from 'azure-devops-node-api/interfaces/WorkItemTrackingInterfaces.js';
import type { JsonPatchOperation } from 'azure-devops-node-api/interfaces/common/VSSInterfaces.js';
const definitions = [
{
name: 'get_work_item',
description: 'Get work items by IDs',
inputSchema: {
type: 'object',
properties: {
ids: {
type: 'array',
items: {
type: 'number'
},
description: 'Work item IDs',
},
fields: {
type: 'array',
items: {
type: 'string'
},
description: 'Fields to include (e.g., "System.Title", "System.State")',
},
asOf: {
type: 'string',
format: 'date-time',
description: 'As of a specific date (ISO 8601)',
},
$expand: {
type: 'number',
enum: [0, 1, 2, 3, 4],
description: 'Expand options (None=0, Relations=1, Fields=2, Links=3, All=4)',
},
errorPolicy: {
type: 'number',
enum: [1, 2],
description: 'Error policy (Fail=1, Omit=2)',
}
},
required: ['ids'],
},
},
{
name: 'add_work_item_comment',
description: 'Add a comment to a work item',
inputSchema: {
type: 'object',
properties: {
id: {
type: 'number',
description: 'Work item ID',
},
text: {
type: 'string',
description: 'Comment text',
},
},
required: ['id', 'text'],
},
},
{
name: 'get_work_item_comments',
description: 'Get comments from a work item',
inputSchema: {
type: 'object',
properties: {
id: {
type: 'number',
description: 'Work item ID',
},
},
required: ['id'],
},
},
{
name: 'search_work_items',
description: 'Search for work items using text search',
inputSchema: {
type: 'object',
properties: {
searchText: {
type: 'string',
description: 'Text to search for in work items',
},
top: {
type: 'number',
description: 'Maximum number of results to return (default: 10)',
},
skip: {
type: 'number',
description: 'Number of results to skip (for pagination)',
},
},
required: ['searchText'],
},
},
{
name: 'list_work_items',
description: 'List work items from a board',
inputSchema: {
type: 'object',
properties: {
query: {
type: 'string',
description: 'WIQL query to filter work items',
},
page: {
type: 'number',
description: 'Page number for pagination (defaults to 1)',
},
},
required: ['query'],
},
},
{
name: 'create_work_item',
description: 'Create a new work item using JSON patch operations',
inputSchema: {
type: 'object',
properties: {
type: {
type: 'string',
description: 'Work item type (e.g., "Bug", "Task", "User Story")',
},
document: {
type: 'array',
items: {
type: 'object',
properties: {
op: {
type: 'string',
enum: ['add', 'remove', 'replace', 'move', 'copy', 'test'],
description: 'The patch operation to perform',
},
path: {
type: 'string',
description: 'The path for the operation (e.g., /fields/System.Title)',
},
value: {
description: 'The value for the operation',
},
},
required: ['op', 'path'],
},
description: 'Array of JSON patch operations to apply',
},
},
required: ['type', 'document'],
},
},
{
name: 'update_work_item',
description: 'Update an existing work item using JSON patch operations',
inputSchema: {
type: 'object',
properties: {
id: {
type: 'number',
description: 'ID of the work item to update',
},
document: {
type: 'array',
items: {
type: 'object',
properties: {
op: {
type: 'string',
enum: ['add', 'remove', 'replace', 'move', 'copy', 'test'],
description: 'The patch operation to perform',
},
path: {
type: 'string',
description: 'The path for the operation (e.g., /fields/System.Title)',
},
value: {
description: 'The value for the operation',
},
},
required: ['op', 'path'],
},
description: 'Array of JSON patch operations to apply',
},
},
required: ['id', 'document'],
},
},
];
export const workItemTools = {
initialize: (config: AzureDevOpsConfig) => ({
getWorkItem: (args: WorkItemBatchGetRequest) => getWorkItem(args, config),
listWorkItems: (args: WorkItemListArgs) => listWorkItems(args, config),
createWorkItem: (args: { type: string; document: JsonPatchOperation[] }) => createWorkItem(args, config),
updateWorkItem: (args: { id: number; document: JsonPatchOperation[] }) => updateWorkItem(args, config),
searchWorkItems: (args: SearchWorkItemsArgs) => searchWorkItems(args, config),
addWorkItemComment: (args: { id: number; text: string }) => addWorkItemComment(args, config),
getWorkItemComments: (args: { id: number }) => getWorkItemComments(args, config),
definitions,
}),
definitions,
};