n8n-bookstack-agent-tool
Version:
Comprehensive BookStack API integration tool for n8n AI Agent with MCP framework compatibility
146 lines • 5.96 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const commander_1 = require("commander");
const index_js_1 = require("../index.js");
const config_js_1 = require("../auth/config.js");
const error_handler_js_1 = require("../error/error-handler.js");
const program = new commander_1.Command();
program
.name('bookstack-tool')
.description('BookStack n8n Agent Tool CLI')
.version('1.0.0');
program
.command('test')
.description('Test connection to BookStack API')
.requiredOption('--url <url>', 'BookStack base URL')
.requiredOption('--token <token>', 'API token')
.option('--token-secret <tokenSecret>', 'API token secret')
.option('--timeout <timeout>', 'Request timeout in milliseconds', '30000')
.action(async (options) => {
try {
const config = {
baseUrl: options.url,
authType: 'bearer',
token: options.token,
tokenSecret: options.tokenSecret,
timeout: parseInt(options.timeout)
};
config_js_1.BookStackConfigValidator.validate(config);
const tool = new index_js_1.BookStackN8nTool(config);
console.log('Testing connection...');
const isConnected = await tool.testConnection();
if (isConnected) {
console.log('✅ Connection successful!');
process.exit(0);
}
else {
console.log('❌ Connection failed!');
process.exit(1);
}
}
catch (error) {
console.error('❌ Error:', error instanceof error_handler_js_1.BookStackError ? error.message : error);
process.exit(1);
}
});
program
.command('exec')
.description('Execute a BookStack command')
.argument('<command>', 'Command to execute (e.g., listBooks, getBook)')
.requiredOption('--url <url>', 'BookStack base URL')
.requiredOption('--token <token>', 'API token')
.option('--token-secret <tokenSecret>', 'API token secret')
.option('--timeout <timeout>', 'Request timeout in milliseconds', '30000')
.option('--id <id>', 'Resource ID (for get/update/delete operations)')
.option('--count <count>', 'Number of records to return', '10')
.option('--offset <offset>', 'Number of records to skip', '0')
.option('--sort <sort>', 'Sort order (+field or -field)')
.option('--name <name>', 'Resource name (for create/update operations)')
.option('--description <description>', 'Resource description')
.option('--params <params>', 'Additional parameters as JSON string')
.action(async (command, options) => {
try {
const config = {
baseUrl: options.url,
authType: 'bearer',
token: options.token,
tokenSecret: options.tokenSecret,
timeout: parseInt(options.timeout)
};
config_js_1.BookStackConfigValidator.validate(config);
const tool = new index_js_1.BookStackN8nTool(config);
const params = {};
if (options.id)
params.id = parseInt(options.id);
if (options.count)
params.count = parseInt(options.count);
if (options.offset)
params.offset = parseInt(options.offset);
if (options.sort)
params.sort = options.sort;
if (options.name)
params.name = options.name;
if (options.description)
params.description = options.description;
if (options.params) {
try {
const additionalParams = JSON.parse(options.params);
Object.assign(params, additionalParams);
}
catch (error) {
console.error('❌ Invalid JSON in --params option');
process.exit(1);
}
}
console.log(`Executing command: ${command}`);
console.log(`Parameters:`, JSON.stringify(params, null, 2));
const result = await tool.execCommand(command, params);
console.log('✅ Result:');
console.log(JSON.stringify(result, null, 2));
}
catch (error) {
console.error('❌ Error:', error instanceof error_handler_js_1.BookStackError ? error.message : error);
if (error instanceof error_handler_js_1.BookStackError && error.details) {
console.error('Details:', JSON.stringify(error.details, null, 2));
}
process.exit(1);
}
});
program
.command('commands')
.description('List available commands')
.requiredOption('--url <url>', 'BookStack base URL')
.requiredOption('--token <token>', 'API token')
.option('--token-secret <tokenSecret>', 'API token secret')
.action(async (options) => {
try {
const config = {
baseUrl: options.url,
authType: 'bearer',
token: options.token,
tokenSecret: options.tokenSecret
};
config_js_1.BookStackConfigValidator.validate(config);
const tool = new index_js_1.BookStackN8nTool(config);
const commands = tool.getAvailableCommands();
console.log('Available commands:');
commands.forEach(cmd => {
console.log(`\n📋 ${cmd.name}`);
console.log(` Description: ${cmd.description}`);
if (cmd.inputSchema && cmd.inputSchema.properties) {
console.log(` Parameters:`);
Object.entries(cmd.inputSchema.properties).forEach(([param, schema]) => {
const required = cmd.inputSchema.required?.includes(param) ? ' (required)' : '';
console.log(` - ${param}: ${schema.type}${required} - ${schema.description || 'No description'}`);
});
}
});
}
catch (error) {
console.error('❌ Error:', error instanceof error_handler_js_1.BookStackError ? error.message : error);
process.exit(1);
}
});
program.parse();
//# sourceMappingURL=cli-tool.js.map