synology_read_file
Read Docker configuration files from your Synology NAS. Restricted to files under /volume1/docker, provides access to compose YAML and container settings.
Instructions
Read a configuration file from the NAS (restricted to /volume1/docker)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filepath | Yes | Absolute path to the file on the NAS (must be within /volume1/docker) |
Implementation Reference
- src/index.ts:247-255 (handler)Handler for 'synology_read_file' tool. Extracts filepath from args, validates it via validateRestrictedPath, then executes 'cat' over SSH to read the file content. Returns the file contents on success or an error message on failure.
else if (name === "synology_read_file") { const { filepath } = args as { filepath: string }; validateRestrictedPath(filepath); const res = await execSshCommand(`cat ${shQuote(filepath)}`); if (res.code !== 0) { return { content: [{ type: "text", text: `Error reading file: ${res.stderr}` }] }; } return { content: [{ type: "text", text: res.stdout }] }; } - src/index.ts:166-175 (schema)Schema registration for 'synology_read_file' tool. Defines the tool name, description, and inputSchema with a required 'filepath' string property.
{ name: "synology_read_file", description: `Read a configuration file from the NAS (restricted to ${NAS_DOCKER_DIR})`, inputSchema: { type: "object", properties: { filepath: { type: "string", description: `Absolute path to the file on the NAS (must be within ${NAS_DOCKER_DIR})` }, }, required: ["filepath"], }, - src/index.ts:46-58 (helper)Helper function 'validateRestrictedPath' used by the handler to ensure filepath is absolute, contains no '..' traversal, and starts with NAS_DOCKER_DIR.
/** Filepath must be absolute, contain no .. segments, and be under NAS_DOCKER_DIR. */ function validateRestrictedPath(filepath: string): void { if (!filepath.startsWith("/")) { throw new Error("Path must be absolute"); } if (filepath.split("/").some((p) => p === "..")) { throw new Error("Path traversal not allowed"); } const base = NAS_DOCKER_DIR.replace(/\/$/, ""); if (!filepath.startsWith(base + "/")) { throw new Error(`Path must be within ${NAS_DOCKER_DIR}`); } } - src/index.ts:111-191 (registration)Tool registration via ListToolsRequestSchema handler. Lists 'synology_read_file' among other tools as part of the available tool set.
server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ { name: "synology_docker_ps", description: "List all docker containers on the Synology NAS", inputSchema: { type: "object", properties: {}, }, }, { name: "synology_docker_logs", description: "Get logs for a specific docker container", inputSchema: { type: "object", properties: { container_name: { type: "string", description: "Name or ID of the container" }, tail: { type: "number", description: "Number of lines to show from the end of the logs", default: 100 }, }, required: ["container_name"], }, }, { name: "synology_docker_manage", description: "Manage container lifecycle (start, stop, restart)", inputSchema: { type: "object", properties: { action: { type: "string", enum: ["start", "stop", "restart", "rm"], description: "Action to perform" }, container_name: { type: "string", description: "Name or ID of the container" }, }, required: ["action", "container_name"], }, }, { name: "synology_project_list", description: "List docker-compose projects in the Synology NAS docker directory", inputSchema: { type: "object", properties: {}, }, }, { name: "synology_project_manage", description: "Manage a docker-compose project (up, down, restart)", inputSchema: { type: "object", properties: { project_name: { type: "string", description: "Name of the project folder in NAS_DOCKER_DIR" }, action: { type: "string", enum: ["up -d", "down", "restart", "pull"], description: "Docker compose action" }, }, required: ["project_name", "action"], }, }, { name: "synology_read_file", description: `Read a configuration file from the NAS (restricted to ${NAS_DOCKER_DIR})`, inputSchema: { type: "object", properties: { filepath: { type: "string", description: `Absolute path to the file on the NAS (must be within ${NAS_DOCKER_DIR})` }, }, required: ["filepath"], }, }, { name: "synology_write_file", description: `Write or update a configuration file on the NAS (restricted to ${NAS_DOCKER_DIR})`, inputSchema: { type: "object", properties: { filepath: { type: "string", description: `Absolute path to the file on the NAS (must be within ${NAS_DOCKER_DIR})` }, content: { type: "string", description: "File content to write" }, }, required: ["filepath", "content"], }, }, ], }; });