generate-domain
Generate a domain for your Railway project. Returns the existing domain URL if one is already configured, or creates a new domain for the project or specific service.
Instructions
Generate a domain for the currently linked Railway project. If a domain already exists, it will return the existing domain URL. Optionally specify a service to generate the domain for.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| workspacePath | Yes | The path to the workspace to generate domain for | |
| service | No | The name of the service to generate the domain for (optional) |
Implementation Reference
- src/tools/generate-domain.ts:22-46 (handler)The main execution logic for the 'generate-domain' tool. Calls the helper generateRailwayDomain, handles errors, and returns formatted responses using createToolResponse.handler: async ({ workspacePath, service }: GenerateDomainOptions) => { try { const domain = await generateRailwayDomain({ workspacePath, service, }); return createToolResponse( `ā Successfully generated Railway domain${ service ? ` for service '${service}'` : "" }:\n\nš ${domain}\n\n**Note:** This domain is now available for your Railway project.` ); } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : "Unknown error occurred"; return createToolResponse( "ā Failed to generate Railway domain\n\n" + `**Error:** ${errorMessage}\n\n` + "**Next Steps:**\n" + "⢠Ensure you have a Railway project linked\n" + "⢠Check that you have permissions to generate domains\n" + "⢠Verify the project has been deployed at least once\n" + "⢠Run `railway link` to ensure proper project connection" ); } },
- src/tools/generate-domain.ts:11-21 (schema)Zod-based input schema defining parameters for the tool: workspacePath (required string) and service (optional string).inputSchema: { workspacePath: z .string() .describe("The path to the workspace to generate domain for"), service: z .string() .optional() .describe( "The name of the service to generate the domain for (optional)" ), },
- src/index.ts:21-31 (registration)Dynamic registration of all tools (including 'generate-domain') to the MCP server using registerTool with name, schema details, and handler.Object.values(tools).forEach((tool) => { server.registerTool( tool.name, { title: tool.title, description: tool.description, inputSchema: tool.inputSchema, }, tool.handler, ); });
- src/tools/index.ts:6-6 (registration)Export of the generateDomainTool object from its definition file, making it available for bulk import and registration.export { generateDomainTool } from "./generate-domain";
- src/cli/domain.ts:10-38 (helper)Core helper function that executes the 'railway domain --json' CLI command (optionally for a service), parses JSON output, and returns the domain URL or error.export const generateRailwayDomain = async ({ workspacePath, service, }: GenerateDomainOptions): Promise<string> => { try { await checkRailwayCliStatus(); const projectResult = await getLinkedProjectInfo({ workspacePath }); if (!projectResult.success) { throw new Error(projectResult.error); } // Build the railway domain command with options let command = "railway domain --json"; if (service) { command += ` --service ${service}`; } const domainResult = await runRailwayJsonCommand(command, workspacePath); if (domainResult.domain) { return domainResult.domain; } throw new Error("No domain found in Railway CLI JSON response"); } catch (error: unknown) { return analyzeRailwayError(error, "railway domain --json"); } };