mirror of
https://github.com/modelcontextprotocol/servers.git
synced 2026-04-20 12:55:21 +02:00
feat: add search_files handler in CallToolRequestSchema
This commit is contained in:
@@ -442,6 +442,18 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|||||||
const { name, arguments: args } = request.params;
|
const { name, arguments: args } = request.params;
|
||||||
|
|
||||||
switch (name) {
|
switch (name) {
|
||||||
|
case "search_files": {
|
||||||
|
const parsed = SearchFilesArgsSchema.safeParse(args);
|
||||||
|
if (!parsed.success) {
|
||||||
|
throw new Error(`Invalid arguments for search_files: ${parsed.error}`);
|
||||||
|
}
|
||||||
|
const validPath = await validatePath(parsed.data.path);
|
||||||
|
const results = await searchFiles(validPath, parsed.data.pattern, parsed.data.excludePatterns);
|
||||||
|
return {
|
||||||
|
content: [{ type: "text", text: results.length > 0 ? results.join("\n") : "No matches found" }],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
case "read_file": {
|
case "read_file": {
|
||||||
const parsed = ReadFileArgsSchema.safeParse(args);
|
const parsed = ReadFileArgsSchema.safeParse(args);
|
||||||
if (!parsed.success) {
|
if (!parsed.success) {
|
||||||
@@ -540,18 +552,6 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
case "search_files": {
|
|
||||||
const parsed = SearchFilesArgsSchema.safeParse(args);
|
|
||||||
if (!parsed.success) {
|
|
||||||
throw new Error(`Invalid arguments for search_files: ${parsed.error}`);
|
|
||||||
}
|
|
||||||
const validPath = await validatePath(parsed.data.path);
|
|
||||||
const results = await searchFiles(validPath, parsed.data.pattern, parsed.data.excludePatterns);
|
|
||||||
return {
|
|
||||||
content: [{ type: "text", text: results.length > 0 ? results.join("\n") : "No matches found" }],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
case "get_file_info": {
|
case "get_file_info": {
|
||||||
const parsed = GetFileInfoArgsSchema.safeParse(args);
|
const parsed = GetFileInfoArgsSchema.safeParse(args);
|
||||||
if (!parsed.success) {
|
if (!parsed.success) {
|
||||||
|
|||||||
Reference in New Issue
Block a user