MCP Workspace Server
Provides secure, sandboxed file system access for AI assistants to read, write, and manage project files with controlled command execution capabilities, all confined to a designated workspace directory.
README
MCP Workspace Server
A secure, sandboxed Model Context Protocol (MCP) server that gives LLMs like Claude, ChatGPT, and local models (via Ollama) controlled file system access to build and manage projects.
๐ Features
- ๐ Secure Sandboxing: All file operations strictly confined to a designated workspace directory
- ๐ Complete File Operations: Read, write, list, delete files and directories
- ๐ง Command Execution: Run allowed build and test commands (npm, git, etc.)
- ๐ก๏ธ Path Traversal Protection: Comprehensive security against directory escape attempts
- ๐ Atomic Operations: Safe file writes that prevent partial updates
- ๐ Patch Support: Apply targeted file modifications without rewriting entire files
- ๐ซ Read-Only Mode: Optional mode to prevent any write operations
- ๐ Structured Logging: Configurable logging for debugging and monitoring
- โ Fully Tested: 109 passing tests including property-based tests
๐ Table of Contents
- Installation
- Quick Start
- Configuration Guide
- Usage with Different AI Clients
- Available Tools
- Security
- Testing
- Troubleshooting
- Contributing
- License
๐ Installation
Prerequisites
- Node.js v18 or higher (Download)
- npm (comes with Node.js)
- An MCP-compatible client (Claude Desktop, Cline, etc.)
Setup Steps
-
Clone the repository
git clone https://github.com/ShayYeffet/mcp_workspace_server.git cd mcp_workspace_server -
Install dependencies
npm install -
Build the project
npm run build -
Verify installation
npm test
You should see all 109 tests passing! โ
โก Quick Start
For Claude Desktop Users
-
Find your Claude config file:
- Windows:
%APPDATA%\Claude\claude_desktop_config.json - macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
- Windows:
-
Create or edit the file with this configuration:
{ "mcpServers": { "workspace": { "command": "node", "args": ["/ABSOLUTE/PATH/TO/mcp_workspace_server/dist/index.js"], "env": { "MCP_WORKSPACE_ROOT": "/path/to/your/project", "MCP_ALLOWED_COMMANDS": "npm,git,node", "MCP_LOG_LEVEL": "info" } } } } -
Restart Claude Desktop
-
Test it! Ask Claude:
"List all files in my workspace" "Create a new file called test.txt with 'Hello World'"
For Cline (VS Code) Users
-
Install Cline extension from VS Code marketplace
-
Open VS Code Settings (
Ctrl+,orCmd+,) -
Search for "Cline" and find "MCP Servers" section
-
Add this configuration (or edit
settings.json):{ "cline.mcpServers": { "workspace": { "command": "node", "args": ["/ABSOLUTE/PATH/TO/mcp_workspace_server/dist/index.js"], "env": { "MCP_WORKSPACE_ROOT": "/path/to/your/project", "MCP_ALLOWED_COMMANDS": "npm,git,node" } } } } -
Reload VS Code and start using Cline!
โ๏ธ Configuration Guide
๐ง What You MUST Change
When setting up the MCP server, you must customize these values in your config file:
1. Path to the Server (Required)
"args": ["/ABSOLUTE/PATH/TO/mcp_workspace_server/dist/index.js"]
Replace with:
- Windows:
"C:\\Users\\YourName\\path\\to\\mcp_workspace_server\\dist\\index.js" - macOS/Linux:
"/home/username/path/to/mcp_workspace_server/dist/index.js"
How to find it:
# In the mcp_workspace_server directory, run:
pwd # macOS/Linux
cd # Windows
2. Workspace Root Directory (Required)
"MCP_WORKSPACE_ROOT": "/path/to/your/project"
This is THE MOST IMPORTANT setting! This directory is where the AI can read/write files.
Examples:
- Your web project:
"C:\\Users\\YourName\\projects\\my-website" - Your app:
"/home/username/projects/my-app" - A test folder:
"C:\\Users\\YourName\\ai-workspace"
โ ๏ธ Security Note: The AI can ONLY access files inside this directory. Choose carefully!
3. Allowed Commands (Recommended)
"MCP_ALLOWED_COMMANDS": "npm,git,node"
Customize based on your needs:
- Web development:
"npm,git,node,yarn" - Python projects:
"python,pip,git" - No commands:
""(empty string - disables command execution) - Multiple commands:
"npm,git,python,node,cargo,go"
โ ๏ธ Security Note: Only list commands you trust the AI to run!
๐ Optional Configuration
Read-Only Mode
Prevent ALL write operations (useful for analysis only):
"MCP_READ_ONLY": "true"
Logging Level
Control how much logging you see:
"MCP_LOG_LEVEL": "debug" // Options: debug, info, warn, error
Command Timeout
Set maximum time for commands (in milliseconds):
"MCP_COMMAND_TIMEOUT": "600000" // 10 minutes
๐ Complete Configuration Examples
Example 1: Web Development Project
{
"mcpServers": {
"workspace": {
"command": "node",
"args": ["C:\\Users\\John\\mcp_workspace_server\\dist\\index.js"],
"env": {
"MCP_WORKSPACE_ROOT": "C:\\Users\\John\\projects\\my-react-app",
"MCP_ALLOWED_COMMANDS": "npm,git,node,yarn",
"MCP_LOG_LEVEL": "info"
}
}
}
}
Example 2: Python Data Science Project
{
"mcpServers": {
"workspace": {
"command": "node",
"args": ["/home/jane/mcp_workspace_server/dist/index.js"],
"env": {
"MCP_WORKSPACE_ROOT": "/home/jane/projects/data-analysis",
"MCP_ALLOWED_COMMANDS": "python,pip,git,jupyter",
"MCP_LOG_LEVEL": "info"
}
}
}
}
Example 3: Read-Only Code Review
{
"mcpServers": {
"workspace": {
"command": "node",
"args": ["/Users/alex/mcp_workspace_server/dist/index.js"],
"env": {
"MCP_WORKSPACE_ROOT": "/Users/alex/code-to-review",
"MCP_ALLOWED_COMMANDS": "",
"MCP_READ_ONLY": "true",
"MCP_LOG_LEVEL": "warn"
}
}
}
}
Example 4: Multiple Workspaces
You can configure multiple MCP servers for different projects:
{
"mcpServers": {
"project-a": {
"command": "node",
"args": ["C:\\mcp_workspace_server\\dist\\index.js"],
"env": {
"MCP_WORKSPACE_ROOT": "C:\\projects\\project-a",
"MCP_ALLOWED_COMMANDS": "npm,git"
}
},
"project-b": {
"command": "node",
"args": ["C:\\mcp_workspace_server\\dist\\index.js"],
"env": {
"MCP_WORKSPACE_ROOT": "C:\\projects\\project-b",
"MCP_ALLOWED_COMMANDS": "python,pip"
}
}
}
}
๐ค Usage with Different AI Clients
Claude Desktop
- Best for: General use, easiest setup
- Supports: Claude models only
- Config location: See Quick Start
Cline (VS Code Extension)
- Best for: Coding workflows, integrated development
- Supports: Claude, OpenAI, Ollama, and more
- Config location: VS Code Settings โ Cline โ MCP Servers
Open WebUI
- Best for: Web-based interface with Ollama
- Supports: Ollama models
- Setup: Configure in Open WebUI settings under MCP/Tools section
Custom Integration
You can integrate this server with any MCP-compatible client. The server communicates via stdio using the MCP protocol.
๐ ๏ธ Available Tools
The server exposes these tools to AI clients:
list_files
List files and directories in the workspace.
Parameters:
path(optional): Relative path to listrecursive(optional): Include nested directories
Example:
"List all TypeScript files in the src directory"
read_file
Read the contents of a file.
Parameters:
path(required): Relative path to the file
Example:
"Read the package.json file"
write_file
Create or overwrite a file.
Parameters:
path(required): Relative path for the filecontent(required): File contentcreateDirectories(optional): Create parent directories
Example:
"Create a new file src/utils/helper.ts with a function to format dates"
delete_file
Delete a file or empty directory.
Parameters:
path(required): Relative path to delete
Example:
"Delete the old-config.json file"
create_folder
Create a directory and its parents.
Parameters:
path(required): Relative path for the directory
Example:
"Create a folder structure: src/components/ui"
apply_patch
Apply a patch to modify an existing file.
Parameters:
path(required): Relative path to the filepatch(required): Patch in custom format
Patch Format:
<<<OLD
old content to replace
===
new content
>>>NEW
Example:
"Change the port from 3000 to 8080 in the config file"
run_command
Execute an allowed command.
Parameters:
command(required): Command name (must be in allowed list)args(optional): Command argumentscwd(optional): Working directorytimeoutMs(optional): Timeout override
Example:
"Run npm install"
"Run the tests with npm test"
๐ Security
Sandboxing
All file operations are strictly sandboxed to the MCP_WORKSPACE_ROOT directory:
โ Allowed:
read_file("src/index.ts")
write_file("output/data.json", content)
โ Blocked:
read_file("../../../etc/passwd")
read_file("/etc/passwd")
write_file("C:\\Windows\\System32\\file.txt", content)
Protection Mechanisms
- Path Resolution: All paths resolved to absolute paths and validated
- Boundary Checking: Resolved paths must start with workspace root
- Traversal Detection:
../sequences that escape workspace are blocked - Absolute Path Blocking: Absolute paths outside workspace rejected
- Symbolic Link Resolution: Symlinks resolved and validated
- Command Allowlist: Only explicitly allowed commands can execute
- Argument Safety: Command arguments passed as arrays (no shell injection)
Best Practices
- โ Use a dedicated workspace directory for AI operations
- โ Only allow commands you trust
- โ Use read-only mode for code review/analysis
- โ Regularly review what the AI is doing
- โ Keep the workspace separate from system directories
- โ Don't set workspace root to
/orC:\ - โ Don't allow dangerous commands like
rm,del,format
๐งช Testing
The project includes comprehensive test coverage:
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run with coverage
npm run test:coverage
Test Structure
- Unit Tests: Test individual functions and modules (26 tests)
- Property-Based Tests: Use fast-check to verify properties across random inputs (83 tests)
- Integration Tests: Test full MCP protocol communication
All 109 tests validate the correctness properties defined in the design specification.
๐ Troubleshooting
Server Won't Start
Problem: Claude/Cline shows connection errors
Solutions:
- Verify Node.js is installed:
node --version(should be 18+) - Check the server path in config is correct and absolute
- Ensure the project is built:
npm run build - Check that
dist/index.jsexists
Security Errors
Problem: "Path outside workspace" errors
Solutions:
- Ensure
MCP_WORKSPACE_ROOTis an absolute path - Use relative paths in requests (no leading
/) - Avoid
../to navigate outside workspace - Check for symbolic links pointing outside workspace
Command Not Allowed
Problem: "Command not allowed" errors
Solutions:
- Add command to
MCP_ALLOWED_COMMANDS:"npm,git,python" - Use only the command name, not full path
- Ensure commands are comma-separated without spaces
Command Timeout
Problem: Commands killed before completing
Solutions:
- Increase
MCP_COMMAND_TIMEOUT(value in milliseconds) - For long builds:
"MCP_COMMAND_TIMEOUT": "1800000"(30 min) - Check if command is actually hanging
File Not Found
Problem: AI can't find files that exist
Solutions:
- Verify
MCP_WORKSPACE_ROOTpoints to correct directory - Use relative paths from workspace root
- Check file actually exists:
lsordirin workspace
JSON Parse Error (Claude Desktop)
Problem: "Could not load app settings" or "invalid JSON"
Solutions:
- Validate JSON syntax at jsonlint.com
- Ensure all paths use double backslashes on Windows:
C:\\Users\\... - Check for trailing commas (not allowed in JSON)
- Verify file encoding is UTF-8 without BOM
๐ Environment Variables Reference
| Variable | Type | Default | Description |
|---|---|---|---|
MCP_WORKSPACE_ROOT |
string | process.cwd() |
REQUIRED: Absolute path to workspace directory |
MCP_ALLOWED_COMMANDS |
string | "" |
Comma-separated list of allowed commands |
MCP_READ_ONLY |
boolean | false |
Disable all write operations |
MCP_LOG_LEVEL |
string | "info" |
Logging level: debug, info, warn, error |
MCP_COMMAND_TIMEOUT |
number | 300000 |
Command timeout in milliseconds (5 min default) |
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Development Setup
- Fork the repository
- Clone your fork
- Install dependencies:
npm install - Make your changes
- Run tests:
npm test - Build:
npm run build - Submit a PR
Guidelines
- Ensure all tests pass
- Add tests for new features
- Follow TypeScript strict mode
- Update documentation as needed
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Built following the Model Context Protocol specification
- Tested with fast-check for property-based testing
- Inspired by the need for secure AI-filesystem interaction
๐ Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
โญ If you find this project useful, please consider giving it a star on GitHub!
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.