@uarlouski/testrail-mcp-server 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/testrail.js +167 -0
- package/{src/index.ts → dist/index.js} +25 -35
- package/{src/tools/add_attachment_to_run.ts → dist/tools/add_attachment_to_run.js} +8 -18
- package/{src/tools/add_results.ts → dist/tools/add_results.js} +3 -7
- package/{src/tools/add_run.ts → dist/tools/add_run.js} +3 -8
- package/{src/tools/create_case.ts → dist/tools/create_case.js} +1 -7
- package/{src/tools/get_case.ts → dist/tools/get_case.js} +2 -11
- package/{src/tools/get_case_fields.ts → dist/tools/get_case_fields.js} +8 -37
- package/{src/tools/get_cases.ts → dist/tools/get_cases.js} +5 -19
- package/{src/tools/get_projects.ts → dist/tools/get_projects.js} +1 -6
- package/{src/tools/get_sections.ts → dist/tools/get_sections.js} +1 -6
- package/{src/tools/get_statuses.ts → dist/tools/get_statuses.js} +2 -7
- package/{src/tools/get_templates.ts → dist/tools/get_templates.js} +1 -6
- package/{src/tools/get_tests.ts → dist/tools/get_tests.js} +5 -10
- package/{src/tools/update_case.ts → dist/tools/update_case.js} +1 -7
- package/{src/tools/update_cases.ts → dist/tools/update_cases.js} +1 -6
- package/dist/types/custom.js +1 -0
- package/{src/types/testrail.ts → dist/types/testrail.js} +2 -42
- package/{src/utils/mapper.ts → dist/utils/mapper.js} +16 -36
- package/{src/utils/sanitizer.ts → dist/utils/sanitizer.js} +4 -8
- package/package.json +8 -2
- package/.env.example +0 -3
- package/.github/workflows/ci.yml +0 -46
- package/.github/workflows/publish.yml +0 -35
- package/CHANGELOG.md +0 -38
- package/jest.config.js +0 -24
- package/src/client/testrail.ts +0 -227
- package/src/types/custom.ts +0 -19
- package/test/client/testrail.test.ts +0 -545
- package/test/tools/add_results.test.ts +0 -94
- package/test/tools/add_run.test.ts +0 -83
- package/test/tools/create_case.test.ts +0 -101
- package/test/tools/get_case.test.ts +0 -185
- package/test/tools/get_case_fields.test.ts +0 -132
- package/test/tools/get_cases.test.ts +0 -104
- package/test/tools/get_projects.test.ts +0 -38
- package/test/tools/get_sections.test.ts +0 -39
- package/test/tools/get_statuses.test.ts +0 -56
- package/test/tools/get_templates.test.ts +0 -38
- package/test/tools/get_tests.test.ts +0 -47
- package/test/tools/update_case.test.ts +0 -102
- package/test/tools/update_cases.test.ts +0 -89
- package/test/utils/mapper.test.ts +0 -112
- package/test/utils/sanitizer.test.ts +0 -143
- package/tsconfig.json +0 -24
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
const API_INDEX = '/index.php?';
|
|
3
|
+
const API_BASE_V2 = `${API_INDEX}/api/v2`;
|
|
4
|
+
export class TestRailClient {
|
|
5
|
+
baseUrl;
|
|
6
|
+
headers;
|
|
7
|
+
auth;
|
|
8
|
+
prioritiesPromise = null;
|
|
9
|
+
caseTypesPromise = null;
|
|
10
|
+
caseFieldsPromise = null;
|
|
11
|
+
statusesPromise = null;
|
|
12
|
+
projectsPromise = null;
|
|
13
|
+
templatesPromiseMap = new Map();
|
|
14
|
+
constructor(baseUrl, email, apiKey) {
|
|
15
|
+
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
16
|
+
const auth = Buffer.from(`${email}:${apiKey}`).toString('base64');
|
|
17
|
+
this.auth = `Basic ${auth}`;
|
|
18
|
+
this.headers = {
|
|
19
|
+
"Content-Type": "application/json",
|
|
20
|
+
"Authorization": this.auth,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
async getCase(caseId) {
|
|
24
|
+
return this.get(`${API_BASE_V2}/get_case/${caseId}`);
|
|
25
|
+
}
|
|
26
|
+
async getCases(projectId, sectionId, filter) {
|
|
27
|
+
let url = `${API_BASE_V2}/get_cases/${projectId}`;
|
|
28
|
+
if (sectionId) {
|
|
29
|
+
url += `§ion_id=${sectionId}`;
|
|
30
|
+
}
|
|
31
|
+
if (filter) {
|
|
32
|
+
for (const [key, value] of Object.entries(filter)) {
|
|
33
|
+
url += `&${key}=${encodeURIComponent(value)}`;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const allCases = [];
|
|
37
|
+
let nextUrl = url;
|
|
38
|
+
while (nextUrl) {
|
|
39
|
+
const response = await this.get(nextUrl);
|
|
40
|
+
allCases.push(...response.cases);
|
|
41
|
+
nextUrl = response._links?.next;
|
|
42
|
+
if (nextUrl) {
|
|
43
|
+
nextUrl = `${API_INDEX}${nextUrl}`;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return allCases;
|
|
47
|
+
}
|
|
48
|
+
async getSection(sectionId) {
|
|
49
|
+
return this.get(`${API_BASE_V2}/get_section/${sectionId}`);
|
|
50
|
+
}
|
|
51
|
+
async getPriorities() {
|
|
52
|
+
if (!this.prioritiesPromise) {
|
|
53
|
+
this.prioritiesPromise = this.get(`${API_BASE_V2}/get_priorities`);
|
|
54
|
+
}
|
|
55
|
+
return this.prioritiesPromise;
|
|
56
|
+
}
|
|
57
|
+
async getCaseTypes() {
|
|
58
|
+
if (!this.caseTypesPromise) {
|
|
59
|
+
this.caseTypesPromise = this.get(`${API_BASE_V2}/get_case_types`);
|
|
60
|
+
}
|
|
61
|
+
return this.caseTypesPromise;
|
|
62
|
+
}
|
|
63
|
+
async getCaseFields() {
|
|
64
|
+
if (!this.caseFieldsPromise) {
|
|
65
|
+
this.caseFieldsPromise = this.get(`${API_BASE_V2}/get_case_fields`);
|
|
66
|
+
}
|
|
67
|
+
return this.caseFieldsPromise;
|
|
68
|
+
}
|
|
69
|
+
async getStatuses() {
|
|
70
|
+
if (!this.statusesPromise) {
|
|
71
|
+
this.statusesPromise = this.get(`${API_BASE_V2}/get_statuses`);
|
|
72
|
+
}
|
|
73
|
+
return this.statusesPromise;
|
|
74
|
+
}
|
|
75
|
+
async getTemplates(projectId) {
|
|
76
|
+
if (!this.templatesPromiseMap.has(projectId)) {
|
|
77
|
+
this.templatesPromiseMap.set(projectId, this.get(`${API_BASE_V2}/get_templates/${projectId}`));
|
|
78
|
+
}
|
|
79
|
+
return this.templatesPromiseMap.get(projectId);
|
|
80
|
+
}
|
|
81
|
+
async updateCase(caseId, fields) {
|
|
82
|
+
return this.post(`${API_BASE_V2}/update_case/${caseId}`, fields);
|
|
83
|
+
}
|
|
84
|
+
async updateCases(suiteId, caseIds, fields) {
|
|
85
|
+
const response = await this.post(`${API_BASE_V2}/update_cases/${suiteId}`, {
|
|
86
|
+
case_ids: caseIds,
|
|
87
|
+
...fields,
|
|
88
|
+
});
|
|
89
|
+
return response.updated_cases;
|
|
90
|
+
}
|
|
91
|
+
async createCase(sectionId, fields) {
|
|
92
|
+
return this.post(`${API_BASE_V2}/add_case/${sectionId}`, fields);
|
|
93
|
+
}
|
|
94
|
+
async addRun(projectId, fields) {
|
|
95
|
+
return this.post(`${API_BASE_V2}/add_run/${projectId}`, fields);
|
|
96
|
+
}
|
|
97
|
+
async getSections(projectId) {
|
|
98
|
+
const response = await this.get(`${API_BASE_V2}/get_sections/${projectId}`);
|
|
99
|
+
return response.sections;
|
|
100
|
+
}
|
|
101
|
+
async getProjects() {
|
|
102
|
+
if (!this.projectsPromise) {
|
|
103
|
+
this.projectsPromise = this.get(`${API_BASE_V2}/get_projects`)
|
|
104
|
+
.then(response => response.projects);
|
|
105
|
+
}
|
|
106
|
+
return this.projectsPromise;
|
|
107
|
+
}
|
|
108
|
+
async getTests(runId, statusId) {
|
|
109
|
+
let url = `${API_BASE_V2}/get_tests/${runId}`;
|
|
110
|
+
if (statusId && statusId.length > 0) {
|
|
111
|
+
url += `&status_id=${statusId.join(',')}`;
|
|
112
|
+
}
|
|
113
|
+
const allTests = [];
|
|
114
|
+
let nextUrl = url;
|
|
115
|
+
while (nextUrl) {
|
|
116
|
+
const response = await this.get(nextUrl);
|
|
117
|
+
allTests.push(...response.tests);
|
|
118
|
+
nextUrl = response._links?.next;
|
|
119
|
+
if (nextUrl) {
|
|
120
|
+
nextUrl = `${API_INDEX}${nextUrl}`;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return allTests;
|
|
124
|
+
}
|
|
125
|
+
async addResults(runId, results) {
|
|
126
|
+
return this.post(`${API_BASE_V2}/add_results/${runId}`, { results });
|
|
127
|
+
}
|
|
128
|
+
async addAttachmentToRun(runId, filePath, filename) {
|
|
129
|
+
const fileBuffer = await fs.promises.readFile(filePath);
|
|
130
|
+
const blob = new Blob([fileBuffer]);
|
|
131
|
+
const formData = new FormData();
|
|
132
|
+
formData.append('attachment', blob, filename);
|
|
133
|
+
const headers = {
|
|
134
|
+
'Authorization': this.auth,
|
|
135
|
+
};
|
|
136
|
+
return this._executeRequest('POST', `${API_BASE_V2}/add_attachment_to_run/${runId}`, headers, formData);
|
|
137
|
+
}
|
|
138
|
+
async get(endpoint) {
|
|
139
|
+
return this.executeRequest('GET', endpoint);
|
|
140
|
+
}
|
|
141
|
+
async post(endpoint, data) {
|
|
142
|
+
return this.executeRequest('POST', endpoint, data);
|
|
143
|
+
}
|
|
144
|
+
async executeRequest(method, endpoint, data) {
|
|
145
|
+
let jsonData = undefined;
|
|
146
|
+
if (data) {
|
|
147
|
+
jsonData = JSON.stringify(data);
|
|
148
|
+
}
|
|
149
|
+
return this._executeRequest(method, endpoint, this.headers, jsonData);
|
|
150
|
+
}
|
|
151
|
+
async _executeRequest(method, endpoint, headers, body) {
|
|
152
|
+
const url = `${this.baseUrl}${endpoint}`;
|
|
153
|
+
const params = {
|
|
154
|
+
method,
|
|
155
|
+
headers,
|
|
156
|
+
body,
|
|
157
|
+
};
|
|
158
|
+
const response = await fetch(url, params);
|
|
159
|
+
if (!response.ok) {
|
|
160
|
+
let errorMessage = `TestRail: ${response.status} ${response.statusText}`;
|
|
161
|
+
const errorText = await response.text();
|
|
162
|
+
errorMessage += ` - ${errorText}`;
|
|
163
|
+
throw new Error(errorMessage);
|
|
164
|
+
}
|
|
165
|
+
return await response.json();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
1
2
|
import "dotenv/config";
|
|
2
3
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
4
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
@@ -17,23 +18,18 @@ import { getTestsTool } from "./tools/get_tests.js";
|
|
|
17
18
|
import { addResultsTool } from "./tools/add_results.js";
|
|
18
19
|
import { addAttachmentToRunTool } from "./tools/add_attachment_to_run.js";
|
|
19
20
|
import { removeNullish } from "./utils/sanitizer.js";
|
|
20
|
-
|
|
21
21
|
const TESTRAIL_INSTANCE_URL = process.env.TESTRAIL_INSTANCE_URL;
|
|
22
22
|
const TESTRAIL_USERNAME = process.env.TESTRAIL_USERNAME;
|
|
23
23
|
const TESTRAIL_API_KEY = process.env.TESTRAIL_API_KEY;
|
|
24
|
-
|
|
25
24
|
if (!TESTRAIL_INSTANCE_URL || !TESTRAIL_USERNAME || !TESTRAIL_API_KEY) {
|
|
26
25
|
console.error("Error: TESTRAIL_INSTANCE_URL, TESTRAIL_USERNAME, and TESTRAIL_API_KEY environment variables are required.");
|
|
27
26
|
process.exit(1);
|
|
28
27
|
}
|
|
29
|
-
|
|
30
28
|
const server = new McpServer({
|
|
31
29
|
name: "TestRail MCP Server",
|
|
32
|
-
version: "1.3.
|
|
30
|
+
version: "1.3.1",
|
|
33
31
|
});
|
|
34
|
-
|
|
35
32
|
const client = new TestRailClient(TESTRAIL_INSTANCE_URL, TESTRAIL_USERNAME, TESTRAIL_API_KEY);
|
|
36
|
-
|
|
37
33
|
const tools = [
|
|
38
34
|
getProjectsTool,
|
|
39
35
|
getCaseTool,
|
|
@@ -49,37 +45,31 @@ const tools = [
|
|
|
49
45
|
getTestsTool,
|
|
50
46
|
addResultsTool,
|
|
51
47
|
addAttachmentToRunTool,
|
|
52
|
-
]
|
|
53
|
-
|
|
48
|
+
];
|
|
54
49
|
for (const tool of tools) {
|
|
55
|
-
server.registerTool(
|
|
56
|
-
tool.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
text: JSON.stringify(sanitized),
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
} as any;
|
|
74
|
-
} catch (error: any) {
|
|
75
|
-
return {
|
|
76
|
-
content: [{ type: "text", text: `Error: ${error.message}` }],
|
|
77
|
-
isError: true,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
50
|
+
server.registerTool(tool.name, {
|
|
51
|
+
description: tool.description,
|
|
52
|
+
inputSchema: tool.parameters,
|
|
53
|
+
}, async (args) => {
|
|
54
|
+
try {
|
|
55
|
+
const output = await tool.handler(args, client);
|
|
56
|
+
const sanitized = removeNullish(output);
|
|
57
|
+
return {
|
|
58
|
+
content: [
|
|
59
|
+
{
|
|
60
|
+
type: "text",
|
|
61
|
+
text: JSON.stringify(sanitized),
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
};
|
|
80
65
|
}
|
|
81
|
-
|
|
66
|
+
catch (error) {
|
|
67
|
+
return {
|
|
68
|
+
content: [{ type: "text", text: `Error: ${error.message}` }],
|
|
69
|
+
isError: true,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
});
|
|
82
73
|
}
|
|
83
|
-
|
|
84
74
|
const transport = new StdioServerTransport();
|
|
85
75
|
await server.connect(transport);
|
|
@@ -1,59 +1,49 @@
|
|
|
1
|
-
import { TestRailClient } from "../client/testrail.js";
|
|
2
1
|
import { z } from "zod";
|
|
3
2
|
import { AttachmentSchema } from "../types/testrail.js";
|
|
4
3
|
import * as fs from "fs";
|
|
5
4
|
import * as path from "path";
|
|
6
5
|
import * as os from "os";
|
|
7
6
|
import archiver from "archiver";
|
|
8
|
-
import { ToolDefinition } from "../types/custom.js";
|
|
9
|
-
|
|
10
7
|
const parameters = {
|
|
11
8
|
run_id: z.string().describe("The ID of the test run to attach the file to"),
|
|
12
9
|
file_path: z.string().describe("The path to the file or directory to attach. Directories will be automatically zipped."),
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const addAttachmentToRunTool: ToolDefinition<typeof parameters, TestRailClient> = {
|
|
10
|
+
};
|
|
11
|
+
export const addAttachmentToRunTool = {
|
|
16
12
|
name: "add_attachment_to_run",
|
|
17
13
|
description: "Add an attachment to a test run in TestRail. If the file_path points to a directory, it will be automatically zipped before uploading. Maximum upload size is 256MB.",
|
|
18
14
|
parameters,
|
|
19
|
-
handler: async ({ run_id, file_path }, client
|
|
15
|
+
handler: async ({ run_id, file_path }, client) => {
|
|
20
16
|
if (!fs.existsSync(file_path)) {
|
|
21
17
|
throw new Error(`File or directory not found: ${file_path}`);
|
|
22
18
|
}
|
|
23
|
-
|
|
24
19
|
const stats = fs.statSync(file_path);
|
|
25
|
-
let uploadPath
|
|
26
|
-
let filename
|
|
20
|
+
let uploadPath = file_path;
|
|
21
|
+
let filename = path.basename(file_path);
|
|
27
22
|
let isTemporary = false;
|
|
28
|
-
|
|
29
23
|
if (stats.isDirectory()) {
|
|
30
24
|
const basename = path.basename(file_path);
|
|
31
25
|
const tempDir = os.tmpdir();
|
|
32
26
|
const zipPath = path.join(tempDir, `${basename}-${Date.now()}.zip`);
|
|
33
|
-
|
|
34
|
-
await new Promise<void>((resolve, reject) => {
|
|
27
|
+
await new Promise((resolve, reject) => {
|
|
35
28
|
const output = fs.createWriteStream(zipPath);
|
|
36
29
|
const archive = archiver('zip', {
|
|
37
30
|
zlib: { level: 9 }
|
|
38
31
|
});
|
|
39
|
-
|
|
40
32
|
output.on('close', () => resolve());
|
|
41
33
|
archive.on('error', (err) => reject(err));
|
|
42
|
-
|
|
43
34
|
archive.pipe(output);
|
|
44
35
|
archive.directory(file_path, basename);
|
|
45
36
|
archive.finalize();
|
|
46
37
|
});
|
|
47
|
-
|
|
48
38
|
uploadPath = zipPath;
|
|
49
39
|
filename = `${basename}.zip`;
|
|
50
40
|
isTemporary = true;
|
|
51
41
|
}
|
|
52
|
-
|
|
53
42
|
try {
|
|
54
43
|
const result = await client.addAttachmentToRun(Number(run_id), uploadPath, filename);
|
|
55
44
|
return AttachmentSchema.parse(result);
|
|
56
|
-
}
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
57
47
|
if (isTemporary && fs.existsSync(uploadPath)) {
|
|
58
48
|
fs.unlinkSync(uploadPath);
|
|
59
49
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { TestRailClient } from "../client/testrail.js";
|
|
2
1
|
import { z } from "zod";
|
|
3
2
|
import { ResultSchema } from "../types/testrail.js";
|
|
4
|
-
import { ToolDefinition } from "../types/custom.js";
|
|
5
|
-
|
|
6
3
|
const parameters = {
|
|
7
4
|
run_id: z.number().describe("The ID of the test run"),
|
|
8
5
|
results: z.array(z.object({
|
|
@@ -11,13 +8,12 @@ const parameters = {
|
|
|
11
8
|
comment: z.string().optional().describe("Optional comment/description for the result"),
|
|
12
9
|
defects: z.string().optional().describe("Optional comma-separated list of defect IDs"),
|
|
13
10
|
})).describe("Array of results to add. Each result must have test_id and status_id"),
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const addResultsTool: ToolDefinition<typeof parameters, TestRailClient> = {
|
|
11
|
+
};
|
|
12
|
+
export const addResultsTool = {
|
|
17
13
|
name: "add_results",
|
|
18
14
|
description: "Add one or more test results to a test run",
|
|
19
15
|
parameters,
|
|
20
|
-
handler: async ({ run_id, results }, client
|
|
16
|
+
handler: async ({ run_id, results }, client) => {
|
|
21
17
|
const response = await client.addResults(run_id, results);
|
|
22
18
|
return {
|
|
23
19
|
success: true,
|
|
@@ -1,24 +1,19 @@
|
|
|
1
|
-
import { TestRailClient } from "../client/testrail.js";
|
|
2
1
|
import { z } from "zod";
|
|
3
2
|
import { RunSchema } from "../types/testrail.js";
|
|
4
|
-
import { ToolDefinition } from "../types/custom.js";
|
|
5
|
-
|
|
6
3
|
const parameters = {
|
|
7
4
|
project_id: z.string().describe("The ID of the project. Use get_projects to find available projects"),
|
|
8
5
|
name: z.string().optional().describe("The name of the test run"),
|
|
9
6
|
description: z.string().optional().describe("The description of the test run"),
|
|
10
7
|
case_ids: z.array(z.number()).describe("Array of case IDs to include in the run. After creating the run, use get_tests with the returned run_id to retrieve test IDs for result submission")
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const addRunTool: ToolDefinition<typeof parameters, TestRailClient> = {
|
|
8
|
+
};
|
|
9
|
+
export const addRunTool = {
|
|
14
10
|
name: "add_run",
|
|
15
11
|
description: "Create a new test run in TestRail",
|
|
16
12
|
parameters,
|
|
17
|
-
handler: async ({ project_id, ...fields }, client
|
|
13
|
+
handler: async ({ project_id, ...fields }, client) => {
|
|
18
14
|
const caseData = await client.getCase(String(fields.case_ids[0]));
|
|
19
15
|
const params = { suite_id: caseData.suite_id, include_all: false, ...fields };
|
|
20
16
|
const run = await client.addRun(project_id, params);
|
|
21
|
-
|
|
22
17
|
return RunSchema.parse(run);
|
|
23
18
|
},
|
|
24
19
|
};
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { TestRailClient } from "../client/testrail.js";
|
|
3
|
-
import { ToolDefinition } from "../types/custom.js";
|
|
4
|
-
|
|
5
2
|
const parameters = {
|
|
6
3
|
section_id: z.string().describe("The ID of the section where the case should be created. Use get_sections to find available sections"),
|
|
7
4
|
title: z.string().describe("The title of the test case"),
|
|
8
5
|
fields: z.record(z.string(), z.any()).optional().describe("Optional fields for the test case. First use get_templates to discover available templates, then get_case_fields to see available fields for your template. Example: {\"priority_id\": 2, \"template_id\": 1, \"custom_automation_priority\": 1}"),
|
|
9
6
|
};
|
|
10
|
-
|
|
11
|
-
export const createCaseTool: ToolDefinition<typeof parameters, TestRailClient> = {
|
|
7
|
+
export const createCaseTool = {
|
|
12
8
|
name: "create_case",
|
|
13
9
|
description: "Create a new test case in TestRail",
|
|
14
10
|
parameters,
|
|
@@ -17,9 +13,7 @@ export const createCaseTool: ToolDefinition<typeof parameters, TestRailClient> =
|
|
|
17
13
|
title,
|
|
18
14
|
...fields,
|
|
19
15
|
};
|
|
20
|
-
|
|
21
16
|
const createdCase = await client.createCase(section_id, caseData);
|
|
22
|
-
|
|
23
17
|
return {
|
|
24
18
|
success: true,
|
|
25
19
|
case_id: createdCase.id,
|
|
@@ -1,33 +1,25 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { processCustomFields } from "../utils/mapper.js";
|
|
3
|
-
import { TestRailClient } from "../client/testrail.js";
|
|
4
|
-
import { TestCaseResponse, ToolDefinition } from "../types/custom.js";
|
|
5
|
-
|
|
6
3
|
const parameters = {
|
|
7
4
|
case_id: z.string().describe("The ID of the test case (e.g. '123' or 'C123')"),
|
|
8
5
|
};
|
|
9
|
-
|
|
10
|
-
export const getCaseTool: ToolDefinition<typeof parameters, TestRailClient> = {
|
|
6
|
+
export const getCaseTool = {
|
|
11
7
|
name: "get_case",
|
|
12
8
|
description: "Get detailed information about a test case including its custom fields",
|
|
13
9
|
parameters,
|
|
14
10
|
handler: async ({ case_id }, client) => {
|
|
15
11
|
const id = case_id.toUpperCase().startsWith("C") ? case_id.substring(1) : case_id;
|
|
16
12
|
const testCase = await client.getCase(id);
|
|
17
|
-
|
|
18
13
|
const [section, caseTypes, priorities, caseFields] = await Promise.all([
|
|
19
14
|
client.getSection(testCase.section_id.toString()),
|
|
20
15
|
client.getCaseTypes(),
|
|
21
16
|
client.getPriorities(),
|
|
22
17
|
client.getCaseFields()
|
|
23
18
|
]);
|
|
24
|
-
|
|
25
19
|
const caseType = caseTypes.find(t => t.id === testCase.type_id);
|
|
26
20
|
const priority = priorities.find(p => p.id === testCase.priority_id);
|
|
27
|
-
|
|
28
21
|
const customFields = processCustomFields(testCase, caseFields);
|
|
29
|
-
|
|
30
|
-
const response: TestCaseResponse = {
|
|
22
|
+
const response = {
|
|
31
23
|
id: testCase.id,
|
|
32
24
|
title: testCase.title,
|
|
33
25
|
section: section.name,
|
|
@@ -38,7 +30,6 @@ export const getCaseTool: ToolDefinition<typeof parameters, TestRailClient> = {
|
|
|
38
30
|
updated_on: testCase.updated_on,
|
|
39
31
|
...customFields
|
|
40
32
|
};
|
|
41
|
-
|
|
42
33
|
return response;
|
|
43
34
|
}
|
|
44
35
|
};
|
|
@@ -1,24 +1,6 @@
|
|
|
1
|
-
import { TestRailClient } from "../client/testrail.js";
|
|
2
|
-
import { ToolDefinition } from "../types/custom.js";
|
|
3
|
-
import { CaseField } from "../types/testrail.js";
|
|
4
1
|
import { parseDropdownOptions } from "../utils/mapper.js";
|
|
5
|
-
|
|
6
2
|
const parameters = {};
|
|
7
|
-
|
|
8
|
-
interface FieldSchema {
|
|
9
|
-
system_name: string;
|
|
10
|
-
label: string;
|
|
11
|
-
type: string;
|
|
12
|
-
is_required: boolean;
|
|
13
|
-
template_ids?: number[];
|
|
14
|
-
options?: string[];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface CaseFieldsResponse {
|
|
18
|
-
fields: FieldSchema[];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const FIELD_TYPE_NAMES: Record<number, string> = {
|
|
3
|
+
const FIELD_TYPE_NAMES = {
|
|
22
4
|
1: "String",
|
|
23
5
|
2: "Integer",
|
|
24
6
|
3: "Text",
|
|
@@ -33,35 +15,28 @@ const FIELD_TYPE_NAMES: Record<number, string> = {
|
|
|
33
15
|
12: "Multi-select",
|
|
34
16
|
13: "Scenarios",
|
|
35
17
|
};
|
|
36
|
-
|
|
37
|
-
function getFieldTypeName(typeId: number): string {
|
|
18
|
+
function getFieldTypeName(typeId) {
|
|
38
19
|
return FIELD_TYPE_NAMES[typeId] || `Unknown (${typeId})`;
|
|
39
20
|
}
|
|
40
|
-
|
|
41
|
-
function isFieldRequired(field: CaseField): boolean {
|
|
21
|
+
function isFieldRequired(field) {
|
|
42
22
|
return field.configs.some(config => config.options?.is_required === true);
|
|
43
23
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const schema: FieldSchema = {
|
|
24
|
+
function mapToFieldSchema(field) {
|
|
25
|
+
const schema = {
|
|
47
26
|
system_name: field.system_name,
|
|
48
27
|
label: field.label,
|
|
49
28
|
type: getFieldTypeName(field.type_id),
|
|
50
29
|
is_required: isFieldRequired(field),
|
|
51
30
|
};
|
|
52
|
-
|
|
53
31
|
if (!field.include_all && field.template_ids.length > 0) {
|
|
54
32
|
schema.template_ids = field.template_ids;
|
|
55
33
|
}
|
|
56
|
-
|
|
57
34
|
if (field.type_id === 6 || field.type_id === 12) {
|
|
58
35
|
schema.options = Array.from(parseDropdownOptions(field).values());
|
|
59
36
|
}
|
|
60
|
-
|
|
61
37
|
return schema;
|
|
62
38
|
}
|
|
63
|
-
|
|
64
|
-
const SYSTEM_FIELDS: FieldSchema[] = [
|
|
39
|
+
const SYSTEM_FIELDS = [
|
|
65
40
|
{ system_name: "title", label: "Title", type: "String", is_required: true },
|
|
66
41
|
{ system_name: "section_id", label: "Section", type: "Integer", is_required: true },
|
|
67
42
|
{ system_name: "template_id", label: "Template", type: "Integer", is_required: false },
|
|
@@ -71,20 +46,16 @@ const SYSTEM_FIELDS: FieldSchema[] = [
|
|
|
71
46
|
{ system_name: "milestone_id", label: "Milestone", type: "Integer", is_required: false },
|
|
72
47
|
{ system_name: "refs", label: "References", type: "String", is_required: false },
|
|
73
48
|
];
|
|
74
|
-
|
|
75
|
-
export const getCaseFieldsTool: ToolDefinition<typeof parameters, TestRailClient> = {
|
|
49
|
+
export const getCaseFieldsTool = {
|
|
76
50
|
name: "get_case_fields",
|
|
77
51
|
description: "Get the field schema for test cases. Returns all available fields with their types, descriptions, and options (for dropdown fields). Use this to understand what fields can be set when creating or updating test cases.",
|
|
78
52
|
parameters,
|
|
79
53
|
handler: async (_args, client) => {
|
|
80
54
|
const caseFields = await client.getCaseFields();
|
|
81
|
-
|
|
82
55
|
const customFieldSchemas = caseFields.filter(field => field.is_active).map(mapToFieldSchema);
|
|
83
|
-
|
|
84
|
-
const response: CaseFieldsResponse = {
|
|
56
|
+
const response = {
|
|
85
57
|
fields: [...SYSTEM_FIELDS, ...customFieldSchemas],
|
|
86
58
|
};
|
|
87
|
-
|
|
88
59
|
return response;
|
|
89
60
|
}
|
|
90
61
|
};
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { TestRailClient } from "../client/testrail.js";
|
|
3
|
-
import { ToolDefinition } from "../types/custom.js";
|
|
4
|
-
import { Case } from "../types/testrail.js";
|
|
5
|
-
|
|
6
2
|
const parameters = {
|
|
7
3
|
project_id: z.string().describe("The ID of the project. Use get_projects to find available projects"),
|
|
8
4
|
section_id: z.string().optional().describe("Optional section ID to filter cases by section. Use get_sections to find available sections"),
|
|
@@ -10,23 +6,17 @@ const parameters = {
|
|
|
10
6
|
where: z.record(z.string(), z.any()).optional().describe("Optional client-side filter for any field including custom fields (filters after fetching all cases). Supports exact value matching. Example: {\"custom_automation_status\": 1, \"priority_id\": 2}"),
|
|
11
7
|
fields: z.array(z.string()).optional().describe("Additional fields to include in response beyond id, title, and suite_id. Use get_case_fields to see available fields. Example: [\"priority_id\", \"type_id\", \"custom_automation_status\"]"),
|
|
12
8
|
};
|
|
13
|
-
|
|
14
|
-
interface CasesResponse {
|
|
15
|
-
cases: Record<string, any>[];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const getCasesTool: ToolDefinition<typeof parameters, TestRailClient> = {
|
|
9
|
+
export const getCasesTool = {
|
|
19
10
|
name: "get_cases",
|
|
20
11
|
description: "Get all test cases for a project. Filter by section, API params (priority, type), or any field including custom fields via 'where'. Returns case IDs, titles, and any additional requested fields.",
|
|
21
12
|
parameters,
|
|
22
13
|
handler: async ({ project_id, section_id, filter, where, fields }, client) => {
|
|
23
|
-
let cases
|
|
24
|
-
|
|
14
|
+
let cases = await client.getCases(project_id, section_id, filter);
|
|
25
15
|
// Client-side filtering for custom fields and other unsupported API filters
|
|
26
16
|
if (where) {
|
|
27
17
|
cases = cases.filter(c => {
|
|
28
18
|
for (const [key, value] of Object.entries(where)) {
|
|
29
|
-
const caseValue =
|
|
19
|
+
const caseValue = c[key];
|
|
30
20
|
if (caseValue !== value) {
|
|
31
21
|
return false;
|
|
32
22
|
}
|
|
@@ -34,15 +24,13 @@ export const getCasesTool: ToolDefinition<typeof parameters, TestRailClient> = {
|
|
|
34
24
|
return true;
|
|
35
25
|
});
|
|
36
26
|
}
|
|
37
|
-
|
|
38
|
-
const response: CasesResponse = {
|
|
27
|
+
const response = {
|
|
39
28
|
cases: cases.map(c => {
|
|
40
|
-
const result
|
|
29
|
+
const result = {
|
|
41
30
|
id: c.id,
|
|
42
31
|
title: c.title,
|
|
43
32
|
suite_id: c.suite_id,
|
|
44
33
|
};
|
|
45
|
-
|
|
46
34
|
if (fields) {
|
|
47
35
|
for (const field of fields) {
|
|
48
36
|
if (field in c) {
|
|
@@ -50,11 +38,9 @@ export const getCasesTool: ToolDefinition<typeof parameters, TestRailClient> = {
|
|
|
50
38
|
}
|
|
51
39
|
}
|
|
52
40
|
}
|
|
53
|
-
|
|
54
41
|
return result;
|
|
55
42
|
}),
|
|
56
43
|
};
|
|
57
|
-
|
|
58
44
|
return response;
|
|
59
45
|
}
|
|
60
46
|
};
|
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
import { TestRailClient } from "../client/testrail.js";
|
|
2
|
-
import { ToolDefinition } from "../types/custom.js";
|
|
3
1
|
import { ProjectSchema } from "../types/testrail.js";
|
|
4
|
-
|
|
5
2
|
const parameters = {};
|
|
6
|
-
|
|
7
|
-
export const getProjectsTool: ToolDefinition<typeof parameters, TestRailClient> = {
|
|
3
|
+
export const getProjectsTool = {
|
|
8
4
|
name: "get_projects",
|
|
9
5
|
description: "Get all available projects in TestRail. Returns project IDs and names that can be used with get_sections, get_templates, get_cases, and add_run",
|
|
10
6
|
parameters,
|
|
11
7
|
handler: async (_args, client) => {
|
|
12
8
|
const projects = await client.getProjects();
|
|
13
|
-
|
|
14
9
|
return {
|
|
15
10
|
projects: projects
|
|
16
11
|
.filter(p => !p.is_completed)
|
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { TestRailClient } from "../client/testrail.js";
|
|
3
|
-
import { ToolDefinition } from "../types/custom.js";
|
|
4
2
|
import { SectionSchema } from "../types/testrail.js";
|
|
5
|
-
|
|
6
3
|
const parameters = {
|
|
7
4
|
project_id: z.string().describe("The ID of the project. Use get_projects to find available projects"),
|
|
8
5
|
};
|
|
9
|
-
|
|
10
|
-
export const getSectionsTool: ToolDefinition<typeof parameters, TestRailClient> = {
|
|
6
|
+
export const getSectionsTool = {
|
|
11
7
|
name: "get_sections",
|
|
12
8
|
description: "Get all sections for a project. Returns section IDs and names that can be used with create_case",
|
|
13
9
|
parameters,
|
|
14
10
|
handler: async ({ project_id }, client) => {
|
|
15
11
|
const sections = await client.getSections(project_id);
|
|
16
|
-
|
|
17
12
|
return {
|
|
18
13
|
sections: sections.map(s => SectionSchema.parse(s)),
|
|
19
14
|
};
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import { TestRailClient } from "../client/testrail.js";
|
|
2
|
-
import { z } from "zod";
|
|
3
1
|
import { StatusSchema } from "../types/testrail.js";
|
|
4
|
-
import { ToolDefinition } from "../types/custom.js";
|
|
5
|
-
|
|
6
2
|
const parameters = {};
|
|
7
|
-
|
|
8
|
-
export const getStatusesTool: ToolDefinition<typeof parameters, TestRailClient> = {
|
|
3
|
+
export const getStatusesTool = {
|
|
9
4
|
name: "get_statuses",
|
|
10
5
|
description: "Get all available test statuses (e.g. Passed, Failed, Blocked). Returns status IDs and names that can be used with add_result and get_tests",
|
|
11
6
|
parameters,
|
|
12
|
-
handler: async (args
|
|
7
|
+
handler: async (args, client) => {
|
|
13
8
|
const statuses = await client.getStatuses();
|
|
14
9
|
return {
|
|
15
10
|
statuses: statuses.map(s => StatusSchema.parse(s)),
|