Skip to main content
Glama

detect_environment

Identifies the current environment context using wavefunction collapse, returning detected environment and its source such as NODE_ENV, git branch, or project configuration.

Instructions

Detect the current environment context (wavefunction collapse). Returns the detected environment and its source (NODE_ENV, git branch, project config, etc.).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectPathNoProject root path for project-scoped secrets

Implementation Reference

  • The core logic for `collapseEnvironment` which is invoked by the `detect_environment` MCP tool to determine the environment context.
    export function collapseEnvironment(
      ctx: CollapseContext = {},
    ): CollapseResult | null {
      if (ctx.explicit) {
        return { env: ctx.explicit, source: "explicit" };
      }
    
      const qringEnv = process.env.QRING_ENV;
      if (qringEnv) {
        return { env: qringEnv, source: "QRING_ENV" };
      }
    
      const nodeEnv = process.env.NODE_ENV;
      if (nodeEnv) {
        const mapped = mapEnvName(nodeEnv);
        return { env: mapped, source: "NODE_ENV" };
      }
    
      const config = readProjectConfig(ctx.projectPath);
      if (config?.env) {
        return { env: config.env, source: "project-config" };
      }
    
      const branch = detectGitBranch(ctx.projectPath);
      if (branch) {
        const branchMap = { ...BRANCH_ENV_MAP, ...config?.branchMap };
        const mapped = branchMap[branch];
        if (mapped) {
          return { env: mapped, source: "git-branch" };
        }
      }
    
      if (config?.defaultEnv) {
        return { env: config.defaultEnv, source: "project-config" };
      }
    
      return null;
    }
  • Registration of the `detect_environment` MCP tool, which wraps the `collapseEnvironment` core logic.
    server.tool(
      "detect_environment",
      "Detect the current environment context (wavefunction collapse). Returns the detected environment and its source (NODE_ENV, git branch, project config, etc.).",
      {
        projectPath: projectPathSchema,
      },
      async (params) => {
        const result = collapseEnvironment({
          projectPath: params.projectPath ?? process.cwd(),
        });
    
        if (!result) {
          return text(
            "No environment detected. Set QRING_ENV, NODE_ENV, or create .q-ring.json",
          );
        }
    
        return text(JSON.stringify(result, null, 2));
      },

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/I4cTime/quantum_ring'

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