import { Tool } from '@modelcontextprotocol/sdk/types.js';
import { ZephyrClient } from '../zephyr-client.js';
export function createTestExecutionTools(client: ZephyrClient): Tool[] {
return [
{
name: 'zephyr_list_test_executions',
description: 'List test executions for a specific test cycle',
inputSchema: {
type: 'object',
properties: {
testCycleKey: {
type: 'string',
description: 'The test cycle key to list executions for'
},
maxResults: {
type: 'number',
description: 'Maximum number of results to return (default: 50)',
default: 50
}
},
required: ['testCycleKey']
}
},
{
name: 'zephyr_get_test_execution',
description: 'Get a specific test execution by its key',
inputSchema: {
type: 'object',
properties: {
executionKey: {
type: 'string',
description: 'The key of the test execution to retrieve'
}
},
required: ['executionKey']
}
},
{
name: 'zephyr_create_test_execution',
description: 'Create a new test execution',
inputSchema: {
type: 'object',
properties: {
testCaseKey: {
type: 'string',
description: 'The test case key being executed'
},
testCycleKey: {
type: 'string',
description: 'The test cycle key this execution belongs to'
},
status: {
type: 'string',
description: 'Execution status (e.g., "Pass", "Fail", "Blocked", "In Progress")',
enum: ['Pass', 'Fail', 'Blocked', 'In Progress', 'Not Executed']
},
executedBy: {
type: 'string',
description: 'User who executed the test (optional)'
},
actualTime: {
type: 'number',
description: 'Actual execution time in minutes (optional)'
},
comment: {
type: 'string',
description: 'Comments about the execution (optional)'
},
defects: {
type: 'array',
items: { type: 'string' },
description: 'Array of defect keys linked to this execution (optional)'
},
stepResults: {
type: 'array',
items: {
type: 'object',
properties: {
stepIndex: {
type: 'number',
description: 'Step order (0-based)'
},
status: {
type: 'string',
description: 'Step execution status',
enum: ['Pass', 'Fail', 'Blocked', 'Not Executed']
},
actual: {
type: 'string',
description: 'Actual result of the step'
},
comment: {
type: 'string',
description: 'Comments about the step execution'
}
},
required: ['stepIndex', 'status']
},
description: 'Array of step execution results (optional)'
}
},
required: ['testCaseKey', 'testCycleKey', 'status']
}
},
{
name: 'zephyr_update_test_execution',
description: 'Update an existing test execution',
inputSchema: {
type: 'object',
properties: {
executionKey: {
type: 'string',
description: 'The key of the test execution to update'
},
status: {
type: 'string',
description: 'Updated execution status',
enum: ['Pass', 'Fail', 'Blocked', 'In Progress', 'Not Executed']
},
executedBy: {
type: 'string',
description: 'Updated user who executed the test'
},
actualTime: {
type: 'number',
description: 'Updated actual execution time in minutes'
},
comment: {
type: 'string',
description: 'Updated comments about the execution'
},
defects: {
type: 'array',
items: { type: 'string' },
description: 'Updated array of defect keys'
},
stepResults: {
type: 'array',
items: {
type: 'object',
properties: {
stepIndex: {
type: 'number',
description: 'Step order (0-based)'
},
status: {
type: 'string',
description: 'Step execution status',
enum: ['Pass', 'Fail', 'Blocked', 'Not Executed']
},
actual: {
type: 'string',
description: 'Actual result of the step'
},
comment: {
type: 'string',
description: 'Comments about the step execution'
}
},
required: ['stepIndex', 'status']
},
description: 'Updated array of step execution results'
}
},
required: ['executionKey']
}
},
{
name: 'zephyr_bulk_create_test_executions',
description: 'Create multiple test executions at once',
inputSchema: {
type: 'object',
properties: {
executions: {
type: 'array',
items: {
type: 'object',
properties: {
testCaseKey: {
type: 'string',
description: 'The test case key being executed'
},
testCycleKey: {
type: 'string',
description: 'The test cycle key this execution belongs to'
},
status: {
type: 'string',
description: 'Execution status'
},
executedBy: {
type: 'string',
description: 'User who executed the test'
},
actualTime: {
type: 'number',
description: 'Actual execution time in minutes'
},
comment: {
type: 'string',
description: 'Comments about the execution'
},
defects: {
type: 'array',
items: { type: 'string' },
description: 'Array of defect keys'
}
},
required: ['testCaseKey', 'testCycleKey', 'status']
},
description: 'Array of test executions to create',
minItems: 1,
maxItems: 50
}
},
required: ['executions']
}
},
{
name: 'zephyr_get_test_case_executions',
description: 'Get all executions for a specific test case',
inputSchema: {
type: 'object',
properties: {
testCaseKey: {
type: 'string',
description: 'The test case key to get executions for'
},
maxResults: {
type: 'number',
description: 'Maximum number of results to return (default: 50)',
default: 50
}
},
required: ['testCaseKey']
}
},
{
name: 'zephyr_get_test_results',
description: 'Get test results for a specific test cycle',
inputSchema: {
type: 'object',
properties: {
testCycleKey: {
type: 'string',
description: 'The test cycle key to get results for'
},
maxResults: {
type: 'number',
description: 'Maximum number of results to return (default: 50)',
default: 50
}
},
required: ['testCycleKey']
}
}
];
}
export async function handleTestExecutionToolCall(toolName: string, args: any, client: ZephyrClient): Promise<any> {
switch (toolName) {
case 'zephyr_list_test_executions':
return await client.getTestExecutions(args.testCycleKey, args.maxResults);
case 'zephyr_get_test_execution':
return await client.getTestExecution(args.executionKey);
case 'zephyr_create_test_execution':
return await client.createTestExecution(args);
case 'zephyr_update_test_execution':
return await client.updateTestExecution(args.executionKey, args);
case 'zephyr_bulk_create_test_executions':
return await client.bulkCreateTestExecutions(args.executions);
case 'zephyr_get_test_case_executions':
return await client.getTestCaseExecutions(args.testCaseKey, args.maxResults);
case 'zephyr_get_test_results':
return await client.getTestResults(args.testCycleKey, args.maxResults);
default:
throw new Error(`Unknown test execution tool: ${toolName}`);
}
}