How Desktop Commander Collects System Information for AI Context
Desktop Commander collects system information for AI context through the getSystemInfo function in src/utils/system-info.ts, which aggregates OS detection, container environment analysis, toolchain discovery, and process metadata into a structured SystemInfo object.
The wonderwhy-er/DesktopCommanderMCP repository implements a comprehensive environment detection pipeline that enables AI assistants to understand the host system, container constraints, and available development tools. By capturing runtime metadata through low-level system calls and environment inspection, Desktop Commander ensures that LLM-powered interactions are contextually aware of platform-specific paths, container boundaries, and installed toolchains.
Architecture of the System Detection Pipeline
The detection logic centers on src/utils/system-info.ts, where the getSystemInfo function (lines 500-526) orchestrates multiple specialized detectors. This modular approach allows the system to build a complete snapshot without blocking the main execution thread, aggregating data from platform APIs, filesystem markers, and subprocess invocations.
Runtime Platform Detection
At the foundation of the pipeline, Desktop Commander uses Node.js os.platform() to label the operating system as win32, darwin, or linux. The detection routine (lines 500-505) derives three boolean flags—isWindows, isMacOS, and isLinux—that subsequent helpers reference to determine platform-specific behavior, path conventions, and available system utilities.
Container Environment Awareness
For environments running inside containers, the system implements a multi-layer detection strategy. The detectContainerEnvironment function (lines 69-81) inspects environment variables such as MCP_CLIENT_DOCKER and KUBERNETES_SERVICE_HOST, checks for the existence of /.dockerenv, and parses /proc/1/cgroup to identify Docker, Kubernetes, Podman, LXC, or systemd-nspawn runtimes.
Once containerization is confirmed, discoverContainerMounts (lines 87-136) parses /proc/mounts and scans common mount points like /mnt and /home to enumerate host-to-container bind mounts. Additionally, getContainerEnvironment (line 42) enriches the metadata by extracting the hostname, Docker labels, and Kubernetes service-account files, exposing fields such as containerName, dockerImage, and kubernetesNamespace.
Toolchain and Process Discovery
Beyond the operating system and container context, Desktop Commander identifies available development tools to inform AI suggestions about build systems, package managers, and runtime environments.
Node.js and Python Detection
The detectNodeInfo function (lines 43-60) captures the current Node.js environment by reading process.version, process.execPath, and the optional npm_version environment variable. For Python environments, detectPythonInfo (lines 66-94) attempts to execute a series of common executables—including python3, python, and py—parsing their --version output to determine availability and exact version numbers.
Process Context Capture
The current process context is captured in the processInfo object (lines 595-600), which records the PID, architecture, platform string, and Node.js version map. This metadata helps AI assistants understand the execution context when suggesting process-management commands or debugging deployment issues.
Building AI-Ready Context
Raw system data is transformed into actionable AI guidance through two specialized formatting functions that consume the SystemInfo structure.
The SystemInfo Structure
The getSystemInfo function returns a comprehensive SystemInfo object that aggregates all detection results. It includes examplePaths (lines 515-525) tailored to the detected platform—such as C:\Users\username for Windows, /Users/username for macOS, and /home/username for Linux. When running inside a container, the function appends discovered mount points under examplePaths.accessible, ensuring AI models understand which host directories are reachable within the container boundary.
Generating LLM Guidance
Two helper functions convert technical metadata into human-readable instructions:
getOSSpecificGuidance(lines 531-555) emits platform and container-specific advice, including mount-point warnings and path-translation rules for cross-platform compatibility.getDevelopmentToolGuidance(lines 560-608) surfaces recommendations for Node.js, Python, and OS-specific tooling based on detected availability.
// Retrieve full system snapshot for AI context
import { getSystemInfo, getOSSpecificGuidance } from './src/utils/system-info';
const sysInfo = getSystemInfo();
console.log('System snapshot:', sysInfo);
// Generate AI-friendly guidance for LLM prompts
const guidance = getOSSpecificGuidance(sysInfo);
const prompt = `
You are a developer assistant. Use the following system context to answer the user:
${guidance}
User request: ${userMessage}
`;
Summary
- Central orchestration: The
getSystemInfofunction insrc/utils/system-info.ts(lines 500-526) coordinates all detection helpers into a singleSystemInfoobject. - Platform detection: Uses
os.platform()to set boolean flags for Windows, macOS, and Linux (lines 500-505). - Container awareness:
detectContainerEnvironment(lines 69-81) identifies Docker, Kubernetes, and other runtimes via environment variables and cgroup inspection, whilediscoverContainerMounts(lines 87-136) maps accessible host directories. - Toolchain discovery:
detectNodeInfo(lines 43-60) anddetectPythonInfo(lines 66-94) capture runtime versions and installation paths. - AI integration:
getOSSpecificGuidance(lines 531-555) andgetDevelopmentToolGuidance(lines 560-608) transform raw system data into LLM-ready instructions.
Frequently Asked Questions
How does Desktop Commander detect if it's running inside a container?
The detectContainerEnvironment function (lines 69-81 in src/utils/system-info.ts) checks for environment variables like MCP_CLIENT_DOCKER and KUBERNETES_SERVICE_HOST, the presence of /.dockerenv marker files, and container runtime signatures in /proc/1/cgroup. This multi-factor detection identifies Docker, Kubernetes, Podman, LXC, and systemd-nspawn environments.
What programming languages does the system information detector look for?
According to the source code in src/utils/system-info.ts, Desktop Commander specifically detects Node.js via detectNodeInfo (lines 43-60) by reading process.version and npm_version, and Python via detectPythonInfo (lines 66-94) by attempting to execute python3, python, or py executables and parsing their version strings.
How does the system information get formatted for AI consumption?
Raw detection data is passed to getOSSpecificGuidance (lines 531-555) and getDevelopmentToolGuidance (lines 560-608), which transform the SystemInfo object into natural language instructions. These functions generate platform-specific path examples, container mount warnings, and toolchain recommendations that LLMs can reference when formulating responses.
Can Desktop Commander detect bind mounts in containerized environments?
Yes. When detectContainerEnvironment confirms containerization, the discoverContainerMounts function (lines 87-136) parses /proc/mounts and scans directories like /mnt and /home to identify host-to-container bind mounts. These paths are exposed in examplePaths.accessible within the SystemInfo object, allowing AI assistants to suggest file operations that respect container boundaries.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →