configure_environment
Set up Python execution environments by configuring conda or virtualenv settings to manage dependencies for code execution.
Instructions
Change the environment configuration settings
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| type | Yes | Type of Python environment | |
| conda_name | No | Name of the conda environment (required if type is 'conda') | |
| venv_path | No | Path to the virtualenv (required if type is 'venv') | |
| uv_venv_path | No | Path to the UV virtualenv (required if type is 'venv-uv') |
Implementation Reference
- src/index.ts:894-958 (handler)Main handler implementation for the 'configure_environment' tool. Validates input arguments, checks environment type, uses helper to validate config, updates global ENV_CONFIG, and returns JSON response with previous and current config.case "configure_environment": { // Safely access and validate arguments const rawArgs = request.params.arguments || {}; // Check if type exists and is one of the allowed values if (!rawArgs || typeof rawArgs !== 'object' || !('type' in rawArgs) || !['conda', 'venv', 'venv-uv'].includes(String(rawArgs.type))) { return { content: [{ type: "text", text: JSON.stringify({ status: 'error', error: "Invalid arguments: 'type' is required and must be one of 'conda', 'venv', or 'venv-uv'" }), isError: true }] }; } // Now we can safely create a properly typed object const args: ConfigureEnvironmentArgs = { type: String(rawArgs.type) as 'conda' | 'venv' | 'venv-uv', conda_name: 'conda_name' in rawArgs ? String(rawArgs.conda_name) : undefined, venv_path: 'venv_path' in rawArgs ? String(rawArgs.venv_path) : undefined, uv_venv_path: 'uv_venv_path' in rawArgs ? String(rawArgs.uv_venv_path) : undefined, }; // Validate configuration const validationError = validateEnvironmentConfig(args); if (validationError) { return { content: [{ type: "text", text: JSON.stringify({ status: 'error', error: validationError }), isError: true }] }; } // Update configuration const previousConfig = { ...ENV_CONFIG }; ENV_CONFIG = { ...ENV_CONFIG, type: args.type, ...(args.conda_name && { conda_name: args.conda_name }), ...(args.venv_path && { venv_path: args.venv_path }), ...(args.uv_venv_path && { uv_venv_path: args.uv_venv_path }) }; return { content: [{ type: "text", text: JSON.stringify({ status: 'success', message: 'Environment configuration updated', previous: previousConfig, current: ENV_CONFIG }), isError: false }] }; }
- src/index.ts:721-726 (schema)TypeScript interface defining the expected input schema for the configure_environment tool arguments.interface ConfigureEnvironmentArgs { type: 'conda' | 'venv' | 'venv-uv'; conda_name?: string; venv_path?: string; uv_venv_path?: string; }
- src/index.ts:652-677 (registration)Tool registration in the ListTools response, defining name, description, and input schema matching the handler args.name: "configure_environment", description: "Change the environment configuration settings", inputSchema: { type: "object", properties: { type: { type: "string", enum: ["conda", "venv", "venv-uv"], description: "Type of Python environment" }, conda_name: { type: "string", description: "Name of the conda environment (required if type is 'conda')" }, venv_path: { type: "string", description: "Path to the virtualenv (required if type is 'venv')" }, uv_venv_path: { type: "string", description: "Path to the UV virtualenv (required if type is 'venv-uv')" } }, required: ["type"] } },
- src/index.ts:731-740 (helper)Helper function to validate the environment configuration arguments based on the selected type.function validateEnvironmentConfig(config: ConfigureEnvironmentArgs): string | null { if (config.type === 'conda' && !config.conda_name) { return "conda_name is required when type is 'conda'"; } else if (config.type === 'venv' && !config.venv_path) { return "venv_path is required when type is 'venv'"; } else if (config.type === 'venv-uv' && !config.uv_venv_path) { return "uv_venv_path is required when type is 'venv-uv'"; } return null; }