@azure-devops/mcp 2.2.2 → 2.3.0-nightly.20251203
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/README.md +1 -105
- package/dist/auth.js +27 -1
- package/dist/index.js +12 -1
- package/dist/logger.js +34 -0
- package/dist/org-tenants.js +4 -3
- package/dist/prompts.js +0 -0
- package/dist/shared/domains.js +2 -1
- package/dist/tools/pipelines.js +52 -4
- package/dist/tools/repositories.js +621 -360
- package/dist/tools/test-plans.js +256 -123
- package/dist/tools/work-items.js +398 -210
- package/dist/tools/work.js +22 -3
- package/dist/tools.js +0 -0
- package/dist/useragent.js +0 -0
- package/dist/utils.js +0 -0
- package/dist/version.js +1 -1
- package/package.json +16 -7
- package/dist/domains.js +0 -1
- package/dist/http.js +0 -52
- package/dist/orgtenants.js +0 -73
- package/dist/server.js +0 -36
- package/dist/tenant.js +0 -73
- package/dist/tools/advsec.js +0 -108
- package/dist/tools/builds.js +0 -271
- package/dist/tools/releases.js +0 -97
- package/dist/tools/repos.js +0 -666
- package/dist/tools/testplans.js +0 -213
- package/dist/tools/workitems.js +0 -809
package/dist/tools/repos.js
DELETED
|
@@ -1,666 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
import { PullRequestStatus, GitVersionType, GitPullRequestQueryType, CommentThreadStatus, } from "azure-devops-node-api/interfaces/GitInterfaces.js";
|
|
4
|
-
import { z } from "zod";
|
|
5
|
-
import { getCurrentUserDetails, getUserIdFromEmail } from "./auth.js";
|
|
6
|
-
import { getEnumKeys } from "../utils.js";
|
|
7
|
-
const REPO_TOOLS = {
|
|
8
|
-
list_repos_by_project: "repo_list_repos_by_project",
|
|
9
|
-
list_pull_requests_by_repo: "repo_list_pull_requests_by_repo",
|
|
10
|
-
list_pull_requests_by_project: "repo_list_pull_requests_by_project",
|
|
11
|
-
list_branches_by_repo: "repo_list_branches_by_repo",
|
|
12
|
-
list_my_branches_by_repo: "repo_list_my_branches_by_repo",
|
|
13
|
-
list_pull_request_threads: "repo_list_pull_request_threads",
|
|
14
|
-
list_pull_request_thread_comments: "repo_list_pull_request_thread_comments",
|
|
15
|
-
get_repo_by_name_or_id: "repo_get_repo_by_name_or_id",
|
|
16
|
-
get_branch_by_name: "repo_get_branch_by_name",
|
|
17
|
-
get_pull_request_by_id: "repo_get_pull_request_by_id",
|
|
18
|
-
create_pull_request: "repo_create_pull_request",
|
|
19
|
-
update_pull_request: "repo_update_pull_request",
|
|
20
|
-
update_pull_request_reviewers: "repo_update_pull_request_reviewers",
|
|
21
|
-
reply_to_comment: "repo_reply_to_comment",
|
|
22
|
-
create_pull_request_thread: "repo_create_pull_request_thread",
|
|
23
|
-
resolve_comment: "repo_resolve_comment",
|
|
24
|
-
search_commits: "repo_search_commits",
|
|
25
|
-
list_pull_requests_by_commits: "repo_list_pull_requests_by_commits",
|
|
26
|
-
};
|
|
27
|
-
function branchesFilterOutIrrelevantProperties(branches, top) {
|
|
28
|
-
return branches
|
|
29
|
-
?.flatMap((branch) => (branch.name ? [branch.name] : []))
|
|
30
|
-
?.filter((branch) => branch.startsWith("refs/heads/"))
|
|
31
|
-
.map((branch) => branch.replace("refs/heads/", ""))
|
|
32
|
-
.sort((a, b) => b.localeCompare(a))
|
|
33
|
-
.slice(0, top);
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Trims comment data to essential properties, filtering out deleted comments
|
|
37
|
-
* @param comments Array of comments to trim (can be undefined/null)
|
|
38
|
-
* @returns Array of trimmed comment objects with essential properties only
|
|
39
|
-
*/
|
|
40
|
-
function trimComments(comments) {
|
|
41
|
-
return comments
|
|
42
|
-
?.filter((comment) => !comment.isDeleted) // Exclude deleted comments
|
|
43
|
-
?.map((comment) => ({
|
|
44
|
-
id: comment.id,
|
|
45
|
-
author: {
|
|
46
|
-
displayName: comment.author?.displayName,
|
|
47
|
-
uniqueName: comment.author?.uniqueName,
|
|
48
|
-
},
|
|
49
|
-
content: comment.content,
|
|
50
|
-
publishedDate: comment.publishedDate,
|
|
51
|
-
lastUpdatedDate: comment.lastUpdatedDate,
|
|
52
|
-
lastContentUpdatedDate: comment.lastContentUpdatedDate,
|
|
53
|
-
}));
|
|
54
|
-
}
|
|
55
|
-
function pullRequestStatusStringToInt(status) {
|
|
56
|
-
switch (status) {
|
|
57
|
-
case "Abandoned":
|
|
58
|
-
return PullRequestStatus.Abandoned.valueOf();
|
|
59
|
-
case "Active":
|
|
60
|
-
return PullRequestStatus.Active.valueOf();
|
|
61
|
-
case "All":
|
|
62
|
-
return PullRequestStatus.All.valueOf();
|
|
63
|
-
case "Completed":
|
|
64
|
-
return PullRequestStatus.Completed.valueOf();
|
|
65
|
-
case "NotSet":
|
|
66
|
-
return PullRequestStatus.NotSet.valueOf();
|
|
67
|
-
default:
|
|
68
|
-
throw new Error(`Unknown pull request status: ${status}`);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
function filterReposByName(repositories, repoNameFilter) {
|
|
72
|
-
const lowerCaseFilter = repoNameFilter.toLowerCase();
|
|
73
|
-
const filteredByName = repositories?.filter((repo) => repo.name?.toLowerCase().includes(lowerCaseFilter));
|
|
74
|
-
return filteredByName;
|
|
75
|
-
}
|
|
76
|
-
function configureRepoTools(server, tokenProvider, connectionProvider, userAgentProvider) {
|
|
77
|
-
server.tool(REPO_TOOLS.create_pull_request, "Create a new pull request.", {
|
|
78
|
-
repositoryId: z.string().describe("The ID of the repository where the pull request will be created."),
|
|
79
|
-
sourceRefName: z.string().describe("The source branch name for the pull request, e.g., 'refs/heads/feature-branch'."),
|
|
80
|
-
targetRefName: z.string().describe("The target branch name for the pull request, e.g., 'refs/heads/main'."),
|
|
81
|
-
title: z.string().describe("The title of the pull request."),
|
|
82
|
-
description: z.string().optional().describe("The description of the pull request. Optional."),
|
|
83
|
-
isDraft: z.boolean().optional().default(false).describe("Indicates whether the pull request is a draft. Defaults to false."),
|
|
84
|
-
workItems: z.string().optional().describe("Work item IDs to associate with the pull request, space-separated."),
|
|
85
|
-
forkSourceRepositoryId: z.string().optional().describe("The ID of the fork repository that the pull request originates from. Optional, used when creating a pull request from a fork."),
|
|
86
|
-
}, async ({ repositoryId, sourceRefName, targetRefName, title, description, isDraft, workItems, forkSourceRepositoryId }) => {
|
|
87
|
-
const connection = await connectionProvider();
|
|
88
|
-
const gitApi = await connection.getGitApi();
|
|
89
|
-
const workItemRefs = workItems ? workItems.split(" ").map((id) => ({ id: id.trim() })) : [];
|
|
90
|
-
const forkSource = forkSourceRepositoryId
|
|
91
|
-
? {
|
|
92
|
-
repository: {
|
|
93
|
-
id: forkSourceRepositoryId,
|
|
94
|
-
},
|
|
95
|
-
}
|
|
96
|
-
: undefined;
|
|
97
|
-
const pullRequest = await gitApi.createPullRequest({
|
|
98
|
-
sourceRefName,
|
|
99
|
-
targetRefName,
|
|
100
|
-
title,
|
|
101
|
-
description,
|
|
102
|
-
isDraft,
|
|
103
|
-
workItemRefs: workItemRefs,
|
|
104
|
-
forkSource,
|
|
105
|
-
}, repositoryId);
|
|
106
|
-
return {
|
|
107
|
-
content: [{ type: "text", text: JSON.stringify(pullRequest, null, 2) }],
|
|
108
|
-
};
|
|
109
|
-
});
|
|
110
|
-
server.tool(REPO_TOOLS.update_pull_request, "Update a Pull Request by ID with specified fields.", {
|
|
111
|
-
repositoryId: z.string().describe("The ID of the repository where the pull request exists."),
|
|
112
|
-
pullRequestId: z.number().describe("The ID of the pull request to update."),
|
|
113
|
-
title: z.string().optional().describe("The new title for the pull request."),
|
|
114
|
-
description: z.string().optional().describe("The new description for the pull request."),
|
|
115
|
-
isDraft: z.boolean().optional().describe("Whether the pull request should be a draft."),
|
|
116
|
-
targetRefName: z.string().optional().describe("The new target branch name (e.g., 'refs/heads/main')."),
|
|
117
|
-
status: z.enum(["Active", "Abandoned"]).optional().describe("The new status of the pull request. Can be 'Active' or 'Abandoned'."),
|
|
118
|
-
}, async ({ repositoryId, pullRequestId, title, description, isDraft, targetRefName, status }) => {
|
|
119
|
-
const connection = await connectionProvider();
|
|
120
|
-
const gitApi = await connection.getGitApi();
|
|
121
|
-
// Build update object with only provided fields
|
|
122
|
-
const updateRequest = {};
|
|
123
|
-
if (title !== undefined)
|
|
124
|
-
updateRequest.title = title;
|
|
125
|
-
if (description !== undefined)
|
|
126
|
-
updateRequest.description = description;
|
|
127
|
-
if (isDraft !== undefined)
|
|
128
|
-
updateRequest.isDraft = isDraft;
|
|
129
|
-
if (targetRefName !== undefined)
|
|
130
|
-
updateRequest.targetRefName = targetRefName;
|
|
131
|
-
if (status !== undefined) {
|
|
132
|
-
updateRequest.status = status === "Active" ? PullRequestStatus.Active.valueOf() : PullRequestStatus.Abandoned.valueOf();
|
|
133
|
-
}
|
|
134
|
-
// Validate that at least one field is provided for update
|
|
135
|
-
if (Object.keys(updateRequest).length === 0) {
|
|
136
|
-
return {
|
|
137
|
-
content: [{ type: "text", text: "Error: At least one field (title, description, isDraft, targetRefName, or status) must be provided for update." }],
|
|
138
|
-
isError: true,
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
const updatedPullRequest = await gitApi.updatePullRequest(updateRequest, repositoryId, pullRequestId);
|
|
142
|
-
return {
|
|
143
|
-
content: [{ type: "text", text: JSON.stringify(updatedPullRequest, null, 2) }],
|
|
144
|
-
};
|
|
145
|
-
});
|
|
146
|
-
server.tool(REPO_TOOLS.update_pull_request_reviewers, "Add or remove reviewers for an existing pull request.", {
|
|
147
|
-
repositoryId: z.string().describe("The ID of the repository where the pull request exists."),
|
|
148
|
-
pullRequestId: z.number().describe("The ID of the pull request to update."),
|
|
149
|
-
reviewerIds: z.array(z.string()).describe("List of reviewer ids to add or remove from the pull request."),
|
|
150
|
-
action: z.enum(["add", "remove"]).describe("Action to perform on the reviewers. Can be 'add' or 'remove'."),
|
|
151
|
-
}, async ({ repositoryId, pullRequestId, reviewerIds, action }) => {
|
|
152
|
-
const connection = await connectionProvider();
|
|
153
|
-
const gitApi = await connection.getGitApi();
|
|
154
|
-
let updatedPullRequest;
|
|
155
|
-
if (action === "add") {
|
|
156
|
-
updatedPullRequest = await gitApi.createPullRequestReviewers(reviewerIds.map((id) => ({ id: id })), repositoryId, pullRequestId);
|
|
157
|
-
return {
|
|
158
|
-
content: [{ type: "text", text: JSON.stringify(updatedPullRequest, null, 2) }],
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
else {
|
|
162
|
-
for (const reviewerId of reviewerIds) {
|
|
163
|
-
await gitApi.deletePullRequestReviewer(repositoryId, pullRequestId, reviewerId);
|
|
164
|
-
}
|
|
165
|
-
return {
|
|
166
|
-
content: [{ type: "text", text: `Reviewers with IDs ${reviewerIds.join(", ")} removed from pull request ${pullRequestId}.` }],
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
server.tool(REPO_TOOLS.list_repos_by_project, "Retrieve a list of repositories for a given project", {
|
|
171
|
-
project: z.string().describe("The name or ID of the Azure DevOps project."),
|
|
172
|
-
top: z.number().default(100).describe("The maximum number of repositories to return."),
|
|
173
|
-
skip: z.number().default(0).describe("The number of repositories to skip. Defaults to 0."),
|
|
174
|
-
repoNameFilter: z.string().optional().describe("Optional filter to search for repositories by name. If provided, only repositories with names containing this string will be returned."),
|
|
175
|
-
}, async ({ project, top, skip, repoNameFilter }) => {
|
|
176
|
-
const connection = await connectionProvider();
|
|
177
|
-
const gitApi = await connection.getGitApi();
|
|
178
|
-
const repositories = await gitApi.getRepositories(project, false, false, false);
|
|
179
|
-
const filteredRepositories = repoNameFilter ? filterReposByName(repositories, repoNameFilter) : repositories;
|
|
180
|
-
const paginatedRepositories = filteredRepositories?.sort((a, b) => a.name?.localeCompare(b.name ?? "") ?? 0).slice(skip, skip + top);
|
|
181
|
-
// Filter out the irrelevant properties
|
|
182
|
-
const trimmedRepositories = paginatedRepositories?.map((repo) => ({
|
|
183
|
-
id: repo.id,
|
|
184
|
-
name: repo.name,
|
|
185
|
-
isDisabled: repo.isDisabled,
|
|
186
|
-
isFork: repo.isFork,
|
|
187
|
-
isInMaintenance: repo.isInMaintenance,
|
|
188
|
-
webUrl: repo.webUrl,
|
|
189
|
-
size: repo.size,
|
|
190
|
-
}));
|
|
191
|
-
return {
|
|
192
|
-
content: [{ type: "text", text: JSON.stringify(trimmedRepositories, null, 2) }],
|
|
193
|
-
};
|
|
194
|
-
});
|
|
195
|
-
server.tool(REPO_TOOLS.list_pull_requests_by_repo, "Retrieve a list of pull requests for a given repository.", {
|
|
196
|
-
repositoryId: z.string().describe("The ID of the repository where the pull requests are located."),
|
|
197
|
-
top: z.number().default(100).describe("The maximum number of pull requests to return."),
|
|
198
|
-
skip: z.number().default(0).describe("The number of pull requests to skip."),
|
|
199
|
-
created_by_me: z.boolean().default(false).describe("Filter pull requests created by the current user."),
|
|
200
|
-
created_by_user: z.string().optional().describe("Filter pull requests created by a specific user (provide email or unique name). Takes precedence over created_by_me if both are provided."),
|
|
201
|
-
i_am_reviewer: z.boolean().default(false).describe("Filter pull requests where the current user is a reviewer."),
|
|
202
|
-
status: z
|
|
203
|
-
.enum(getEnumKeys(PullRequestStatus))
|
|
204
|
-
.default("Active")
|
|
205
|
-
.describe("Filter pull requests by status. Defaults to 'Active'."),
|
|
206
|
-
}, async ({ repositoryId, top, skip, created_by_me, created_by_user, i_am_reviewer, status }) => {
|
|
207
|
-
const connection = await connectionProvider();
|
|
208
|
-
const gitApi = await connection.getGitApi();
|
|
209
|
-
// Build the search criteria
|
|
210
|
-
const searchCriteria = {
|
|
211
|
-
status: pullRequestStatusStringToInt(status),
|
|
212
|
-
repositoryId: repositoryId,
|
|
213
|
-
};
|
|
214
|
-
if (created_by_user) {
|
|
215
|
-
try {
|
|
216
|
-
const userId = await getUserIdFromEmail(created_by_user, tokenProvider, connectionProvider, userAgentProvider);
|
|
217
|
-
searchCriteria.creatorId = userId;
|
|
218
|
-
}
|
|
219
|
-
catch (error) {
|
|
220
|
-
return {
|
|
221
|
-
content: [
|
|
222
|
-
{
|
|
223
|
-
type: "text",
|
|
224
|
-
text: `Error finding user with email ${created_by_user}: ${error instanceof Error ? error.message : String(error)}`,
|
|
225
|
-
},
|
|
226
|
-
],
|
|
227
|
-
isError: true,
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
else if (created_by_me || i_am_reviewer) {
|
|
232
|
-
const data = await getCurrentUserDetails(tokenProvider, connectionProvider, userAgentProvider);
|
|
233
|
-
const userId = data.authenticatedUser.id;
|
|
234
|
-
if (created_by_me) {
|
|
235
|
-
searchCriteria.creatorId = userId;
|
|
236
|
-
}
|
|
237
|
-
if (i_am_reviewer) {
|
|
238
|
-
searchCriteria.reviewerId = userId;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
const pullRequests = await gitApi.getPullRequests(repositoryId, searchCriteria, undefined, // project
|
|
242
|
-
undefined, // maxCommentLength
|
|
243
|
-
skip, top);
|
|
244
|
-
// Filter out the irrelevant properties
|
|
245
|
-
const filteredPullRequests = pullRequests?.map((pr) => ({
|
|
246
|
-
pullRequestId: pr.pullRequestId,
|
|
247
|
-
codeReviewId: pr.codeReviewId,
|
|
248
|
-
status: pr.status,
|
|
249
|
-
createdBy: {
|
|
250
|
-
displayName: pr.createdBy?.displayName,
|
|
251
|
-
uniqueName: pr.createdBy?.uniqueName,
|
|
252
|
-
},
|
|
253
|
-
creationDate: pr.creationDate,
|
|
254
|
-
title: pr.title,
|
|
255
|
-
isDraft: pr.isDraft,
|
|
256
|
-
sourceRefName: pr.sourceRefName,
|
|
257
|
-
targetRefName: pr.targetRefName,
|
|
258
|
-
}));
|
|
259
|
-
return {
|
|
260
|
-
content: [{ type: "text", text: JSON.stringify(filteredPullRequests, null, 2) }],
|
|
261
|
-
};
|
|
262
|
-
});
|
|
263
|
-
server.tool(REPO_TOOLS.list_pull_requests_by_project, "Retrieve a list of pull requests for a given project Id or Name.", {
|
|
264
|
-
project: z.string().describe("The name or ID of the Azure DevOps project."),
|
|
265
|
-
top: z.number().default(100).describe("The maximum number of pull requests to return."),
|
|
266
|
-
skip: z.number().default(0).describe("The number of pull requests to skip."),
|
|
267
|
-
created_by_me: z.boolean().default(false).describe("Filter pull requests created by the current user."),
|
|
268
|
-
created_by_user: z.string().optional().describe("Filter pull requests created by a specific user (provide email or unique name). Takes precedence over created_by_me if both are provided."),
|
|
269
|
-
i_am_reviewer: z.boolean().default(false).describe("Filter pull requests where the current user is a reviewer."),
|
|
270
|
-
status: z
|
|
271
|
-
.enum(getEnumKeys(PullRequestStatus))
|
|
272
|
-
.default("Active")
|
|
273
|
-
.describe("Filter pull requests by status. Defaults to 'Active'."),
|
|
274
|
-
}, async ({ project, top, skip, created_by_me, created_by_user, i_am_reviewer, status }) => {
|
|
275
|
-
const connection = await connectionProvider();
|
|
276
|
-
const gitApi = await connection.getGitApi();
|
|
277
|
-
// Build the search criteria
|
|
278
|
-
const gitPullRequestSearchCriteria = {
|
|
279
|
-
status: pullRequestStatusStringToInt(status),
|
|
280
|
-
};
|
|
281
|
-
if (created_by_user) {
|
|
282
|
-
try {
|
|
283
|
-
const userId = await getUserIdFromEmail(created_by_user, tokenProvider, connectionProvider, userAgentProvider);
|
|
284
|
-
gitPullRequestSearchCriteria.creatorId = userId;
|
|
285
|
-
}
|
|
286
|
-
catch (error) {
|
|
287
|
-
return {
|
|
288
|
-
content: [
|
|
289
|
-
{
|
|
290
|
-
type: "text",
|
|
291
|
-
text: `Error finding user with email ${created_by_user}: ${error instanceof Error ? error.message : String(error)}`,
|
|
292
|
-
},
|
|
293
|
-
],
|
|
294
|
-
isError: true,
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
else if (created_by_me || i_am_reviewer) {
|
|
299
|
-
const data = await getCurrentUserDetails(tokenProvider, connectionProvider, userAgentProvider);
|
|
300
|
-
const userId = data.authenticatedUser.id;
|
|
301
|
-
if (created_by_me) {
|
|
302
|
-
gitPullRequestSearchCriteria.creatorId = userId;
|
|
303
|
-
}
|
|
304
|
-
if (i_am_reviewer) {
|
|
305
|
-
gitPullRequestSearchCriteria.reviewerId = userId;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
const pullRequests = await gitApi.getPullRequestsByProject(project, gitPullRequestSearchCriteria, undefined, // maxCommentLength
|
|
309
|
-
skip, top);
|
|
310
|
-
// Filter out the irrelevant properties
|
|
311
|
-
const filteredPullRequests = pullRequests?.map((pr) => ({
|
|
312
|
-
pullRequestId: pr.pullRequestId,
|
|
313
|
-
codeReviewId: pr.codeReviewId,
|
|
314
|
-
repository: pr.repository?.name,
|
|
315
|
-
status: pr.status,
|
|
316
|
-
createdBy: {
|
|
317
|
-
displayName: pr.createdBy?.displayName,
|
|
318
|
-
uniqueName: pr.createdBy?.uniqueName,
|
|
319
|
-
},
|
|
320
|
-
creationDate: pr.creationDate,
|
|
321
|
-
title: pr.title,
|
|
322
|
-
isDraft: pr.isDraft,
|
|
323
|
-
sourceRefName: pr.sourceRefName,
|
|
324
|
-
targetRefName: pr.targetRefName,
|
|
325
|
-
}));
|
|
326
|
-
return {
|
|
327
|
-
content: [{ type: "text", text: JSON.stringify(filteredPullRequests, null, 2) }],
|
|
328
|
-
};
|
|
329
|
-
});
|
|
330
|
-
server.tool(REPO_TOOLS.list_pull_request_threads, "Retrieve a list of comment threads for a pull request.", {
|
|
331
|
-
repositoryId: z.string().describe("The ID of the repository where the pull request is located."),
|
|
332
|
-
pullRequestId: z.number().describe("The ID of the pull request for which to retrieve threads."),
|
|
333
|
-
project: z.string().optional().describe("Project ID or project name (optional)"),
|
|
334
|
-
iteration: z.number().optional().describe("The iteration ID for which to retrieve threads. Optional, defaults to the latest iteration."),
|
|
335
|
-
baseIteration: z.number().optional().describe("The base iteration ID for which to retrieve threads. Optional, defaults to the latest base iteration."),
|
|
336
|
-
top: z.number().default(100).describe("The maximum number of threads to return."),
|
|
337
|
-
skip: z.number().default(0).describe("The number of threads to skip."),
|
|
338
|
-
fullResponse: z.boolean().optional().default(false).describe("Return full thread JSON response instead of trimmed data."),
|
|
339
|
-
}, async ({ repositoryId, pullRequestId, project, iteration, baseIteration, top, skip, fullResponse }) => {
|
|
340
|
-
const connection = await connectionProvider();
|
|
341
|
-
const gitApi = await connection.getGitApi();
|
|
342
|
-
const threads = await gitApi.getThreads(repositoryId, pullRequestId, project, iteration, baseIteration);
|
|
343
|
-
const paginatedThreads = threads?.sort((a, b) => (a.id ?? 0) - (b.id ?? 0)).slice(skip, skip + top);
|
|
344
|
-
if (fullResponse) {
|
|
345
|
-
return {
|
|
346
|
-
content: [{ type: "text", text: JSON.stringify(paginatedThreads, null, 2) }],
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
// Return trimmed thread data focusing on essential information
|
|
350
|
-
const trimmedThreads = paginatedThreads?.map((thread) => ({
|
|
351
|
-
id: thread.id,
|
|
352
|
-
publishedDate: thread.publishedDate,
|
|
353
|
-
lastUpdatedDate: thread.lastUpdatedDate,
|
|
354
|
-
status: thread.status,
|
|
355
|
-
comments: trimComments(thread.comments),
|
|
356
|
-
}));
|
|
357
|
-
return {
|
|
358
|
-
content: [{ type: "text", text: JSON.stringify(trimmedThreads, null, 2) }],
|
|
359
|
-
};
|
|
360
|
-
});
|
|
361
|
-
server.tool(REPO_TOOLS.list_pull_request_thread_comments, "Retrieve a list of comments in a pull request thread.", {
|
|
362
|
-
repositoryId: z.string().describe("The ID of the repository where the pull request is located."),
|
|
363
|
-
pullRequestId: z.number().describe("The ID of the pull request for which to retrieve thread comments."),
|
|
364
|
-
threadId: z.number().describe("The ID of the thread for which to retrieve comments."),
|
|
365
|
-
project: z.string().optional().describe("Project ID or project name (optional)"),
|
|
366
|
-
top: z.number().default(100).describe("The maximum number of comments to return."),
|
|
367
|
-
skip: z.number().default(0).describe("The number of comments to skip."),
|
|
368
|
-
fullResponse: z.boolean().optional().default(false).describe("Return full comment JSON response instead of trimmed data."),
|
|
369
|
-
}, async ({ repositoryId, pullRequestId, threadId, project, top, skip, fullResponse }) => {
|
|
370
|
-
const connection = await connectionProvider();
|
|
371
|
-
const gitApi = await connection.getGitApi();
|
|
372
|
-
// Get thread comments - GitApi uses getComments for retrieving comments from a specific thread
|
|
373
|
-
const comments = await gitApi.getComments(repositoryId, pullRequestId, threadId, project);
|
|
374
|
-
const paginatedComments = comments?.sort((a, b) => (a.id ?? 0) - (b.id ?? 0)).slice(skip, skip + top);
|
|
375
|
-
if (fullResponse) {
|
|
376
|
-
return {
|
|
377
|
-
content: [{ type: "text", text: JSON.stringify(paginatedComments, null, 2) }],
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
// Return trimmed comment data focusing on essential information
|
|
381
|
-
const trimmedComments = trimComments(paginatedComments);
|
|
382
|
-
return {
|
|
383
|
-
content: [{ type: "text", text: JSON.stringify(trimmedComments, null, 2) }],
|
|
384
|
-
};
|
|
385
|
-
});
|
|
386
|
-
server.tool(REPO_TOOLS.list_branches_by_repo, "Retrieve a list of branches for a given repository.", {
|
|
387
|
-
repositoryId: z.string().describe("The ID of the repository where the branches are located."),
|
|
388
|
-
top: z.number().default(100).describe("The maximum number of branches to return. Defaults to 100."),
|
|
389
|
-
filterContains: z.string().optional().describe("Filter to find branches that contain this string in their name."),
|
|
390
|
-
}, async ({ repositoryId, top, filterContains }) => {
|
|
391
|
-
const connection = await connectionProvider();
|
|
392
|
-
const gitApi = await connection.getGitApi();
|
|
393
|
-
const branches = await gitApi.getRefs(repositoryId, undefined, "heads/", undefined, undefined, undefined, undefined, undefined, filterContains);
|
|
394
|
-
const filteredBranches = branchesFilterOutIrrelevantProperties(branches, top);
|
|
395
|
-
return {
|
|
396
|
-
content: [{ type: "text", text: JSON.stringify(filteredBranches, null, 2) }],
|
|
397
|
-
};
|
|
398
|
-
});
|
|
399
|
-
server.tool(REPO_TOOLS.list_my_branches_by_repo, "Retrieve a list of my branches for a given repository Id.", {
|
|
400
|
-
repositoryId: z.string().describe("The ID of the repository where the branches are located."),
|
|
401
|
-
top: z.number().default(100).describe("The maximum number of branches to return."),
|
|
402
|
-
filterContains: z.string().optional().describe("Filter to find branches that contain this string in their name."),
|
|
403
|
-
}, async ({ repositoryId, top, filterContains }) => {
|
|
404
|
-
const connection = await connectionProvider();
|
|
405
|
-
const gitApi = await connection.getGitApi();
|
|
406
|
-
const branches = await gitApi.getRefs(repositoryId, undefined, "heads/", undefined, undefined, true, undefined, undefined, filterContains);
|
|
407
|
-
const filteredBranches = branchesFilterOutIrrelevantProperties(branches, top);
|
|
408
|
-
return {
|
|
409
|
-
content: [{ type: "text", text: JSON.stringify(filteredBranches, null, 2) }],
|
|
410
|
-
};
|
|
411
|
-
});
|
|
412
|
-
server.tool(REPO_TOOLS.get_repo_by_name_or_id, "Get the repository by project and repository name or ID.", {
|
|
413
|
-
project: z.string().describe("Project name or ID where the repository is located."),
|
|
414
|
-
repositoryNameOrId: z.string().describe("Repository name or ID."),
|
|
415
|
-
}, async ({ project, repositoryNameOrId }) => {
|
|
416
|
-
const connection = await connectionProvider();
|
|
417
|
-
const gitApi = await connection.getGitApi();
|
|
418
|
-
const repositories = await gitApi.getRepositories(project);
|
|
419
|
-
const repository = repositories?.find((repo) => repo.name === repositoryNameOrId || repo.id === repositoryNameOrId);
|
|
420
|
-
if (!repository) {
|
|
421
|
-
throw new Error(`Repository ${repositoryNameOrId} not found in project ${project}`);
|
|
422
|
-
}
|
|
423
|
-
return {
|
|
424
|
-
content: [{ type: "text", text: JSON.stringify(repository, null, 2) }],
|
|
425
|
-
};
|
|
426
|
-
});
|
|
427
|
-
server.tool(REPO_TOOLS.get_branch_by_name, "Get a branch by its name.", {
|
|
428
|
-
repositoryId: z.string().describe("The ID of the repository where the branch is located."),
|
|
429
|
-
branchName: z.string().describe("The name of the branch to retrieve, e.g., 'main' or 'feature-branch'."),
|
|
430
|
-
}, async ({ repositoryId, branchName }) => {
|
|
431
|
-
const connection = await connectionProvider();
|
|
432
|
-
const gitApi = await connection.getGitApi();
|
|
433
|
-
const branches = await gitApi.getRefs(repositoryId, undefined, "heads/", false, false, undefined, false, undefined, branchName);
|
|
434
|
-
const branch = branches.find((branch) => branch.name === `refs/heads/${branchName}` || branch.name === branchName);
|
|
435
|
-
if (!branch) {
|
|
436
|
-
return {
|
|
437
|
-
content: [
|
|
438
|
-
{
|
|
439
|
-
type: "text",
|
|
440
|
-
text: `Branch ${branchName} not found in repository ${repositoryId}`,
|
|
441
|
-
},
|
|
442
|
-
],
|
|
443
|
-
isError: true,
|
|
444
|
-
};
|
|
445
|
-
}
|
|
446
|
-
return {
|
|
447
|
-
content: [{ type: "text", text: JSON.stringify(branch, null, 2) }],
|
|
448
|
-
};
|
|
449
|
-
});
|
|
450
|
-
server.tool(REPO_TOOLS.get_pull_request_by_id, "Get a pull request by its ID.", {
|
|
451
|
-
repositoryId: z.string().describe("The ID of the repository where the pull request is located."),
|
|
452
|
-
pullRequestId: z.number().describe("The ID of the pull request to retrieve."),
|
|
453
|
-
includeWorkItemRefs: z.boolean().optional().default(false).describe("Whether to reference work items associated with the pull request."),
|
|
454
|
-
}, async ({ repositoryId, pullRequestId, includeWorkItemRefs }) => {
|
|
455
|
-
const connection = await connectionProvider();
|
|
456
|
-
const gitApi = await connection.getGitApi();
|
|
457
|
-
const pullRequest = await gitApi.getPullRequest(repositoryId, pullRequestId, undefined, undefined, undefined, undefined, undefined, includeWorkItemRefs);
|
|
458
|
-
return {
|
|
459
|
-
content: [{ type: "text", text: JSON.stringify(pullRequest, null, 2) }],
|
|
460
|
-
};
|
|
461
|
-
});
|
|
462
|
-
server.tool(REPO_TOOLS.reply_to_comment, "Replies to a specific comment on a pull request.", {
|
|
463
|
-
repositoryId: z.string().describe("The ID of the repository where the pull request is located."),
|
|
464
|
-
pullRequestId: z.number().describe("The ID of the pull request where the comment thread exists."),
|
|
465
|
-
threadId: z.number().describe("The ID of the thread to which the comment will be added."),
|
|
466
|
-
content: z.string().describe("The content of the comment to be added."),
|
|
467
|
-
project: z.string().optional().describe("Project ID or project name (optional)"),
|
|
468
|
-
fullResponse: z.boolean().optional().default(false).describe("Return full comment JSON response instead of a simple confirmation message."),
|
|
469
|
-
}, async ({ repositoryId, pullRequestId, threadId, content, project, fullResponse }) => {
|
|
470
|
-
const connection = await connectionProvider();
|
|
471
|
-
const gitApi = await connection.getGitApi();
|
|
472
|
-
const comment = await gitApi.createComment({ content }, repositoryId, pullRequestId, threadId, project);
|
|
473
|
-
// Check if the comment was successfully created
|
|
474
|
-
if (!comment) {
|
|
475
|
-
return {
|
|
476
|
-
content: [{ type: "text", text: `Error: Failed to add comment to thread ${threadId}. The comment was not created successfully.` }],
|
|
477
|
-
isError: true,
|
|
478
|
-
};
|
|
479
|
-
}
|
|
480
|
-
if (fullResponse) {
|
|
481
|
-
return {
|
|
482
|
-
content: [{ type: "text", text: JSON.stringify(comment, null, 2) }],
|
|
483
|
-
};
|
|
484
|
-
}
|
|
485
|
-
return {
|
|
486
|
-
content: [{ type: "text", text: `Comment successfully added to thread ${threadId}.` }],
|
|
487
|
-
};
|
|
488
|
-
});
|
|
489
|
-
server.tool(REPO_TOOLS.create_pull_request_thread, "Creates a new comment thread on a pull request.", {
|
|
490
|
-
repositoryId: z.string().describe("The ID of the repository where the pull request is located."),
|
|
491
|
-
pullRequestId: z.number().describe("The ID of the pull request where the comment thread exists."),
|
|
492
|
-
content: z.string().describe("The content of the comment to be added."),
|
|
493
|
-
project: z.string().optional().describe("Project ID or project name (optional)"),
|
|
494
|
-
filePath: z.string().optional().describe("The path of the file where the comment thread will be created. (optional)"),
|
|
495
|
-
status: z
|
|
496
|
-
.enum(getEnumKeys(CommentThreadStatus))
|
|
497
|
-
.optional()
|
|
498
|
-
.default(CommentThreadStatus[CommentThreadStatus.Active])
|
|
499
|
-
.describe("The status of the comment thread. Defaults to 'Active'."),
|
|
500
|
-
rightFileStartLine: z.number().optional().describe("Position of first character of the thread's span in right file. The line number of a thread's position. Starts at 1. (optional)"),
|
|
501
|
-
rightFileStartOffset: z
|
|
502
|
-
.number()
|
|
503
|
-
.optional()
|
|
504
|
-
.describe("Position of first character of the thread's span in right file. The line number of a thread's position. The character offset of a thread's position inside of a line. Starts at 1. Must only be set if rightFileStartLine is also specified. (optional)"),
|
|
505
|
-
rightFileEndLine: z
|
|
506
|
-
.number()
|
|
507
|
-
.optional()
|
|
508
|
-
.describe("Position of last character of the thread's span in right file. The line number of a thread's position. Starts at 1. Must only be set if rightFileStartLine is also specified. (optional)"),
|
|
509
|
-
rightFileEndOffset: z
|
|
510
|
-
.number()
|
|
511
|
-
.optional()
|
|
512
|
-
.describe("Position of last character of the thread's span in right file. The character offset of a thread's position inside of a line. Must only be set if rightFileEndLine is also specified. (optional)"),
|
|
513
|
-
}, async ({ repositoryId, pullRequestId, content, project, filePath, status, rightFileStartLine, rightFileStartOffset, rightFileEndLine, rightFileEndOffset }) => {
|
|
514
|
-
const connection = await connectionProvider();
|
|
515
|
-
const gitApi = await connection.getGitApi();
|
|
516
|
-
const threadContext = { filePath: filePath };
|
|
517
|
-
if (rightFileStartLine !== undefined) {
|
|
518
|
-
if (rightFileStartLine < 1) {
|
|
519
|
-
throw new Error("rightFileStartLine must be greater than or equal to 1.");
|
|
520
|
-
}
|
|
521
|
-
threadContext.rightFileStart = { line: rightFileStartLine };
|
|
522
|
-
if (rightFileStartOffset !== undefined) {
|
|
523
|
-
if (rightFileStartOffset < 1) {
|
|
524
|
-
throw new Error("rightFileStartOffset must be greater than or equal to 1.");
|
|
525
|
-
}
|
|
526
|
-
threadContext.rightFileStart.offset = rightFileStartOffset;
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
if (rightFileEndLine !== undefined) {
|
|
530
|
-
if (rightFileStartLine === undefined) {
|
|
531
|
-
throw new Error("rightFileEndLine must only be specified if rightFileStartLine is also specified.");
|
|
532
|
-
}
|
|
533
|
-
if (rightFileEndLine < 1) {
|
|
534
|
-
throw new Error("rightFileEndLine must be greater than or equal to 1.");
|
|
535
|
-
}
|
|
536
|
-
threadContext.rightFileEnd = { line: rightFileEndLine };
|
|
537
|
-
if (rightFileEndOffset !== undefined) {
|
|
538
|
-
if (rightFileEndOffset < 1) {
|
|
539
|
-
throw new Error("rightFileEndOffset must be greater than or equal to 1.");
|
|
540
|
-
}
|
|
541
|
-
threadContext.rightFileEnd.offset = rightFileEndOffset;
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
const thread = await gitApi.createThread({ comments: [{ content: content }], threadContext: threadContext, status: CommentThreadStatus[status] }, repositoryId, pullRequestId, project);
|
|
545
|
-
return {
|
|
546
|
-
content: [{ type: "text", text: JSON.stringify(thread, null, 2) }],
|
|
547
|
-
};
|
|
548
|
-
});
|
|
549
|
-
server.tool(REPO_TOOLS.resolve_comment, "Resolves a specific comment thread on a pull request.", {
|
|
550
|
-
repositoryId: z.string().describe("The ID of the repository where the pull request is located."),
|
|
551
|
-
pullRequestId: z.number().describe("The ID of the pull request where the comment thread exists."),
|
|
552
|
-
threadId: z.number().describe("The ID of the thread to be resolved."),
|
|
553
|
-
fullResponse: z.boolean().optional().default(false).describe("Return full thread JSON response instead of a simple confirmation message."),
|
|
554
|
-
}, async ({ repositoryId, pullRequestId, threadId, fullResponse }) => {
|
|
555
|
-
const connection = await connectionProvider();
|
|
556
|
-
const gitApi = await connection.getGitApi();
|
|
557
|
-
const thread = await gitApi.updateThread({ status: 2 }, // 2 corresponds to "Resolved" status
|
|
558
|
-
repositoryId, pullRequestId, threadId);
|
|
559
|
-
// Check if the thread was successfully resolved
|
|
560
|
-
if (!thread) {
|
|
561
|
-
return {
|
|
562
|
-
content: [{ type: "text", text: `Error: Failed to resolve thread ${threadId}. The thread status was not updated successfully.` }],
|
|
563
|
-
isError: true,
|
|
564
|
-
};
|
|
565
|
-
}
|
|
566
|
-
if (fullResponse) {
|
|
567
|
-
return {
|
|
568
|
-
content: [{ type: "text", text: JSON.stringify(thread, null, 2) }],
|
|
569
|
-
};
|
|
570
|
-
}
|
|
571
|
-
return {
|
|
572
|
-
content: [{ type: "text", text: `Thread ${threadId} was successfully resolved.` }],
|
|
573
|
-
};
|
|
574
|
-
});
|
|
575
|
-
const gitVersionTypeStrings = Object.values(GitVersionType).filter((value) => typeof value === "string");
|
|
576
|
-
server.tool(REPO_TOOLS.search_commits, "Searches for commits in a repository", {
|
|
577
|
-
project: z.string().describe("Project name or ID"),
|
|
578
|
-
repository: z.string().describe("Repository name or ID"),
|
|
579
|
-
fromCommit: z.string().optional().describe("Starting commit ID"),
|
|
580
|
-
toCommit: z.string().optional().describe("Ending commit ID"),
|
|
581
|
-
version: z.string().optional().describe("The name of the branch, tag or commit to filter commits by"),
|
|
582
|
-
versionType: z
|
|
583
|
-
.enum(gitVersionTypeStrings)
|
|
584
|
-
.optional()
|
|
585
|
-
.default(GitVersionType[GitVersionType.Branch])
|
|
586
|
-
.describe("The meaning of the version parameter, e.g., branch, tag or commit"),
|
|
587
|
-
skip: z.number().optional().default(0).describe("Number of commits to skip"),
|
|
588
|
-
top: z.number().optional().default(10).describe("Maximum number of commits to return"),
|
|
589
|
-
includeLinks: z.boolean().optional().default(false).describe("Include commit links"),
|
|
590
|
-
includeWorkItems: z.boolean().optional().default(false).describe("Include associated work items"),
|
|
591
|
-
}, async ({ project, repository, fromCommit, toCommit, version, versionType, skip, top, includeLinks, includeWorkItems }) => {
|
|
592
|
-
try {
|
|
593
|
-
const connection = await connectionProvider();
|
|
594
|
-
const gitApi = await connection.getGitApi();
|
|
595
|
-
const searchCriteria = {
|
|
596
|
-
fromCommitId: fromCommit,
|
|
597
|
-
toCommitId: toCommit,
|
|
598
|
-
includeLinks: includeLinks,
|
|
599
|
-
includeWorkItems: includeWorkItems,
|
|
600
|
-
};
|
|
601
|
-
if (version) {
|
|
602
|
-
const itemVersion = {
|
|
603
|
-
version: version,
|
|
604
|
-
versionType: GitVersionType[versionType],
|
|
605
|
-
};
|
|
606
|
-
searchCriteria.itemVersion = itemVersion;
|
|
607
|
-
}
|
|
608
|
-
const commits = await gitApi.getCommits(repository, searchCriteria, project, skip, // skip
|
|
609
|
-
top);
|
|
610
|
-
return {
|
|
611
|
-
content: [{ type: "text", text: JSON.stringify(commits, null, 2) }],
|
|
612
|
-
};
|
|
613
|
-
}
|
|
614
|
-
catch (error) {
|
|
615
|
-
return {
|
|
616
|
-
content: [
|
|
617
|
-
{
|
|
618
|
-
type: "text",
|
|
619
|
-
text: `Error searching commits: ${error instanceof Error ? error.message : String(error)}`,
|
|
620
|
-
},
|
|
621
|
-
],
|
|
622
|
-
isError: true,
|
|
623
|
-
};
|
|
624
|
-
}
|
|
625
|
-
});
|
|
626
|
-
const pullRequestQueryTypesStrings = Object.values(GitPullRequestQueryType).filter((value) => typeof value === "string");
|
|
627
|
-
server.tool(REPO_TOOLS.list_pull_requests_by_commits, "Lists pull requests by commit IDs to find which pull requests contain specific commits", {
|
|
628
|
-
project: z.string().describe("Project name or ID"),
|
|
629
|
-
repository: z.string().describe("Repository name or ID"),
|
|
630
|
-
commits: z.array(z.string()).describe("Array of commit IDs to query for"),
|
|
631
|
-
queryType: z
|
|
632
|
-
.enum(pullRequestQueryTypesStrings)
|
|
633
|
-
.optional()
|
|
634
|
-
.default(GitPullRequestQueryType[GitPullRequestQueryType.LastMergeCommit])
|
|
635
|
-
.describe("Type of query to perform"),
|
|
636
|
-
}, async ({ project, repository, commits, queryType }) => {
|
|
637
|
-
try {
|
|
638
|
-
const connection = await connectionProvider();
|
|
639
|
-
const gitApi = await connection.getGitApi();
|
|
640
|
-
const query = {
|
|
641
|
-
queries: [
|
|
642
|
-
{
|
|
643
|
-
items: commits,
|
|
644
|
-
type: GitPullRequestQueryType[queryType],
|
|
645
|
-
},
|
|
646
|
-
],
|
|
647
|
-
};
|
|
648
|
-
const queryResult = await gitApi.getPullRequestQuery(query, repository, project);
|
|
649
|
-
return {
|
|
650
|
-
content: [{ type: "text", text: JSON.stringify(queryResult, null, 2) }],
|
|
651
|
-
};
|
|
652
|
-
}
|
|
653
|
-
catch (error) {
|
|
654
|
-
return {
|
|
655
|
-
content: [
|
|
656
|
-
{
|
|
657
|
-
type: "text",
|
|
658
|
-
text: `Error querying pull requests by commits: ${error instanceof Error ? error.message : String(error)}`,
|
|
659
|
-
},
|
|
660
|
-
],
|
|
661
|
-
isError: true,
|
|
662
|
-
};
|
|
663
|
-
}
|
|
664
|
-
});
|
|
665
|
-
}
|
|
666
|
-
export { REPO_TOOLS, configureRepoTools };
|