repo_list_pull_requests_by_commits
Find pull requests containing specific commits in an Azure DevOps repository. Query by commit IDs to accurately track and manage code changes across project branches.
Instructions
Lists pull requests by commit IDs to find which pull requests contain specific commits
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| commits | Yes | Array of commit IDs to query for | |
| project | Yes | Project name or ID | |
| queryType | No | Type of query to perform | LastMergeCommit |
| repository | Yes | Repository name or ID |
Implementation Reference
- src/tools/repos.ts:838-868 (handler)The main handler function that constructs a GitPullRequestQuery from the input commits and calls the Azure DevOps Git API's getPullRequestQuery method to find pull requests containing those commits.async ({ project, repository, commits, queryType }) => { try { const connection = await connectionProvider(); const gitApi = await connection.getGitApi(); const query: GitPullRequestQuery = { queries: [ { items: commits, type: GitPullRequestQueryType[queryType as keyof typeof GitPullRequestQueryType], } as GitPullRequestQueryInput, ], }; const queryResult = await gitApi.getPullRequestQuery(query, repository, project); return { content: [{ type: "text", text: JSON.stringify(queryResult, null, 2) }], }; } catch (error) { return { content: [ { type: "text", text: `Error querying pull requests by commits: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } }
- src/tools/repos.ts:829-837 (schema)Zod schema for input validation, defining parameters project, repository, commits (array of strings), and optional queryType.project: z.string().describe("Project name or ID"), repository: z.string().describe("Repository name or ID"), commits: z.array(z.string()).describe("Array of commit IDs to query for"), queryType: z .enum(pullRequestQueryTypesStrings as [string, ...string[]]) .optional() .default(GitPullRequestQueryType[GitPullRequestQueryType.LastMergeCommit]) .describe("Type of query to perform"), },
- src/tools/repos.ts:825-869 (registration)Registers the tool with the MCP server using server.tool, specifying the name from REPO_TOOLS, description, input schema, and handler function.server.tool( REPO_TOOLS.list_pull_requests_by_commits, "Lists pull requests by commit IDs to find which pull requests contain specific commits", { project: z.string().describe("Project name or ID"), repository: z.string().describe("Repository name or ID"), commits: z.array(z.string()).describe("Array of commit IDs to query for"), queryType: z .enum(pullRequestQueryTypesStrings as [string, ...string[]]) .optional() .default(GitPullRequestQueryType[GitPullRequestQueryType.LastMergeCommit]) .describe("Type of query to perform"), }, async ({ project, repository, commits, queryType }) => { try { const connection = await connectionProvider(); const gitApi = await connection.getGitApi(); const query: GitPullRequestQuery = { queries: [ { items: commits, type: GitPullRequestQueryType[queryType as keyof typeof GitPullRequestQueryType], } as GitPullRequestQueryInput, ], }; const queryResult = await gitApi.getPullRequestQuery(query, repository, project); return { content: [{ type: "text", text: JSON.stringify(queryResult, null, 2) }], }; } catch (error) { return { content: [ { type: "text", text: `Error querying pull requests by commits: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } } );
- src/tools/repos.ts:43-43 (registration)Defines the tool name mapping in the REPO_TOOLS constant object.list_pull_requests_by_commits: "repo_list_pull_requests_by_commits",