n8n-mcp
Version:
Integration between n8n workflow automation and Model Context Protocol (MCP)
113 lines • 4.84 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleToolsDocumentation = handleToolsDocumentation;
exports.formatToolDocumentation = formatToolDocumentation;
const tools_documentation_1 = require("./tools-documentation");
async function handleToolsDocumentation(args) {
try {
const response = {};
if (args.tools && args.tools.length > 0) {
response.documentation = (0, tools_documentation_1.getToolsDocumentation)(args.tools);
response.totalTools = Object.keys(response.documentation).length;
if (response.totalTools === 0) {
response.message = `No documentation found for tools: ${args.tools.join(', ')}`;
}
}
else if (args.search) {
response.documentation = (0, tools_documentation_1.searchToolDocumentation)(args.search);
response.totalTools = Object.keys(response.documentation).length;
if (response.totalTools === 0) {
response.message = `No tools found matching search: "${args.search}"`;
}
else {
response.message = `Found ${response.totalTools} tools matching "${args.search}"`;
}
}
else if (args.category) {
const categories = (0, tools_documentation_1.getToolsByCategory)();
const toolsInCategory = categories[args.category];
if (toolsInCategory) {
response.documentation = (0, tools_documentation_1.getToolsDocumentation)(toolsInCategory);
response.totalTools = toolsInCategory.length;
response.message = `${response.totalTools} tools in category "${args.category}"`;
}
else {
response.categories = categories;
response.message = `Category "${args.category}" not found. Available categories: ${Object.keys(categories).join(', ')}`;
}
}
else {
response.categories = (0, tools_documentation_1.getToolsByCategory)();
response.totalTools = (0, tools_documentation_1.getAllToolNames)().length;
response.message = `${response.totalTools} tools available across ${Object.keys(response.categories).length} categories`;
}
if (args.includeQuickReference) {
response.quickReference = (0, tools_documentation_1.getQuickReference)();
}
return response;
}
catch (error) {
return {
message: `Error retrieving tools documentation: ${error instanceof Error ? error.message : 'Unknown error'}`
};
}
}
function formatToolDocumentation(doc) {
const sections = [];
sections.push(`## ${doc.name}`);
sections.push(`**${doc.briefDescription}**`);
sections.push('');
sections.push('### Parameters');
for (const param of doc.parameters) {
const required = param.required ? ' (required)' : ' (optional)';
const defaultVal = param.default !== undefined ? `, default: ${param.default}` : '';
const enumVals = param.enum ? `, options: ${param.enum.join(', ')}` : '';
sections.push(`- **${param.name}**${required}: ${param.type} - ${param.description}${defaultVal}${enumVals}`);
}
sections.push('');
sections.push('### Return Format');
sections.push('```json');
sections.push(doc.returnFormat);
sections.push('```');
sections.push('');
sections.push('### Common Use Cases');
doc.commonUseCases.forEach(useCase => {
sections.push(`- ${useCase}`);
});
sections.push('');
sections.push('### Examples');
doc.examples.forEach(example => {
sections.push(`**${example.description}**`);
sections.push('```json');
sections.push(JSON.stringify(example.input, null, 2));
sections.push('```');
if (example.expectedOutput) {
sections.push('Expected output:');
sections.push('```');
sections.push(example.expectedOutput);
sections.push('```');
}
sections.push('');
});
if (doc.performanceNotes.length > 0) {
sections.push('### Performance Notes');
doc.performanceNotes.forEach(note => {
sections.push(`- ${note}`);
});
sections.push('');
}
sections.push('### Best Practices');
doc.bestPractices.forEach(practice => {
sections.push(`- ${practice}`);
});
sections.push('');
sections.push('### Common Pitfalls');
doc.commonPitfalls.forEach(pitfall => {
sections.push(`- ${pitfall}`);
});
sections.push('');
sections.push('### Related Tools');
sections.push(doc.relatedTools.map(tool => `\`${tool}\``).join(', '));
return sections.join('\n');
}
//# sourceMappingURL=handlers-documentation.js.map