Skip to main content
Glama

create_environment

Create a new environment with custom variables to manage API configurations and testing workflows for backend development.

Instructions

Create a new environment with variables

Input Schema

NameRequiredDescriptionDefault
nameYesEnvironment name
descriptionNoEnvironment description
variablesNoEnvironment variables (JSON string, object, or comma-separated key=value pairs)
isDefaultNoSet as default environment
projectIdNoProject ID (optional, will use current project if not provided)

Input Schema (JSON Schema)

{ "properties": { "description": { "description": "Environment description", "type": "string" }, "isDefault": { "default": false, "description": "Set as default environment", "type": "boolean" }, "name": { "description": "Environment name", "type": "string" }, "projectId": { "description": "Project ID (optional, will use current project if not provided)", "type": "string" }, "variables": { "description": "Environment variables (JSON string, object, or comma-separated key=value pairs)", "type": "string" } }, "required": [ "name" ], "type": "object" }

Implementation Reference

  • The main handler function that executes the create_environment tool logic. It validates inputs, parses variables, uses EnvironmentService to create the environment via backend API, and returns formatted MCP response.
    export async function handleCreateEnvironment(args: any): Promise<McpToolResponse> { try { const { name, description, variables, isDefault, projectId } = args; if (!name) { return { content: [ { type: 'text', text: JSON.stringify({ success: false, error: 'Environment name is required' }, null, 2) } ] }; } const instances = await getInstances(); // Get project ID if not provided let targetProjectId = projectId; if (!targetProjectId) { const config = await instances.configManager.detectProjectConfig(); targetProjectId = config?.project?.id; if (!targetProjectId) { return { content: [ { type: 'text', text: JSON.stringify({ success: false, error: 'Project ID not found in config and not provided in arguments' }, null, 2) } ] }; } } // Parse variables let parsedVariables: Record<string, string> = {}; if (variables) { if (typeof variables === 'string') { try { parsedVariables = JSON.parse(variables); } catch (e) { return { content: [ { type: 'text', text: JSON.stringify({ success: false, error: 'Variables must be valid JSON string or object' }, null, 2) } ] }; } } else if (typeof variables === 'object') { parsedVariables = variables as Record<string, string>; } } // Create environment service const envService = new EnvironmentService( instances.backendClient.getBaseUrl(), instances.backendClient.getToken() ); // Create environment const createRequest = { name: name.trim(), description: description?.trim(), variables: parsedVariables, isDefault: isDefault || false, projectId: targetProjectId }; const response = await envService.createEnvironment(createRequest); if (!response.success) { return { content: [ { type: 'text', text: JSON.stringify({ success: false, error: response.error || 'Failed to create environment' }, null, 2) } ] }; } return { content: [ { type: 'text', text: JSON.stringify({ success: true, data: response.data, message: 'Environment created successfully' }, null, 2) } ] }; } catch (error: any) { return { content: [ { type: 'text', text: JSON.stringify({ success: false, error: error.message || 'Unknown error occurred while creating environment' }, null, 2) } ] }; }
  • MCP tool definition including input schema validation for create_environment parameters.
    export const createEnvironmentTool: McpTool = { name: 'create_environment', description: 'Create a new environment with variables', inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Environment name' }, description: { type: 'string', description: 'Environment description' }, variables: { type: 'string', description: 'Environment variables (JSON string, object, or comma-separated key=value pairs)' }, isDefault: { type: 'boolean', description: 'Set as default environment', default: false }, projectId: { type: 'string', description: 'Project ID (optional, will use current project if not provided)' } }, required: ['name'] }, handler: handleCreateEnvironment };
  • Registration of the create_environment tool handler in the central tool handlers factory, dynamically importing the actual handler.
    'create_environment': async (args: any) => { const { handleCreateEnvironment } = await import('./environment/handlers/detailsHandler.js'); return handleCreateEnvironment(args); },
  • Inclusion of environmentTools (containing create_environment) into ALL_TOOLS array for MCP tool listing.
    ...environmentTools,
  • Export of all environment tools array, registering createEnvironmentTool for use.
    export const environmentTools = [ listEnvironmentsTool, getEnvironmentDetailsTool, createEnvironmentTool, updateEnvironmentVariablesTool, setDefaultEnvironmentTool, deleteEnvironmentTool ];

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/martin-1103/mcp2'

If you have feedback or need assistance with the MCP directory API, please join our Discord server