UNPKG

n8n-bookstack-agent-tool

Version:

Comprehensive BookStack API integration tool for n8n AI Agent with MCP framework compatibility

98 lines 3.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CommandGenerator = void 0; const api_parser_js_1 = require("../utils/api-parser.js"); class CommandGenerator { static generateMCPCommands() { const apiSpec = api_parser_js_1.BookStackApiParser.parseApiSpec(); const commands = []; apiSpec.endpoints.forEach(endpoint => { const command = this.endpointToMCPCommand(endpoint); commands.push(command); }); return commands; } static endpointToMCPCommand(endpoint) { const properties = {}; const required = []; endpoint.parameters?.forEach(param => { if (param.in === 'path') { properties[param.name] = { type: param.schema.type, description: param.description || `${param.name} parameter` }; if (param.required) { required.push(param.name); } } }); endpoint.parameters?.forEach(param => { if (param.in === 'query') { properties[param.name] = { type: param.schema.type, description: param.description || `${param.name} parameter`, ...(param.schema.minimum && { minimum: param.schema.minimum }), ...(param.schema.maximum && { maximum: param.schema.maximum }) }; if (param.required) { required.push(param.name); } } }); if (endpoint.requestBody) { const jsonContent = endpoint.requestBody.content['application/json']; if (jsonContent?.schema?.properties) { Object.entries(jsonContent.schema.properties).forEach(([key, schema]) => { properties[key] = { type: schema.type, description: `${key} field` }; }); if (jsonContent.schema.required) { required.push(...jsonContent.schema.required); } } } return { name: endpoint.operationId, description: endpoint.description, inputSchema: { type: 'object', properties, ...(required.length > 0 && { required }) } }; } static generateCommandSchema() { const commands = this.generateMCPCommands(); return { $schema: 'http://json-schema.org/draft-07/schema#', title: 'BookStack n8n Agent Tool Commands', description: 'Available commands for the BookStack n8n Agent Tool', type: 'object', properties: { commands: { type: 'array', items: { type: 'object', properties: { name: { type: 'string' }, description: { type: 'string' }, inputSchema: { type: 'object', properties: { type: { type: 'string' }, properties: { type: 'object' }, required: { type: 'array', items: { type: 'string' } } } } } } } }, commands }; } } exports.CommandGenerator = CommandGenerator; //# sourceMappingURL=command-generator.js.map