environment-unified.tsโข4.77 kB
/**
* Unified Coolify Environment & Configuration Tools
* Consolidated MCP tools for managing environments, domains, and logs
*/
import { Tool } from '@modelcontextprotocol/sdk/types.js';
import { CoolifyApiClient } from '../utils/coolify-client';
/**
* Unified Environment & Configuration Tool
* Combines environment variables, domains, and logs into a single tool
*/
export const environmentConfigurationTool: Tool = {
name: 'coolify_environment_configuration',
description: 'Manage environment variables, configure domains, and retrieve application logs',
inputSchema: {
type: 'object',
properties: {
action: {
type: 'string',
enum: ['update_env', 'get_env', 'set_domain', 'get_logs'],
description: 'Action to perform: update env vars, get env vars, set domain, or get logs',
},
applicationId: {
type: 'string',
description: 'Application ID (required for all actions)',
},
// Environment variable parameters
variables: {
type: 'array',
description: 'Array of environment variables to set (for update_env)',
items: {
type: 'object',
properties: {
key: {
type: 'string',
description: 'Environment variable key/name',
},
value: {
type: 'string',
description: 'Environment variable value',
},
is_sensitive: {
type: 'boolean',
description: 'Whether this is a sensitive variable (will be hidden in UI)',
default: false,
},
is_build_time: {
type: 'boolean',
description: 'Whether this variable is available at build time',
default: false,
},
},
required: ['key', 'value'],
},
},
// Domain parameters
domain: {
type: 'string',
description: 'Domain name to set (for set_domain action)',
},
enableHttps: {
type: 'boolean',
description: 'Whether to enable HTTPS/SSL (for set_domain action)',
default: true,
},
// Log parameters
lines: {
type: 'number',
description: 'Number of log lines to retrieve (for get_logs action)',
default: 100,
minimum: 1,
maximum: 1000,
},
since: {
type: 'string',
description: 'Retrieve logs since this timestamp (ISO format, for get_logs action)',
},
},
required: ['action', 'applicationId'],
},
};
export async function handleEnvironmentConfiguration(
coolifyClient: CoolifyApiClient,
args: any
): Promise<any> {
try {
const { action, applicationId, ...params } = args;
let result;
let message;
switch (action) {
case 'update_env':
if (!params.variables || !Array.isArray(params.variables)) {
throw new Error('variables array is required for update_env action');
}
result = await coolifyClient.updateEnvironmentVariables(applicationId, params.variables);
message = `Updated ${params.variables.length} environment variables for application ${applicationId}`;
break;
case 'get_env':
result = await coolifyClient.getEnvironmentVariables(applicationId);
message = `Retrieved environment variables for application ${applicationId}`;
break;
case 'set_domain':
if (!params.domain) {
throw new Error('domain is required for set_domain action');
}
result = await coolifyClient.setDomain(applicationId, params.domain, params.enableHttps);
message = `Set domain ${params.domain} for application ${applicationId}`;
break;
case 'get_logs':
result = await coolifyClient.getApplicationLogs(
applicationId,
params.lines || 100,
params.since
);
message = `Retrieved ${params.lines || 100} log lines for application ${applicationId}`;
break;
default:
throw new Error(`Unknown environment action: ${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 unified tools
export const environmentTools = [environmentConfigurationTool];