This document describes the search tools available in the Azure DevOps MCP server.
The search_code
tool allows you to search for code across repositories in an Azure DevOps project. It uses the Azure DevOps Search API to find code matching your search criteria and can optionally include the full content of the files in the results.
Parameter | Type | Required | Description |
---|---|---|---|
searchText | string | Yes | The text to search for in the code |
projectId | string | No | The ID or name of the project to search in. If not provided, search will be performed across all projects in the organization. |
filters | object | No | Optional filters to narrow search results |
filters.Repository | string[] | No | Filter by repository names |
filters.Path | string[] | No | Filter by file paths |
filters.Branch | string[] | No | Filter by branch names |
filters.CodeElement | string[] | No | Filter by code element types (function, class, etc.) |
top | number | No | Number of results to return (default: 100, max: 1000) |
skip | number | No | Number of results to skip for pagination (default: 0) |
includeSnippet | boolean | No | Whether to include code snippets in results (default: true) |
includeContent | boolean | No | Whether to include full file content in results (default: true) |
The response includes:
count
: The total number of matching filesresults
: An array of search results, each containing:fileName
: The name of the filepath
: The path to the filecontent
: The full content of the file (ifincludeContent
is true)matches
: Information about where the search text was found in the filecollection
: Information about the collectionproject
: Information about the projectrepository
: Information about the repositoryversions
: Information about the versions of the file
facets
: Aggregated information about the search results, such as counts by repository, path, etc.
{
"searchText": "function searchCode",
"projectId": "MyProject"
}
{
"searchText": "function searchCode"
}
{
"searchText": "function searchCode",
"projectId": "MyProject",
"filters": {
"Repository": ["MyRepo"],
"Path": ["/src"],
"Branch": ["main"],
"CodeElement": ["function", "class"]
}
}
{
"searchText": "function",
"projectId": "MyProject",
"top": 10,
"skip": 20
}
{
"searchText": "function",
"projectId": "MyProject",
"includeContent": false
}
- The search is performed using the Azure DevOps Search API, which is separate from the core Azure DevOps API.
- The search API uses a different base URL (
almsearch.dev.azure.com
) than the regular Azure DevOps API. - When
includeContent
is true, the tool makes additional API calls to fetch the full content of each file in the search results. - The search API supports a variety of search syntax, including wildcards, exact phrases, and boolean operators. See the Azure DevOps Search documentation for more information.
- The
CodeElement
filter allows you to filter by code element types such asfunction
,class
,method
,property
,variable
,comment
, etc. - When
projectId
is not provided, the search will be performed across all projects in the organization, which can be useful for finding examples of specific code patterns or libraries used across the organization.