Provides secure Python code execution in isolated Docker containers as a fallback sandbox backend, with support for dependency installation and persistent workspace state.
Analyzes directory structures while respecting .gitignore patterns to generate XML representations of codebases with intelligent summarization.
Directory Intelligence Tool
A comprehensive toolkit for analyzing directory structures and executing code in secure sandboxes. This project combines intelligent directory analysis with a secure execution environment for Programmatic Tool Calling (PTC).
Project Overview
This project consists of three main components:
Directory Intelligence Tool - Analyzes directory structures and generates XML representations
FastMCP Server - Exposes the directory tool as a FastMCP service
Sandbox Execution Engine - Securely executes Python code with Daytona/Docker backends
Components
1. Directory Intelligence Tool (src/directory_tool.py)
A .gitignore-aware directory structure analyzer that generates XML hierarchies with intelligent summarization for large directories.
Key Features:
Respects
.gitignorepatterns usingpathspeclibraryGenerates structured XML output with
<dir>,<file>, and<summary>tagsAutomatically summarizes directories with more than 50 files
Handles edge cases: symlink loops, permission errors, malformed .gitignore
Provides both FastMCP tool interface and command-line usage
Main Function:
2. FastMCP Server (src/mcp_server.py)
Exposes the Directory Intelligence Tool as a FastMCP service with HTTP transport.
Key Features:
Configurable server settings via
config/config.jsonAutomatic Daytona/Docker backend detection
HTTP transport for network accessibility
Comprehensive error handling and logging
Graceful shutdown handling
Usage:
3. Sandbox Execution Engine (src/execute_code.py)
Secure Python code execution environment with Daytona primary backend and Docker fallback.
Key Features:
Sequential execution with threading locks
Persistent workspace maintains state between calls
Dependency installation support
Complete host filesystem isolation
Comprehensive error handling
Main Function:
4. Development Environment (.devcontainer/devcontainer.json)
Pre-configured development environment with:
Python 3.11 with required dependencies
Docker-in-Docker support
VS Code extensions for Python development
Port forwarding for FastMCP server
Reproducible environment setup
5. Test Suite (test/test.py)
Comprehensive test suite covering:
Basic script execution and output capture
Persistent workspace behavior
Error handling and edge cases
Sequential execution verification
Dependency installation testing
Installation
Prerequisites
Python 3.11+
Either Daytona SDK or Docker SDK (for sandbox execution)
Git (for directory analysis)
Setup Steps
Clone the repository:
Install dependencies:
Optional: Install Daytona SDK for primary sandbox backend:
Optional: Install Docker SDK for fallback sandbox backend:
Usage
Running the FastMCP Server
The server will start and print:
Using the Directory Intelligence Tool
As a Python module:
Command line usage:
Using the Sandbox Execution Engine
Development Environment
Using VS Code DevContainer:
Open project in VS Code
Install DevContainer extension
Click "Reopen in Container" when prompted
Environment will be set up automatically
Manual development setup:
End-to-End Example
Here's a complete example combining both tools:
Testing
Run the test suite:
Troubleshooting
Common Issues
"No sandbox backend available"
Install Daytona SDK:
pip install daytona-sdkOr install Docker SDK:
pip install dockerEnsure Docker daemon is running
"FastMCP server won't start"
Check if port 8000 is already in use
Verify all dependencies are installed
Check FastMCP version compatibility
"Directory analysis fails"
Ensure you have read permissions for the target directory
Check that the path exists and is accessible
Verify .gitignore file format if present
"Tests fail with import errors"
Ensure PYTHONPATH includes the src directory
Check that all dependencies are installed
Verify you're running tests from the project root
Debug Mode
Enable debug logging:
Project Structure
Contributing
Fork the repository
Create a feature branch
Make your changes
Run the test suite
Submit a pull request
License
This project is part of the Directory Intelligence Tool suite.