init_project
Create a .ploi.json config file to connect your project to a Ploi site using the project path and domain.
Instructions
Initialize .ploi.json config for a project by searching for a domain. Use when user wants to link a project to a Ploi site.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_path | Yes | The path to the project directory | |
| domain | Yes | The domain name of the Ploi site to link |
Implementation Reference
- src/tools/sites.ts:344-389 (handler)The 'init_project' tool handler: searches for a Ploi site by domain across all servers, then writes a .ploi.json config file in the project directory linking the project to the found server/site.
async ({ project_path, domain }) => { const servers = await client.listServers(); let foundServer: { id: number; name: string } | null = null; let foundSite: Site | null = null; for (const server of servers) { const sites = await client.listSites(server.id); for (const site of sites) { if (site.domain.toLowerCase().includes(domain.toLowerCase())) { foundServer = { id: server.id, name: server.name }; foundSite = site; break; } } if (foundSite) break; } if (!foundSite || !foundServer) { return { content: [ { type: "text" as const, text: `No site found matching "${domain}". Use list_servers and list_sites to find your site.`, }, ], }; } const config = { server_id: foundServer.id, site_id: foundSite.id, }; const configPath = join(project_path, ".ploi.json"); await writeFile(configPath, JSON.stringify(config, null, 2) + "\n"); return { content: [ { type: "text" as const, text: `Created .ploi.json for ${foundSite.domain}\n\nServer: ${foundServer.name} (${foundServer.id})\nSite: ${foundSite.domain} (${foundSite.id})\n\nYou can now use "deploy" to deploy this project.`, }, ], }; } ); - src/tools/sites.ts:340-343 (schema)Input schema for the 'init_project' tool: requires 'project_path' (string) and 'domain' (string) as parameters.
{ project_path: z.string().describe("The path to the project directory"), domain: z.string().describe("The domain name of the Ploi site to link"), }, - src/tools/sites.ts:337-389 (registration)Registration of the 'init_project' tool via server.tool() inside the registerSiteTools function.
server.tool( "init_project", "Initialize .ploi.json config for a project by searching for a domain. Use when user wants to link a project to a Ploi site.", { project_path: z.string().describe("The path to the project directory"), domain: z.string().describe("The domain name of the Ploi site to link"), }, async ({ project_path, domain }) => { const servers = await client.listServers(); let foundServer: { id: number; name: string } | null = null; let foundSite: Site | null = null; for (const server of servers) { const sites = await client.listSites(server.id); for (const site of sites) { if (site.domain.toLowerCase().includes(domain.toLowerCase())) { foundServer = { id: server.id, name: server.name }; foundSite = site; break; } } if (foundSite) break; } if (!foundSite || !foundServer) { return { content: [ { type: "text" as const, text: `No site found matching "${domain}". Use list_servers and list_sites to find your site.`, }, ], }; } const config = { server_id: foundServer.id, site_id: foundSite.id, }; const configPath = join(project_path, ".ploi.json"); await writeFile(configPath, JSON.stringify(config, null, 2) + "\n"); return { content: [ { type: "text" as const, text: `Created .ploi.json for ${foundSite.domain}\n\nServer: ${foundServer.name} (${foundServer.id})\nSite: ${foundSite.domain} (${foundSite.id})\n\nYou can now use "deploy" to deploy this project.`, }, ], }; } ); - src/tools/sites.ts:12-24 (helper)Helper function readPloiConfig for reading existing .ploi.json configs (utility in the same file).
async function readPloiConfig(projectPath: string): Promise<PloiConfig | null> { try { const configPath = join(projectPath, ".ploi.json"); const content = await readFile(configPath, "utf-8"); const config = JSON.parse(content) as PloiConfig; if (typeof config.server_id === "number" && typeof config.site_id === "number") { return config; } return null; } catch { return null; } }