template_deploy
Deploy new services from pre-configured templates to quickly set up infrastructure on Railway.app, ideal for starting standardized projects without custom configurations.
Instructions
[WORKFLOW] Deploy a new service from a template
⚡️ Best for: ✓ Starting new services from templates ✓ Quick service deployment ✓ Using pre-configured templates
⚠️ Not for: × Custom service configurations × GitHub repository deployments (use service_create_from_repo)
→ Prerequisites: template_list
→ Alternatives: service_create_from_repo, service_create_from_image, database_deploy
→ Next steps: service_info, variable_list
→ Related: service_update, deployment_trigger
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectId | Yes | ID of the project to create the service in | |
| templateId | Yes | ID of the template to use | |
| environmentId | Yes | ID of the environment to deploy to | |
| teamId | No | ID of the team to create the service in (if not provided, will use the default team) |
Implementation Reference
- src/tools/template.tool.ts:61-68 (handler)The core handler function for the 'template_deploy' tool, which invokes the templatesService to perform the deployment.async ({ projectId, templateId, environmentId, teamId }: { projectId: string; templateId: string; environmentId: string; teamId?: string; }) => { return templatesService.deployTemplate(projectId, templateId, environmentId, teamId); }
- src/tools/template.tool.ts:56-60 (schema)Zod input schema defining parameters for the template_deploy tool.projectId: z.string().describe("ID of the project to create the service in"), templateId: z.string().describe("ID of the template to use"), environmentId: z.string().describe("ID of the environment to deploy to"), teamId: z.string().optional().describe("ID of the team to create the service in (if not provided, will use the default team)") },
- src/tools/index.ts:16-37 (registration)Registration of all tools, including template_deploy (via ...templateTools), to the MCP server.export function registerAllTools(server: McpServer) { // Collect all tools const allTools = [ ...databaseTools, ...deploymentTools, ...domainTools, ...projectTools, ...serviceTools, ...tcpProxyTools, ...variableTools, ...configTools, ...volumeTools, ...templateTools, ] as Tool[]; // Register each tool with the server allTools.forEach((tool) => { server.tool( ...tool ); }); }
- Helper service method deployTemplate that fetches the template and calls the repository to deploy it.async deployTemplate( projectId: string, templateId: string, environmentId: string, teamId?: string, ) { try { // Get the template const templates = await this.client.templates.listTemplates(); const template = templates.find(t => t.id === templateId); if (!template) { return createErrorResponse(`Template not found: ${templateId}`); } // Deploy the template const response = await this.client.templates.deployTemplate(environmentId, projectId, template.serializedConfig, templateId, teamId); return createSuccessResponse({ text: `Created new service "${template.name}" from template ${template.name} in project ${projectId}. Monitoring workflow status with ID: ${response.workflowId}`, data: response }); } catch (error) { return createErrorResponse(`Error creating service from template: ${formatError(error)}`); } }
- Repository method that executes the GraphQL mutation for deploying the template.async deployTemplate(environmentId: string, projectId: string, serializedConfig: { services: Record<string, ServiceConfig> }, templateId: string, teamId?: string) { const query = ` mutation deployTemplate($environmentId: String, $projectId: String, $templateId: String!, $teamId: String, $serializedConfig: SerializedTemplateConfig!) { templateDeployV2(input: { environmentId: $environmentId, projectId: $projectId, templateId: $templateId, teamId: $teamId, serializedConfig: $serializedConfig }) { projectId workflowId } } `; const response = await this.client.request<{ templateDeployV2: { projectId: string, workflowId: string } }>(query, { environmentId, projectId, templateId, teamId, serializedConfig, }); return response.templateDeployV2; }