template_deploy
Deploy new services from pre-configured templates to quickly launch applications on Railway infrastructure, ideal for starting projects with standardized setups.
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)Handler function that executes the tool logic by delegating to templatesService.deployTemplate(projectId, templateId, environmentId, teamId).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:55-60 (schema)Input schema using Zod validators and descriptions for the tool parameters.{ 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/template.tool.ts:34-69 (registration)Registration of the template_deploy tool via createTool, including formatted description, input schema, and handler function.createTool( "template_deploy", formatToolDescription({ type: 'WORKFLOW', description: "Deploy a new service from a template", bestFor: [ "Starting new services from templates", "Quick service deployment", "Using pre-configured templates" ], notFor: [ "Custom service configurations", "GitHub repository deployments (use service_create_from_repo)" ], relations: { prerequisites: ["template_list"], alternatives: ["service_create_from_repo", "service_create_from_image", "database_deploy"], nextSteps: ["service_info", "variable_list"], related: ["service_update", "deployment_trigger"] } }), { 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)") }, async ({ projectId, templateId, environmentId, teamId }: { projectId: string; templateId: string; environmentId: string; teamId?: string; }) => { return templatesService.deployTemplate(projectId, templateId, environmentId, teamId); } ),
- Core implementation logic in TemplatesService: retrieves template details by ID from list, then invokes repository deployment, formats success/error responses.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 performs the GraphQL mutation 'templateDeployV2' to initiate the template deployment workflow.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; }