create-project-and-link
Create a new Railway project and link it to your current directory for deployment and management.
Instructions
Create a new Railway project and link it to the current directory
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectName | Yes | ||
| workspacePath | Yes | The path to the workspace to create the project in |
Implementation Reference
- The MCP tool handler function that invokes the createRailwayProject helper, formats success/error responses using createToolResponse, and handles exceptions gracefully.handler: async ({ projectName, workspacePath }: CreateProjectOptions) => { try { const result = await createRailwayProject({ projectName, workspacePath, }); return createToolResponse( `✅ Successfully created Railway project "${projectName}":\n\n${result}\n\nThis project is now linked and all commands will be run in the context of the newly created project. No need to run \`railway link\` again.`, ); } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : "Unknown error occurred"; return createToolResponse( "❌ Failed to create Railway project\n\n" + `**Error:** ${errorMessage}\n\n` + "**Next Steps:**\n" + "• Ensure you are logged into Railway CLI (`railway login`)\n" + "• Check that the project name is valid and unique\n" + "• Verify you have permissions to create projects\n" + "• Ensure the workspace path is accessible", ); } },
- Zod-based input schema defining required parameters: projectName (string) and workspacePath (string with description). Used for tool input validation.inputSchema: { projectName: z.string(), workspacePath: z .string() .describe("The path to the workspace to create the project in"), },
- src/index.ts:21-31 (registration)Generic registration loop that registers all exported tools (including create-project-and-link) from ./tools into the McpServer instance.Object.values(tools).forEach((tool) => { server.registerTool( tool.name, { title: tool.title, description: tool.description, inputSchema: tool.inputSchema, }, tool.handler, ); });
- src/cli/projects.ts:91-117 (helper)Core helper function that executes Railway CLI commands (`railway init` and `railway link`) to create and link a new project, checks for existing links, and handles CLI errors.export const createRailwayProject = async ({ projectName, workspacePath, }: CreateProjectOptions): Promise<string> => { try { await checkRailwayCliStatus(); // Check if there's already a linked project const linkedProjectResult = await getLinkedProjectInfo({ workspacePath }); if (linkedProjectResult.success && linkedProjectResult.project) { return "A Railway project is already linked to this workspace. No new project created."; } const { output: initOutput } = await runRailwayCommand( `railway init --name ${projectName}`, workspacePath, ); const { output: linkOutput } = await runRailwayCommand( `railway link -p ${projectName}`, workspacePath, ); return `${initOutput}\n${linkOutput}`; } catch (error: unknown) { return analyzeRailwayError(error, `railway init --name ${projectName}`); } };