Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions src/tools/repos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { AccessToken } from "@azure/identity";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { WebApi } from "azure-devops-node-api";
import { GitRef } from "azure-devops-node-api/interfaces/GitInterfaces.js";
import { GitRef, PullRequestStatus } from "azure-devops-node-api/interfaces/GitInterfaces.js";
import { z } from "zod";
import { getCurrentUserDetails } from "./auth.js";

Expand Down Expand Up @@ -36,6 +36,25 @@ function branchesFilterOutIrrelevantProperties(
.slice(0, top);
}

function pullRequestStatusStringToInt(
status: string)
: number {
switch (status) {
case "abandoned":
return PullRequestStatus.Abandoned.valueOf();
case "active":
return PullRequestStatus.Active.valueOf();
case "all":
return PullRequestStatus.All.valueOf();
case "completed":
return PullRequestStatus.Completed.valueOf();
case "notSet":
return PullRequestStatus.NotSet.valueOf();
default:
throw new Error(`Unknown pull request status: ${status}`);
}
}

function configureRepoTools(
server: McpServer,
tokenProvider: () => Promise<AccessToken>,
Expand Down Expand Up @@ -149,8 +168,9 @@ function configureRepoTools(
repositoryId: z.string().describe("The ID of the repository where the pull requests are located."),
created_by_me: z.boolean().default(false).describe("Filter pull requests created by the current user."),
i_am_reviewer: z.boolean().default(false).describe("Filter pull requests where the current user is a reviewer."),
status: z.enum(["abandoned", "active", "all", "completed", "notSet"]).default("active").describe("Filter pull requests by status. Defaults to 'active'."),
},
async ({ repositoryId, created_by_me, i_am_reviewer }) => {
async ({ repositoryId, created_by_me, i_am_reviewer, status }) => {
const connection = await connectionProvider();
const gitApi = await connection.getGitApi();

Expand All @@ -161,7 +181,7 @@ function configureRepoTools(
creatorId?: string;
reviewerId?: string;
} = {
status: 1,
status: pullRequestStatusStringToInt(status),
repositoryId: repositoryId,
};

Expand Down Expand Up @@ -213,8 +233,9 @@ function configureRepoTools(
project: z.string().describe("The name or ID of the Azure DevOps project."),
created_by_me: z.boolean().default(false).describe("Filter pull requests created by the current user."),
i_am_reviewer: z.boolean().default(false).describe("Filter pull requests where the current user is a reviewer."),
status: z.enum(["abandoned", "active", "all", "completed", "notSet"]).default("active").describe("Filter pull requests by status. Defaults to 'active'."),
},
async ({ project, created_by_me, i_am_reviewer }) => {
async ({ project, created_by_me, i_am_reviewer, status }) => {
const connection = await connectionProvider();
const gitApi = await connection.getGitApi();

Expand All @@ -224,7 +245,7 @@ function configureRepoTools(
creatorId?: string;
reviewerId?: string;
} = {
status: 1,
status: pullRequestStatusStringToInt(status),
};

if (created_by_me || i_am_reviewer) {
Expand Down
Loading