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

list_environments

Retrieve all available environments for your current project to manage API testing and development workflows.

Instructions

List all environments for current project

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectIdNoProject ID (optional, will use current project if not provided)
activeOnlyNoShow only active environments

Implementation Reference

  • Core handler function implementing the list_environments tool logic: detects project config, initializes backend client and EnvironmentService, fetches environments, formats them into a readable list with variable counts, handles errors.
    export async function handleListEnvironments(args: any): Promise<McpToolResponse> {
      try {
        const { projectId, activeOnly } = args;
    
        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)
                }
              ]
            };
          }
        }
    
        // Create environment service
        const envService = new EnvironmentService(
          instances.backendClient.getBaseUrl(),
          instances.backendClient.getToken()
        );
    
        // List environments
        const request: ListEnvironmentsRequest = {
          projectId: targetProjectId,
          activeOnly: activeOnly !== false // default to true
        };
    
        const response = await envService.listEnvironments(request);
    
        if (!response.success) {
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify({
                  success: false,
                  error: response.error || 'Failed to list environments'
                }, null, 2)
              }
            ]
          };
        }
    
        const environments = response.data || [];
    
        // Format response
        let envText = `🌍 Environments List (${environments.length}):\n\n`;
    
        if (environments.length === 0) {
          envText += 'No environments found for this project.\n';
          envText += 'Use create_environment tool to add your first environment.\n';
        } else {
          environments.forEach((env: any, index: number) => {
            const isDefault = env.is_default ? ' [Default]' : '';
            const variables = parseVariables(env.variables);
            const varCount = Object.keys(variables).length;
    
            envText += `${index + 1}. ${env.name} (${env.id})${isDefault}\n`;
            envText += `   - ${varCount} variables\n`;
            if (env.description) {
              envText += `   - ${env.description}\n`;
            }
            envText += '\n';
          });
        }
    
        return {
          content: [
            {
              type: 'text',
              text: envText
            }
          ]
        };
    
      } catch (error: any) {
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({
                success: false,
                error: error.message || 'Unknown error occurred while listing environments'
              }, null, 2)
            }
          ]
        };
      }
    }
  • MCP tool definition for list_environments including input schema with projectId and activeOnly parameters.
    export const listEnvironmentsTool: McpTool = {
      name: 'list_environments',
      description: 'List all environments for current project',
      inputSchema: {
        type: 'object',
        properties: {
          projectId: {
            type: 'string',
            description: 'Project ID (optional, will use current project if not provided)'
          },
          activeOnly: {
            type: 'boolean',
            description: 'Show only active environments',
            default: true
          }
        }
      },
      handler: handleListEnvironments
    };
  • Dynamic registration of the list_environments tool handler in the central tool handlers factory.
    'list_environments': async (args: any) => {
      const { handleListEnvironments } = await import('./environment/handlers/listHandler.js');
      return handleListEnvironments(args);
    },
  • TypeScript interfaces defining input (ListEnvironmentsRequest) and output (ListEnvironmentsResponse) for environment listing operations.
    export interface ListEnvironmentsRequest {
      projectId?: string;
      activeOnly?: boolean;
    }
    
    export interface ListEnvironmentsResponse {
      success: boolean;
      data?: Environment[];
      message?: string;
      error?: string;
    }
  • Export of all environment tools array, which includes listEnvironmentsTool and is imported into main tools index for complete toolset registration.
    export const environmentTools = [
      listEnvironmentsTool,
      getEnvironmentDetailsTool,
      createEnvironmentTool,
      updateEnvironmentVariablesTool,
      setDefaultEnvironmentTool,
      deleteEnvironmentTool
    ];
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states it's a list operation but doesn't mention whether it's paginated, what format the results come in, permission requirements, rate limits, or error conditions. 'List all environments' implies a read-only operation but lacks crucial behavioral details.

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 communicates the core purpose without any wasted words. It's appropriately sized for a simple list operation and gets straight to the point.

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?

For a list operation with no annotations and no output schema, the description is insufficient. It doesn't explain what an 'environment' is in this context, what information is returned, or how results are structured. Given the lack of structured metadata, the description should provide more context about the operation's behavior and results.

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 input schema has 100% description coverage, so parameters are well-documented in the schema. The description adds no additional parameter information beyond what's in the schema, which is acceptable given the comprehensive schema coverage. The baseline of 3 is appropriate when 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 ('List') and resource ('all environments for current project'), making the purpose immediately understandable. It doesn't specifically differentiate from sibling tools like 'list_endpoints' or 'list_flows', but the resource specificity is adequate for basic understanding.

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 like 'get_environment_details' or 'list_endpoints'. It mentions 'current project' but doesn't explain how that's determined or what happens if no project is set, leaving usage context unclear.

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