mirror of
https://github.com/modelcontextprotocol/servers.git
synced 2026-04-23 06:15:15 +02:00
Merge branch 'main' into community/mcp-server-mysql-on-nodejs
This commit is contained in:
@@ -127,6 +127,10 @@ const ListDirectoryArgsSchema = z.object({
|
|||||||
path: z.string(),
|
path: z.string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const DirectoryTreeArgsSchema = z.object({
|
||||||
|
path: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
const MoveFileArgsSchema = z.object({
|
const MoveFileArgsSchema = z.object({
|
||||||
source: z.string(),
|
source: z.string(),
|
||||||
destination: z.string(),
|
destination: z.string(),
|
||||||
@@ -383,6 +387,15 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|||||||
"finding specific files within a directory. Only works within allowed directories.",
|
"finding specific files within a directory. Only works within allowed directories.",
|
||||||
inputSchema: zodToJsonSchema(ListDirectoryArgsSchema) as ToolInput,
|
inputSchema: zodToJsonSchema(ListDirectoryArgsSchema) as ToolInput,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "directory_tree",
|
||||||
|
description:
|
||||||
|
"Get a recursive tree view of files and directories as a JSON structure. " +
|
||||||
|
"Each entry includes 'name', 'type' (file/directory), and 'children' for directories. " +
|
||||||
|
"Files have no children array, while directories always have a children array (which may be empty). " +
|
||||||
|
"The output is formatted with 2-space indentation for readability. Only works within allowed directories.",
|
||||||
|
inputSchema: zodToJsonSchema(DirectoryTreeArgsSchema) as ToolInput,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "move_file",
|
name: "move_file",
|
||||||
description:
|
description:
|
||||||
@@ -517,6 +530,49 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case "directory_tree": {
|
||||||
|
const parsed = DirectoryTreeArgsSchema.safeParse(args);
|
||||||
|
if (!parsed.success) {
|
||||||
|
throw new Error(`Invalid arguments for directory_tree: ${parsed.error}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TreeEntry {
|
||||||
|
name: string;
|
||||||
|
type: 'file' | 'directory';
|
||||||
|
children?: TreeEntry[];
|
||||||
|
}
|
||||||
|
|
||||||
|
async function buildTree(currentPath: string): Promise<TreeEntry[]> {
|
||||||
|
const validPath = await validatePath(currentPath);
|
||||||
|
const entries = await fs.readdir(validPath, {withFileTypes: true});
|
||||||
|
const result: TreeEntry[] = [];
|
||||||
|
|
||||||
|
for (const entry of entries) {
|
||||||
|
const entryData: TreeEntry = {
|
||||||
|
name: entry.name,
|
||||||
|
type: entry.isDirectory() ? 'directory' : 'file'
|
||||||
|
};
|
||||||
|
|
||||||
|
if (entry.isDirectory()) {
|
||||||
|
const subPath = path.join(currentPath, entry.name);
|
||||||
|
entryData.children = await buildTree(subPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
result.push(entryData);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
const treeData = await buildTree(parsed.data.path);
|
||||||
|
return {
|
||||||
|
content: [{
|
||||||
|
type: "text",
|
||||||
|
text: JSON.stringify(treeData, null, 2)
|
||||||
|
}],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
case "move_file": {
|
case "move_file": {
|
||||||
const parsed = MoveFileArgsSchema.safeParse(args);
|
const parsed = MoveFileArgsSchema.safeParse(args);
|
||||||
if (!parsed.success) {
|
if (!parsed.success) {
|
||||||
|
|||||||
Reference in New Issue
Block a user