import { z } from "zod";
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import type { PloiClient } from "../client.js";
export function registerServerTools(server: McpServer, client: PloiClient) {
server.tool(
"list_servers",
"List all servers in your Ploi account",
{},
async () => {
const servers = await client.listServers();
return {
content: [
{
type: "text" as const,
text: JSON.stringify(servers, null, 2),
},
],
};
}
);
server.tool(
"get_server",
"Get details of a specific server",
{
server_id: z.coerce.number().describe("The ID of the server"),
},
async ({ server_id }) => {
const serverInfo = await client.getServer(server_id);
return {
content: [
{
type: "text" as const,
text: JSON.stringify(serverInfo, null, 2),
},
],
};
}
);
server.tool(
"restart_server",
"Restart a server",
{
server_id: z.coerce.number().describe("The ID of the server to restart"),
},
async ({ server_id }) => {
await client.restartServer(server_id);
return {
content: [
{
type: "text" as const,
text: `Server ${server_id} restart initiated successfully`,
},
],
};
}
);
server.tool(
"get_server_logs",
"Get recent server activity logs",
{
server_id: z.coerce.number().describe("The ID of the server"),
},
async ({ server_id }) => {
try {
const logs = await client.getServerLogs(server_id);
return {
content: [
{
type: "text" as const,
text: String(logs || "No logs available"),
},
],
};
} catch (error) {
return {
content: [
{
type: "text" as const,
text: `Error fetching server logs: ${error instanceof Error ? error.message : String(error)}`,
},
],
};
}
}
);
}