createSiteFromGitHub
Deploy a Netlify site directly from a GitHub repository by specifying build commands, publish directory, and environment variables for automated hosting.
Instructions
Create a new Netlify site from a GitHub repository
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Name for the new site (will be used as subdomain) | |
| repo | Yes | GitHub repository in format owner/repo | |
| branch | No | Branch to deploy from (default: main) | main |
| buildCommand | Yes | Build command to run (e.g., npm run build) | |
| publishDir | Yes | Directory containing the built files to publish (e.g., dist, build) | |
| envVars | No | Environment variables for the build process |
Implementation Reference
- src/index.ts:200-264 (handler)The handler logic for the 'createSiteFromGitHub' tool. Validates input parameters, constructs the site creation payload for the Netlify API, makes a POST request to /sites, and returns the site details or throws appropriate MCP errors on failure.case 'createSiteFromGitHub': { const args = request.params.arguments as unknown as CreateSiteFromGitHubArgs; if (!args?.name || !args?.repo || !args?.buildCommand || !args?.publishDir) { throw new McpError( ErrorCode.InvalidParams, 'Missing required parameters: name, repo, buildCommand, and publishDir are required' ); } // Validate repo format if (!args.repo.match(/^[\w.-]+\/[\w.-]+$/)) { throw new McpError( ErrorCode.InvalidParams, 'Invalid repo format. Must be in format: owner/repo' ); } try { const siteData = { name: args.name, repo: { provider: 'github', repo: args.repo, branch: args.branch || 'main', cmd: args.buildCommand, dir: args.publishDir, }, }; // Add environment variables if provided if (args.envVars) { siteData.repo['env'] = args.envVars; } const response = await this.axiosInstance.post('/sites', siteData); return { content: [ { type: 'text', text: JSON.stringify({ success: true, site: { id: response.data.id, name: response.data.name, url: response.data.url, admin_url: response.data.admin_url, deploy_url: response.data.deploy_url, created_at: response.data.created_at, }, message: `Site created successfully! Visit ${response.data.admin_url} to manage it.`, }, null, 2), }, ], }; } catch (error) { if (axios.isAxiosError(error)) { throw new McpError( ErrorCode.InternalError, `Failed to create site: ${this.formatNetlifyError(error)}` ); } throw error; } }
- src/index.ts:106-141 (registration)Tool registration in the ListTools handler, defining the name, description, and JSON inputSchema for 'createSiteFromGitHub'.{ name: 'createSiteFromGitHub', description: 'Create a new Netlify site from a GitHub repository', inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Name for the new site (will be used as subdomain)', }, repo: { type: 'string', description: 'GitHub repository in format owner/repo', }, branch: { type: 'string', description: 'Branch to deploy from (default: main)', default: 'main', }, buildCommand: { type: 'string', description: 'Build command to run (e.g., npm run build)', }, publishDir: { type: 'string', description: 'Directory containing the built files to publish (e.g., dist, build)', }, envVars: { type: 'object', description: 'Environment variables for the build process', additionalProperties: { type: 'string' }, }, }, required: ['name', 'repo', 'buildCommand', 'publishDir'], }, },
- src/index.ts:25-32 (schema)TypeScript interface defining the shape of arguments for the createSiteFromGitHub handler, used for type assertion.interface CreateSiteFromGitHubArgs { name: string; repo: string; branch: string; buildCommand: string; publishDir: string; envVars?: Record<string, string>; }