import { QNAPClient } from '../integrations/qnap-client.js';
/**
* MCP Tools for QNAP NAS File Operations
* Enables Claude to manage files, upload blueprints, and organize storage on QNAP NAS
*/
let qnapClient = null;
// Initialize QNAP client from environment variables
function getQNAPClient() {
if (!qnapClient) {
const nasIP = process.env.QNAP_NAS_IP;
const username = process.env.QNAP_USERNAME;
const password = process.env.QNAP_PASSWORD;
const useHTTPS = process.env.QNAP_USE_HTTPS === 'true';
if (!nasIP || !username || !password) {
throw new Error('QNAP credentials not configured. Set QNAP_NAS_IP, QNAP_USERNAME, and QNAP_PASSWORD environment variables.');
}
qnapClient = new QNAPClient(nasIP, username, password, useHTTPS);
}
return qnapClient;
}
export const qnapTools = {
// Tool 1: List files and directories on QNAP NAS
qnap_list_files: {
name: "qnap_list_files",
description: "List files and directories on QNAP NAS at specified path. Useful for exploring storage structure and finding existing blueprints.",
inputSchema: {
type: "object",
properties: {
directory_path: {
type: "string",
description: "Path to list (default: /Public)",
default: "/Public"
}
}
},
handler: async (args) => {
try {
const client = getQNAPClient();
const result = await client.listFiles(args.directory_path || '/Public');
return {
success: result.success,
message: result.success ?
`Listed files in ${args.directory_path || '/Public'}` :
`Failed to list files: ${result.error}`,
path: result.path,
files: result.files
};
} catch (error) {
return {
success: false,
message: `❌ QNAP list files failed: ${error.message}`
};
}
}
},
// Tool 2: Create directory structure on QNAP NAS
qnap_create_directory: {
name: "qnap_create_directory",
description: "Create a new directory on QNAP NAS. Useful for organizing blueprints and workflows into structured folders.",
inputSchema: {
type: "object",
properties: {
parent_path: {
type: "string",
description: "Parent directory path",
default: "/Public"
},
directory_name: {
type: "string",
description: "Name of the new directory to create"
}
},
required: ["directory_name"]
},
handler: async (args) => {
try {
const client = getQNAPClient();
const result = await client.createDirectory(
args.parent_path || '/Public',
args.directory_name
);
return {
success: result.success,
message: result.message,
directory_path: result.path
};
} catch (error) {
return {
success: false,
message: `❌ Directory creation failed: ${error.message}`
};
}
}
},
// Tool 3: Upload file to QNAP NAS
qnap_upload_file: {
name: "qnap_upload_file",
description: "Upload a file to QNAP NAS. Perfect for storing n8n blueprints, workflow templates, and automation resources.",
inputSchema: {
type: "object",
properties: {
local_file_path: {
type: "string",
description: "Path to the local file to upload"
},
remote_directory: {
type: "string",
description: "Remote directory on QNAP to upload to",
default: "/Public"
},
remote_filename: {
type: "string",
description: "Optional: Custom filename for the uploaded file"
}
},
required: ["local_file_path"]
},
handler: async (args) => {
try {
const client = getQNAPClient();
const result = await client.uploadFile(
args.local_file_path,
args.remote_directory || '/Public',
args.remote_filename
);
return {
success: result.success,
message: result.message,
remote_path: result.remotePath,
uploaded_file: args.local_file_path
};
} catch (error) {
return {
success: false,
message: `❌ File upload failed: ${error.message}`
};
}
}
},
// Tool 4: Download file from QNAP NAS
qnap_download_file: {
name: "qnap_download_file",
description: "Download a file from QNAP NAS to local system. Useful for retrieving blueprints and configurations.",
inputSchema: {
type: "object",
properties: {
remote_file_path: {
type: "string",
description: "Full path to the file on QNAP NAS"
},
local_output_path: {
type: "string",
description: "Optional: Local path to save the downloaded file"
}
},
required: ["remote_file_path"]
},
handler: async (args) => {
try {
const client = getQNAPClient();
const result = await client.downloadFile(
args.remote_file_path,
args.local_output_path
);
return {
success: result.success,
message: result.message,
local_path: result.localPath,
file_size: result.size
};
} catch (error) {
return {
success: false,
message: `❌ File download failed: ${error.message}`
};
}
}
},
// Tool 5: Setup n8n blueprints directory structure
qnap_setup_n8n_structure: {
name: "qnap_setup_n8n_structure",
description: "Create organized directory structure on QNAP NAS for n8n blueprints, workflows, and community nodes storage.",
inputSchema: {
type: "object",
properties: {}
},
handler: async (args) => {
try {
const client = getQNAPClient();
const result = await client.createN8nBlueprintsStructure();
return {
success: result.success,
message: result.message,
directories_created: result.directories
};
} catch (error) {
return {
success: false,
message: `❌ n8n structure setup failed: ${error.message}`
};
}
}
},
// Tool 6: Upload n8n blueprint to organized storage
qnap_upload_n8n_blueprint: {
name: "qnap_upload_n8n_blueprint",
description: "Upload n8n workflow blueprint to QNAP NAS with proper organization. Automatically categorizes workflows, community nodes, and credentials.",
inputSchema: {
type: "object",
properties: {
blueprint_file_path: {
type: "string",
description: "Path to the n8n blueprint/workflow JSON file"
},
blueprint_type: {
type: "string",
description: "Type of blueprint: workflows, community-nodes, credentials, backups",
enum: ["workflows", "community-nodes", "credentials", "backups"],
default: "workflows"
}
},
required: ["blueprint_file_path"]
},
handler: async (args) => {
try {
const client = getQNAPClient();
const result = await client.uploadN8nBlueprint(
args.blueprint_file_path,
args.blueprint_type || 'workflows'
);
return {
success: result.success,
message: result.message,
blueprint_type: result.blueprintType,
remote_path: result.remotePath,
storage_category: args.blueprint_type || 'workflows'
};
} catch (error) {
return {
success: false,
message: `❌ n8n blueprint upload failed: ${error.message}`
};
}
}
},
// Tool 7: Delete files/directories from QNAP NAS
qnap_delete_item: {
name: "qnap_delete_item",
description: "Delete a file or directory from QNAP NAS. Use with caution for cleaning up old blueprints or reorganizing storage.",
inputSchema: {
type: "object",
properties: {
item_path: {
type: "string",
description: "Directory path containing the item"
},
item_name: {
type: "string",
description: "Name of the file or directory to delete"
}
},
required: ["item_path", "item_name"]
},
handler: async (args) => {
try {
const client = getQNAPClient();
const result = await client.deleteItem(args.item_path, args.item_name);
return {
success: result.success,
message: result.message,
deleted_item: `${args.item_path}/${args.item_name}`
};
} catch (error) {
return {
success: false,
message: `❌ Item deletion failed: ${error.message}`
};
}
}
},
// Tool 8: Copy or move files on QNAP NAS
qnap_copy_move_file: {
name: "qnap_copy_move_file",
description: "Copy or move files between directories on QNAP NAS. Useful for organizing blueprints and creating backups.",
inputSchema: {
type: "object",
properties: {
source_path: {
type: "string",
description: "Source directory path"
},
source_filename: {
type: "string",
description: "Source filename"
},
destination_path: {
type: "string",
description: "Destination directory path"
},
operation: {
type: "string",
description: "Operation to perform: copy or move",
enum: ["copy", "move"],
default: "copy"
}
},
required: ["source_path", "source_filename", "destination_path"]
},
handler: async (args) => {
try {
const client = getQNAPClient();
const result = await client.copyOrMoveFile(
args.source_path,
args.source_filename,
args.destination_path,
args.operation || 'copy'
);
return {
success: result.success,
message: result.message,
operation: result.operation,
source: `${args.source_path}/${args.source_filename}`,
destination: args.destination_path
};
} catch (error) {
return {
success: false,
message: `❌ File ${args.operation || 'copy'} failed: ${error.message}`
};
}
}
}
};
// Export tool definitions for MCP server
export const getQNAPToolDefinitions = () => {
return Object.values(qnapTools).map(tool => ({
name: tool.name,
description: tool.description,
inputSchema: tool.inputSchema
}));
};
// Export tool handlers for MCP server execution
export const getQNAPToolHandlers = () => {
const handlers = {};
Object.values(qnapTools).forEach(tool => {
handlers[tool.name] = { handler: tool.handler };
});
return handlers;
};