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
| Name | Required | Description | Default |
|---|---|---|---|
| projectPath | No | Project root path for project-scoped secrets |
Implementation Reference
- src/core/collapse.ts:81-118 (handler)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; } - src/mcp/server.ts:267-285 (registration)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)); },