documentation.tsโข3.15 kB
import { z } from 'zod';
import { CoolifyApiClient } from '../utils/coolify-client.js';
// MCP Tool interface for consistency
interface MCPTool {
name: string;
description: string;
inputSchema: z.ZodSchema;
}
// ToolCall interface for handling requests
interface ToolCall {
params?: {
arguments?: any;
};
}
// Unified documentation schema
const DocumentationSchema = z.object({
action: z.enum(['search', 'get', 'api', 'troubleshoot']).describe('Action to perform: search docs, get topic docs, get API reference, or get troubleshooting'),
query: z.string().describe('Search query, topic name, API endpoint, or issue description'),
category: z.string().optional().describe('Optional category filter (api, guide, configuration, troubleshooting)'),
limit: z.number().min(1).max(50).default(10).describe('Maximum number of results to return')
});
/**
* Unified Documentation Tool for Coolify MCP Server
* Combines search, get, API reference, and troubleshooting into one tool
*/
export const documentationTool: MCPTool = {
name: 'coolify_documentation',
description: 'Access Coolify documentation: search docs, get topic info, API reference, or troubleshooting guides',
inputSchema: DocumentationSchema
};
export async function handleDocumentation(
call: ToolCall,
coolifyClient: CoolifyApiClient
): Promise<any> {
try {
const args = DocumentationSchema.parse(call.params?.arguments);
let result;
let message;
switch (args.action) {
case 'search':
result = await coolifyClient.searchDocumentation(
args.query,
args.category,
args.limit
);
message = `Found ${result.entries.length} documentation entries for "${args.query}"`;
break;
case 'get':
result = await coolifyClient.getDocumentation(args.query, args.category);
message = `Found ${result.length} documentation entries for topic "${args.query}"`;
break;
case 'api':
result = await coolifyClient.getApiReference(args.query);
message = args.query
? `API documentation for endpoint "${args.query}"`
: 'Complete Coolify API reference documentation';
break;
case 'troubleshoot':
result = await coolifyClient.getTroubleshooting(args.query);
message = `Found ${result.length} troubleshooting guides for "${args.query}"`;
break;
default:
throw new Error(`Unknown documentation action: ${args.action}`);
}
return {
content: [
{
type: 'text',
text: JSON.stringify({
success: true,
data: result,
message: message
}, null, 2)
}
]
};
} catch (error) {
return {
content: [
{
type: 'text',
text: JSON.stringify({
success: false,
error: error instanceof Error ? error.message : 'Unknown error occurred'
}, null, 2)
}
],
isError: true
};
}
}
// Export the unified tool
export const documentationTools = [documentationTool];