You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -24,39 +23,41 @@ const server = new McpServer({
24
23
server.tool(
25
24
"search_code",
26
25
dedent`
27
-
Fetches code that matches the provided regex pattern in \`query\`.
28
-
29
-
Results are returned as an array of matching files, with the file's URL, repository, and language.
30
-
31
-
If the \`includeCodeSnippets\` property is true, code snippets containing the matches will be included in the response. Only set this to true if the request requires code snippets (e.g., show me examples where library X is used).
32
-
When referencing a file in your response, **ALWAYS** include the file's external URL as a link. This makes it easier for the user to view the file, even if they don't have it locally checked out.
33
-
**ONLY USE** the \`filterByRepoIds\` property if the request requires searching a specific repo(s). Otherwise, leave it empty.`,
26
+
Searches for code that matches the provided search query as a substring by default, or as a regular expression if useRegex is true. Useful for exploring remote repositories by searching for exact symbols, functions, variables, or specific code patterns. To determine if a repository is indexed, use the \`list_repos\` tool. By default, searches are global and will search the default branch of all repositories. Searches can be scoped to specific repositories, languages, and branches. When referencing code outputted by this tool, always include the file's external URL as a link. This makes it easier for the user to view the file, even if they don't have it locally checked out.
27
+
`,
34
28
{
35
29
query: z
36
30
.string()
37
-
.describe(`The regex pattern to search for. RULES:
38
-
1. When a regex special character needs to be escaped, ALWAYS use a single backslash (\) (e.g., 'console\.log')
39
-
2. **ALWAYS** escape spaces with a single backslash (\) (e.g., 'console\ log')
40
-
`),
41
-
filterByRepoIds: z
31
+
.describe(`The search pattern to match against code contents. Do not escape quotes in your query.`)
32
+
// Wrap in quotes so the query is treated as a literal phrase (like grep).
.describe(`Whether to use regular expression matching to match the search query against code contents. When false, substring matching is used. (default: false)`)
37
+
.optional(),
38
+
filterByRepos: z
42
39
.array(z.string())
43
-
.describe(`Scope the search to the provided repositories to the Sourcebot compatible repository IDs. **DO NOT** use this property if you want to search all repositories. **YOU MUST** call 'list_repos' first to obtain the exact repository ID.`)
40
+
.describe(`Scope the search to the provided repositories.`)
44
41
.optional(),
45
42
filterByLanguages: z
46
43
.array(z.string())
47
-
.describe(`Scope the search to the provided languages. The language MUST be formatted as a GitHub linguist language. Examples: Python, JavaScript, TypeScript, Java, C#, C++, PHP, Go, Rust, Ruby, Swift, Kotlin, Shell, C, Dart, HTML, CSS, PowerShell, SQL, R`)
44
+
.describe(`Scope the search to the provided languages.`)
45
+
.optional(),
46
+
filterByFilepaths: z
47
+
.array(z.string())
48
+
.describe(`Scope the search to the provided filepaths. Interpretted as a regex.`)
48
49
.optional(),
49
50
caseSensitive: z
50
51
.boolean()
51
52
.describe(`Whether the search should be case sensitive (default: false).`)
52
53
.optional(),
53
54
includeCodeSnippets: z
54
55
.boolean()
55
-
.describe(`Whether to include the code snippets in the response (default: false). If false, only the file's URL, repository, and language will be returned. Set to false to get a more concise response.`)
56
+
.describe(`Whether to include the code snippets in the response. If false, only the file's URL, repository, and language will be returned. (default: false)`)
56
57
.optional(),
57
-
gitRevision: z
58
+
ref: z
58
59
.string()
59
-
.describe(`The git revision to search in (e.g., 'main', 'HEAD', 'v1.0.0', 'a1b2c3d'). If not provided, defaults to the default branch (usually 'main' or 'master').`)
60
+
.describe(`Commit SHA, branch or tag name to search on. If not provided, defaults to the default branch (usually 'main' or 'master').`)
60
61
.optional(),
61
62
maxTokens: numberSchema
62
63
.describe(`The maximum number of tokens to return (default: ${env.DEFAULT_MINIMUM_TOKENS}). Higher values provide more context but consume more tokens. Values less than ${env.DEFAULT_MINIMUM_TOKENS} will be ignored.`)
@@ -65,30 +66,36 @@ server.tool(
65
66
},
66
67
async({
67
68
query,
68
-
filterByRepoIds: repoIds=[],
69
+
filterByRepos: repos=[],
69
70
filterByLanguages: languages=[],
71
+
filterByFilepaths: filepaths=[],
70
72
maxTokens =env.DEFAULT_MINIMUM_TOKENS,
71
73
includeCodeSnippets =false,
72
74
caseSensitive =false,
73
-
gitRevision,
75
+
ref,
76
+
useRegex =false,
74
77
})=>{
75
-
if(repoIds.length>0){
76
-
query+=` (repo:${repoIds.map(id=>escapeStringRegexp(id)).join(' or repo:')})`;
78
+
if(repos.length>0){
79
+
query+=` (repo:${repos.map(id=>escapeStringRegexp(id)).join(' or repo:')})`;
77
80
}
78
81
79
82
if(languages.length>0){
80
-
query+=` ( lang:${languages.join(' or lang:')} )`;
83
+
query+=` (lang:${languages.join(' or lang:')})`;
84
+
}
85
+
86
+
if(filepaths.length>0){
87
+
query+=` (file:${filepaths.map(filepath=>escapeStringRegexp(filepath)).join(' or file:')})`;
0 commit comments