Extended guide to customizing file management tools
The desktop version of mcp-ui supports adding file manipulation tools by modifying the MCP service code as follows:
- Defining Tool Parameters: in
mcp_server.js
(used form a nominal expression)tools
New objects are added to the array, for example:{
name: "file_manager",
description: "本地文件管理器",
parameters: {
action: { type: "string", enum: ["read", "write", "list"] },
path: { type: "string" }
}
} - Implementing the tool logic: in the same file as the
handleToolCall
function to add processing code, using Node.js'fs
module to implement read and write operations, note the addition of error handling. - Setting permissions (desktop version only): in Electron's
main.js
centralized configurationnodeIntegration: true
and declare the required file path permissions.
Test cases:
- Read the file: type "read. /notes.txt"
- To list directories: type "list. /documents"
Safety Recommendations:
- Limit the range of directories that can be accessed (e.g., User Documents folder only).
- Adds a confirmation dialog for write operations.
- Sensitive operations are logged to the
mcp_operations.log
The
This answer comes from the articlemcp-ui: a clean AI chat interface based on the MCP protocolThe