Skip to main content
Glama
martin-1103
by martin-1103

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

TableJSON 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)

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
    ];
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the action ('Create') but doesn't describe what happens on success/failure, permissions required, whether the environment is immediately usable, or any side effects. For a creation tool with zero annotation coverage, this leaves significant gaps in understanding the tool's behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core action ('Create a new environment with variables'). There is no wasted text, and it directly communicates the essential purpose without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of creating an environment (a mutation with 5 parameters), no annotations, and no output schema, the description is incomplete. It doesn't cover behavioral aspects like permissions, success criteria, or return values, leaving the agent with insufficient context to use the tool effectively beyond basic parameter passing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description mentions 'variables' but doesn't elaborate beyond what the schema provides. With 100% schema description coverage, the schema already documents all 5 parameters thoroughly (e.g., 'variables' as JSON string/object/comma-separated). The description adds no additional parameter context, so it meets the baseline of 3 where the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'Create' and the resource 'new environment with variables', making the purpose immediately understandable. It distinguishes from siblings like 'delete_environment' or 'update_environment_variables' by focusing on creation. However, it doesn't explicitly differentiate from other creation tools like 'create_endpoint' or 'create_flow' beyond the resource type.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing a project), exclusions, or comparisons to siblings like 'set_default_environment' or 'update_environment_variables'. Usage is implied by the name but not explicitly stated.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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