repo_get_repo_by_name_or_id
Retrieve specific repositories in Azure DevOps using project name or ID and repository name or ID, facilitating precise repository management with PAT authentication.
Instructions
Get the repository by project and repository name or ID.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project | Yes | Project name or ID where the repository is located. | |
| repositoryNameOrId | Yes | Repository name or ID. |
Implementation Reference
- src/tools/repos.ts:530-544 (handler)The handler function that retrieves repositories for the given project using the Azure DevOps Git API, finds the matching repository by name or ID, and returns it as JSON.async ({ project, repositoryNameOrId }) => { const connection = await connectionProvider(); const gitApi = await connection.getGitApi(); const repositories = await gitApi.getRepositories(project); const repository = repositories?.find((repo) => repo.name === repositoryNameOrId || repo.id === repositoryNameOrId); if (!repository) { throw new Error(`Repository ${repositoryNameOrId} not found in project ${project}`); } return { content: [{ type: "text", text: JSON.stringify(repository, null, 2) }], }; }
- src/tools/repos.ts:526-529 (schema)Zod schema defining the input parameters: project (name or ID) and repositoryNameOrId.{ project: z.string().describe("Project name or ID where the repository is located."), repositoryNameOrId: z.string().describe("Repository name or ID."), },
- src/tools/repos.ts:523-545 (registration)Registers the tool on the MCP server using server.tool, referencing the tool name from REPO_TOOLS, with description, input schema, and handler.server.tool( REPO_TOOLS.get_repo_by_name_or_id, "Get the repository by project and repository name or ID.", { project: z.string().describe("Project name or ID where the repository is located."), repositoryNameOrId: z.string().describe("Repository name or ID."), }, async ({ project, repositoryNameOrId }) => { const connection = await connectionProvider(); const gitApi = await connection.getGitApi(); const repositories = await gitApi.getRepositories(project); const repository = repositories?.find((repo) => repo.name === repositoryNameOrId || repo.id === repositoryNameOrId); if (!repository) { throw new Error(`Repository ${repositoryNameOrId} not found in project ${project}`); } return { content: [{ type: "text", text: JSON.stringify(repository, null, 2) }], }; } );
- src/tools/repos.ts:33-33 (helper)Part of the REPO_TOOLS constant object that maps the internal identifier to the actual tool name string used in registration.get_repo_by_name_or_id: "repo_get_repo_by_name_or_id",