system.tsโข5.32 kB
/**
* Coolify System Management Tools
* MCP tools for managing servers, teams, and system-level operations
*/
import { Tool } from '@modelcontextprotocol/sdk/types.js';
import { CoolifyApiClient } from '../utils/coolify-client';
import {
GetServersInput,
GetTeamsInput,
} from '../types/mcp';
/**
* Tool: Get Servers
* Lists all servers managed by Coolify
*/
export const getServersTool: Tool = {
name: 'coolify_get_servers',
description: 'Get list of all servers managed by Coolify, including their status and connection details.',
inputSchema: {
type: 'object',
properties: {},
required: [],
},
};
export async function handleGetServers(
client: CoolifyApiClient,
_args: GetServersInput
): Promise<any> {
try {
const servers = await client.getServers();
if (servers.length === 0) {
return {
content: [
{
type: 'text',
text: '๐ฅ๏ธ No servers found in Coolify.',
},
],
};
}
const serverList = servers
.map(server =>
`โข ${server.name} (${server.id})\n` +
` IP: ${server.ip}:${server.port}\n` +
` User: ${server.user}\n` +
` Status: ${server.status}`
)
.join('\n\n');
return {
content: [
{
type: 'text',
text: `๐ฅ๏ธ Servers (${servers.length} found):\n\n${serverList}`,
},
],
};
} catch (error) {
return {
content: [
{
type: 'text',
text: `โ Failed to get servers: ${error instanceof Error ? error.message : 'Unknown error'}`,
},
],
};
}
}
/**
* Tool: Get Teams
* Lists all teams in Coolify
*/
export const getTeamsTool: Tool = {
name: 'coolify_get_teams',
description: 'Get list of all teams in Coolify with their details.',
inputSchema: {
type: 'object',
properties: {},
required: [],
},
};
export async function handleGetTeams(
client: CoolifyApiClient,
_args: GetTeamsInput
): Promise<any> {
try {
const teams = await client.getTeams();
if (teams.length === 0) {
return {
content: [
{
type: 'text',
text: '๐ฅ No teams found in Coolify.',
},
],
};
}
const teamList = teams
.map(team =>
`โข ${team.name} (${team.id})\n` +
` Description: ${team.description || 'No description'}`
)
.join('\n\n');
return {
content: [
{
type: 'text',
text: `๐ฅ Teams (${teams.length} found):\n\n${teamList}`,
},
],
};
} catch (error) {
return {
content: [
{
type: 'text',
text: `โ Failed to get teams: ${error instanceof Error ? error.message : 'Unknown error'}`,
},
],
};
}
}
/**
* Tool: Test Connection
* Tests the connection to Coolify instance
*/
export const testConnectionTool: Tool = {
name: 'coolify_test_connection',
description: 'Test the connection to the Coolify instance to verify API credentials and connectivity.',
inputSchema: {
type: 'object',
properties: {},
required: [],
},
};
export async function handleTestConnection(
client: CoolifyApiClient,
_args: {}
): Promise<any> {
try {
const isConnected = await client.testConnection();
if (isConnected) {
return {
content: [
{
type: 'text',
text: 'โ
Connection to Coolify instance successful! API credentials are valid.',
},
],
};
} else {
return {
content: [
{
type: 'text',
text: 'โ Connection to Coolify instance failed. Please check your configuration.',
},
],
};
}
} catch (error) {
return {
content: [
{
type: 'text',
text: `โ Connection test failed: ${error instanceof Error ? error.message : 'Unknown error'}`,
},
],
};
}
}
/**
* Tool: Get Services
* Lists all services deployed in Coolify
*/
export const getServicesTool: Tool = {
name: 'coolify_get_services',
description: 'Get list of all services (databases, caches, etc.) deployed in Coolify.',
inputSchema: {
type: 'object',
properties: {},
required: [],
},
};
export async function handleGetServices(
client: CoolifyApiClient,
_args: {}
): Promise<any> {
try {
const services = await client.getServices();
if (services.length === 0) {
return {
content: [
{
type: 'text',
text: '๐ ๏ธ No services found in Coolify.',
},
],
};
}
const serviceList = services
.map(service =>
`โข ${service.name} (${service.id})\n` +
` Type: ${service.type}\n` +
` Status: ${service.status}`
)
.join('\n\n');
return {
content: [
{
type: 'text',
text: `๐ ๏ธ Services (${services.length} found):\n\n${serviceList}`,
},
],
};
} catch (error) {
return {
content: [
{
type: 'text',
text: `โ Failed to get services: ${error instanceof Error ? error.message : 'Unknown error'}`,
},
],
};
}
}