Skip to main content
Glama
ennuiii

Azure DevOps MCP Server with PAT Authentication

by ennuiii

repo_list_pull_requests_by_repo

Retrieve a filtered list of pull requests from a specific Azure DevOps repository. Filter by status, creator, reviewer, or paginate results using top and skip parameters.

Instructions

Retrieve a list of pull requests for a given repository.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
created_by_meNoFilter pull requests created by the current user.
i_am_reviewerNoFilter pull requests where the current user is a reviewer.
repositoryIdYesThe ID of the repository where the pull requests are located.
skipNoThe number of pull requests to skip.
statusNoFilter pull requests by status. Defaults to 'Active'.Active
topNoThe maximum number of pull requests to return.

Implementation Reference

  • Executes the tool logic: connects to Azure DevOps, builds search criteria based on inputs (including user filters), calls gitApi.getPullRequests, trims response, and returns JSON.
    async ({ repositoryId, top, skip, created_by_me, i_am_reviewer, status }) => { const connection = await connectionProvider(); const gitApi = await connection.getGitApi(); // Build the search criteria const searchCriteria: { status: number; repositoryId: string; creatorId?: string; reviewerId?: string; } = { status: pullRequestStatusStringToInt(status), repositoryId: repositoryId, }; if (created_by_me || i_am_reviewer) { const data = await getCurrentUserDetails(tokenProvider, connectionProvider, userAgentProvider); const userId = data.authenticatedUser.id; if (created_by_me) { searchCriteria.creatorId = userId; } if (i_am_reviewer) { searchCriteria.reviewerId = userId; } } const pullRequests = await gitApi.getPullRequests( repositoryId, searchCriteria, undefined, // project undefined, // maxCommentLength skip, top ); // Filter out the irrelevant properties const filteredPullRequests = pullRequests?.map((pr) => ({ pullRequestId: pr.pullRequestId, codeReviewId: pr.codeReviewId, status: pr.status, createdBy: { displayName: pr.createdBy?.displayName, uniqueName: pr.createdBy?.uniqueName, }, creationDate: pr.creationDate, title: pr.title, isDraft: pr.isDraft, sourceRefName: pr.sourceRefName, targetRefName: pr.targetRefName, })); return { content: [{ type: "text", text: JSON.stringify(filteredPullRequests, null, 2) }], }; }
  • Zod input schema defining parameters: repositoryId, top, skip, created_by_me, i_am_reviewer, status.
    repositoryId: z.string().describe("The ID of the repository where the pull requests are located."), top: z.number().default(100).describe("The maximum number of pull requests to return."), skip: z.number().default(0).describe("The number of pull requests to skip."), 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(getEnumKeys(PullRequestStatus) as [string, ...string[]]) .default("Active") .describe("Filter pull requests by status. Defaults to 'Active'."), },
  • Registers the tool on the McpServer with the name REPO_TOOLS.list_pull_requests_by_repo ("repo_list_pull_requests_by_repo"), description, input schema, and handler.
    server.tool( REPO_TOOLS.list_pull_requests_by_repo, "Retrieve a list of pull requests for a given repository.", { repositoryId: z.string().describe("The ID of the repository where the pull requests are located."), top: z.number().default(100).describe("The maximum number of pull requests to return."), skip: z.number().default(0).describe("The number of pull requests to skip."), 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(getEnumKeys(PullRequestStatus) as [string, ...string[]]) .default("Active") .describe("Filter pull requests by status. Defaults to 'Active'."), }, async ({ repositoryId, top, skip, created_by_me, i_am_reviewer, status }) => { const connection = await connectionProvider(); const gitApi = await connection.getGitApi(); // Build the search criteria const searchCriteria: { status: number; repositoryId: string; creatorId?: string; reviewerId?: string; } = { status: pullRequestStatusStringToInt(status), repositoryId: repositoryId, }; if (created_by_me || i_am_reviewer) { const data = await getCurrentUserDetails(tokenProvider, connectionProvider, userAgentProvider); const userId = data.authenticatedUser.id; if (created_by_me) { searchCriteria.creatorId = userId; } if (i_am_reviewer) { searchCriteria.reviewerId = userId; } } const pullRequests = await gitApi.getPullRequests( repositoryId, searchCriteria, undefined, // project undefined, // maxCommentLength skip, top ); // Filter out the irrelevant properties const filteredPullRequests = pullRequests?.map((pr) => ({ pullRequestId: pr.pullRequestId, codeReviewId: pr.codeReviewId, status: pr.status, createdBy: { displayName: pr.createdBy?.displayName, uniqueName: pr.createdBy?.uniqueName, }, creationDate: pr.creationDate, title: pr.title, isDraft: pr.isDraft, sourceRefName: pr.sourceRefName, targetRefName: pr.targetRefName, })); return { content: [{ type: "text", text: JSON.stringify(filteredPullRequests, null, 2) }], }; } );
  • Helper function to convert string status to PullRequestStatus enum value, used in the handler's search criteria.
    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}`); } }
  • Part of REPO_TOOLS constant mapping the internal key to the tool name string used in server.tool registration.
    list_pull_requests_by_repo: "repo_list_pull_requests_by_repo",

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ennuiii/DevOpsMcpPAT'

If you have feedback or need assistance with the MCP directory API, please join our Discord server