Mastra Factory is an open source environment for building software with coding agents. Connect your repository to turn issues into plans, implementations, and reviewed pull requests.
Scaffold it with npm create factory. This project contains the Factory Server and its configuration. Keep it separate from the repository you want agents to change.
Read the documentation or watch the Mastra Factory overview.
This template uses Mastra platform services for authentication and sandboxes, and PostgreSQL for storage. npm create factory provisions a platform project and a Postgres database and writes their credentials to .env. For a direct checkout, run npm install, copy .env.example to .env, and fill in the values from your Mastra platform project. To run without the platform, use npm create factory -- --no-platform, which scaffolds the self-hosted template instead.
npm create factory also generates FACTORY_CREDENTIAL_ENCRYPTION_KEY, which encrypts stored model keys and integration secrets. If it's missing from .env, generate a key once for this project:
openssl rand -base64 32Save the output as FACTORY_CREDENTIAL_ENCRYPTION_KEY in .env. Preserve the key across restarts and deployments, and keep a protected backup. See credential encryption for details.
From the Factory project directory, start the server:
npm run devWith the default setup, open the local URL printed by the server and sign in through Mastra platform. One server serves both the Factory UI and API. After login you'll see an onboarding wizard, select the repository agents should change. Use Manage GitHub connection to grant the GitHub App access if the repository is missing. Optionally add Linear. Connect a model provider using an API key or a supported subscription, then choose the Factory model.
- Open Settings → Work Intake → GitHub issues. Enable Sync GitHub issues and select your repository. Each teammate chooses their own issue sources.
- Create a small GitHub issue, such as adding contribution guidance to the repository's README.
- Find the issue in Work → Intake, select Investigate, and open its session to follow the agent's work.
Continue with the issue-to-pull-request walkthrough to review a plan and take the change through implementation and pull request review.
Choose authentication, storage, and sandboxes independently. Model providers and issue sources are configured through the Factory UI. Server settings live in .env; restart the server after changing them.
| Configuration | What you can change |
|---|---|
| Models | Provider access, personal or organization credentials, and the default model. |
| GitHub | Repository access and personal issue intake. |
| Linear | Workspace connection, project selection, and routing issues to a Factory. |
| Jira | Site connections, project selection, and routing issues to a Factory. |
| Slack | App setup, account linking, and starting sessions from Slack. |
| Auth | Mastra platform sign-in or another provider with Server and Studio support. |
| Storage | The database connection or Factory storage adapter. |
| Sandboxes | Mastra platform, local execution, or another Mastra sandbox provider. |
The server requires DATABASE_URL, a PostgreSQL database with pgvector. Deployments to Mastra platform receive it from the project's attached database.
Slack is bundled but disabled unless you set Slack credentials. For webhook mode, set SLACK_APP_SIGNING_SECRET, SLACK_APP_BOT_TOKEN, SLACK_APP_CLIENT_ID, and SLACK_APP_CLIENT_SECRET. For Socket Mode, use SLACK_APP_TOKEN instead of SLACK_APP_SIGNING_SECRET; the other three variables are still needed. A bot token alone cannot receive events or link Slack users, and an incomplete configuration fails at startup rather than silently disabling Slack. Set MASTRACODE_PUBLIC_URL to your HTTPS Factory origin for account-linking callbacks; for local development, set MASTRACODE_CHANNELS_PUBLIC_URL to an HTTPS tunnel origin instead. See Slack configuration for app setup and callback URLs.
With MASTRA_PLATFORM_SECRET_KEY (or MASTRA_PLATFORM_ACCESS_TOKEN) set, npm run dev runs agent commands in local sandboxes on your machine, and deployments use Mastra platform sandboxes, which also need MASTRA_PROJECT_ID and MASTRA_ENVIRONMENT_ID. To pick a sandbox yourself, pass sandbox to MastraFactory in src/mastra/index.ts, for example new LocalFactorySandbox() from @mastra/factory.
Deploy the Factory Server to your Mastra platform project:
npm run deployThe CLI reports the deployed Factory URL. See Deployment for environment configuration and deployment options.
Run Factory as a persistent Node.js service on a virtual machine or in a container. Configure persistent storage and set MASTRACODE_PUBLIC_URL to the public HTTPS origin. Supply your provider credentials through the deployment environment, then build and start the server:
npm run build
npm run startKeep the project's CLI dependencies installed for these commands. You can use Mastra platform services while hosting the Factory Server elsewhere. See self-hosting for runtime requirements and setup steps.
| Script | What it does |
|---|---|
npm run dev |
Start the local Factory Server with its UI and API. |
npm run check |
Typecheck the Factory Server. |
npm run build |
Build the server and Factory UI in .mastra/output. |
npm run start |
Run the production build. |
npm run deploy |
Build and deploy to Mastra platform. |
- Runtime: Use a Node.js version that matches
engines.nodein this project'spackage.json. - Port changes: Set
PORTand updateMASTRACODE_PUBLIC_URLto match. Update callback URLs for any auth or integration apps you manage. - Missing issues: Check repository access and your Work Intake selections. See intake troubleshooting.
See Troubleshooting for sign-in, provider access, and sandbox errors, or Environment variables for server settings.
Apache-2.0