UNPKG

@railway/mcp-server

Version:
61 lines (58 loc) • 4.45 kB
import { getLinkedProjectInfo } from "./projects-ENU6yIz7.js"; import { getCurrentEnvironmentId } from "./environments-BMQ5EW9R.js"; import { createToolResponse } from "./utils-Cvxm88Gr.js"; import { deployTemplate, searchAndListTemplates } from "./deploy-template-CE3DJG5u.js"; import z from "zod"; //#region src/tools/deploy-template.ts const deployTemplateTool = { name: "deploy-template", title: "Deploy Railway Template", description: "Search and deploy Railway templates. This tool will search for templates using fuzzy search and automatically deploy the selected template to the current Railway project and environment.", inputSchema: { workspacePath: z.string().describe("The path to the workspace to deploy the template to"), searchQuery: z.string().describe("Search query to filter templates by name, description, or category"), templateIndex: z.number().optional().describe("Index of the template to deploy (required if multiple templates found)"), teamId: z.string().optional().describe("The ID of the team (optional)") }, handler: async ({ workspacePath, searchQuery, templateIndex, teamId }) => { try { const { templates, filteredCount, totalCount } = await searchAndListTemplates({ searchQuery }); if (templates.length === 0) return createToolResponse(`šŸ” No templates found matching "${searchQuery}".\n\n**Total templates available:** ${totalCount}\n\n**Suggestions:**\n• Try a different search term\n• Use broader keywords\n• Check your internet connection`); if (templates.length > 1 && templateIndex === void 0) { const templateList = templates.map((template, index) => { const verifiedBadge = template.isVerified ? "verified" : "unverified"; return `${index + 1}. **${template.name}** - (${verifiedBadge})\n ID: \`${template.id}\`\n Description: ${template.description || "No description available"}\n Category: ${template.category}\n Active Projects: ${template.activeProjects} | Health: ${template.health} | Payout: ${template.totalPayout}`; }).join("\n\n"); return createToolResponse(`šŸ” Multiple templates found matching "${searchQuery}":\n\n**Showing ${filteredCount} of ${totalCount} templates:**\n\n` + templateList + `\n\n**Please specify which template to deploy by providing:**\n• templateIndex: [1-${templates.length}]`); } let templateToDeploy; if (templates.length === 1) templateToDeploy = templates[0]; else if (templateIndex !== void 0) { if (templateIndex < 1 || templateIndex > templates.length) return createToolResponse(`āŒ Invalid template index: ${templateIndex}\n\n**Valid range:** 1-${templates.length}\n\nPlease provide a valid template index.`); templateToDeploy = templates[templateIndex - 1]; } else return createToolResponse("āŒ Unexpected error: Multiple templates found but no index specified."); const projectResult = await getLinkedProjectInfo({ workspacePath }); if (!projectResult.success || !projectResult.project) return createToolResponse("āŒ No Railway project is linked to this workspace.\n\n**Next Steps:**\n• Run `railway link` to connect to a project\n• Or use the `create-project-and-link` tool to create a new project"); const currentProjectId = projectResult.project.id; const currentEnvironmentId = await getCurrentEnvironmentId({ workspacePath }); const result = await deployTemplate({ environmentId: currentEnvironmentId, projectId: currentProjectId, serializedConfig: templateToDeploy.serializedConfig, templateId: templateToDeploy.id, teamId }); return createToolResponse(`āœ… Successfully deployed Railway template:\n\n**Template:** ${templateToDeploy.name}\n**Template ID:** ${templateToDeploy.id}\n**Project:** ${projectResult.project.name} (${currentProjectId})\n**Environment:** ${currentEnvironmentId}\n**Workflow ID:** ${result.workflowId}\n\nThe template has been deployed successfully to the current Railway project and environment.`); } catch (error) { const errorMessage = error instanceof Error ? error.message : "Unknown error occurred"; return createToolResponse(`āŒ Failed to search/deploy Railway template **Error:** ${errorMessage}\n\n**Next Steps:** • Check your internet connection • Verify that Railway's API is accessible • Make sure you're authenticated with Railway (\`railway login\`)`); } } }; //#endregion export { deployTemplateTool }; //# sourceMappingURL=deploy-template-C06X74Mt.js.map