Java MCP Filesystem Server
A secure Java-based MCP server that provides controlled filesystem access to AI assistants.
Java MCP Filesystem Server
A secure Model Context Protocol (MCP) server implementation in Java that provides controlled filesystem access to AI assistants. This server enables AI models to safely read, write, and manipulate files within specified directories while preventing unauthorized access through path validation.
Features
Security-First Design
- Path Validation: All file operations are restricted to explicitly allowed directories
- Path Traversal Protection: Prevents
../attacks through path normalization and validation - Symbolic Link Resolution: Safely handles symbolic links by checking their real paths
Comprehensive File Operations
The server exposes 11 MCP tools for filesystem manipulation:
read_file: Read the complete contents of a single fileread_multiple_files: Efficiently read multiple files in one operationwrite_file: Create new files or overwrite existing onesedit_file: Make line-based edits with diff preview supportcreate_directory: Create single or nested directory structureslist_directory: List contents of a directory with type indicatorsdirectory_tree: Get a recursive JSON tree view of directoriesmove_file: Move or rename files and directoriessearch_files: Recursively search for files matching patternsget_file_info: Retrieve detailed file metadata (size, timestamps, permissions)list_allowed_directories: Show which directories the server can access
MCP Resources Support
In addition to tools, the server also supports MCP resources, allowing clients to access file contents through file:// URIs.
Requirements
- Java 21 or higher
- Gradle 8.x (for building from source)
Installation
Option 1: Download Pre-built JAR
Download the latest release JAR file from the releases page (if available).
Option 2: Build from Source
- Clone the repository:
git clone <repository-url>
cd java-mcp-filesystem-server
- Build the project:
./gradlew clean build
This creates a fat JAR with all dependencies at:
build/libs/filesystem-mcp-server-all.jar
Usage
Running the Server
The server requires at least one allowed directory as a command-line argument:
java -jar build/libs/filesystem-mcp-server-all.jar /path/to/allowed/directory [additional directories...]
Example with multiple directories:
java -jar build/libs/filesystem-mcp-server-all.jar /Users/myuser/documents /Users/myuser/projects
Configuring with Claude Desktop
To use this server with Claude Desktop, add it to your claude_desktop_config.json:
{
"mcpServers": {
"filesystem": {
"command": "java",
"args": [
"-jar",
"/absolute/path/to/filesystem-mcp-server-all.jar",
"/Users/myuser/documents",
"/Users/myuser/projects"
]
}
}
}
Configuring with Other MCP Clients
The server communicates over stdio (standard input/output), making it compatible with any MCP client that supports stdio transport. Provide the command and arguments as shown above.
Development
Project Structure
java-mcp-filesystem-server/
├── src/main/java/com/brunorozendo/mcp/filesystem/
│ ├── FilesystemServer.java # Main server entry point
│ ├── FileTools.java # Business logic for all file operations
│ ├── PathValidator.java # Security component for path validation
│ └── ToolSchemas.java # MCP tool schema definitions
├── build.gradle # Gradle build configuration
└── README.md # This file
Building for Development
# Run tests (if any)
./gradlew test
# Build without running tests
./gradlew build -x test
# Create distribution archives
./gradlew distZip distTar
Key Dependencies
io.modelcontextprotocol.sdk:mcp:0.10.0- MCP SDK for Javaio.github.java-diff-utils:java-diff-utils:4.12- For generating diffs in edit operationscom.fasterxml.jackson.core:jackson-databind:2.15.2- JSON processing
Security Considerations
- Directory Access: Only directories explicitly passed as arguments can be accessed
- Path Validation: Every path is validated before any operation
- No Elevation: The server runs with the same permissions as the user who starts it
- Symbolic Links: Resolved to their real paths to prevent escaping allowed directories
Tool Examples
Reading a File
{
"tool": "read_file",
"parameters": {
"path": "/Users/myuser/documents/example.txt"
}
}
Editing a File with Preview
{
"tool": "edit_file",
"parameters": {
"path": "/Users/myuser/documents/example.txt",
"edits": [
{
"oldText": "Hello World",
"newText": "Hello MCP"
}
],
"dryRun": true
}
}
Searching for Files
{
"tool": "search_files",
"parameters": {
"path": "/Users/myuser/projects",
"pattern": ".java",
"excludePatterns": ["build", "target"]
}
}
Troubleshooting
Common Issues
- "Access denied" errors: Ensure the path is within an allowed directory
- "Path is outside of allowed directories": Check that you've included the parent directory in the server arguments
- Server won't start: Verify Java 21+ is installed and in your PATH
Debugging
Enable verbose logging by modifying the server to include debug output, or check stderr for error messages.
Version History
- 0.7.2 - Current version with dependency fixes and full MCP tools support
- Previous versions available in git history
Contributing
Contributions are welcome! Please ensure:
- Code follows Java naming conventions
- Security validations are maintained
- New tools include proper schema definitions
- Changes are tested with an MCP client
License
[Specify your license here]
Author
Bruno Rozendo
Acknowledgments
- Built with the Model Context Protocol SDK for Java
- Inspired by the TypeScript reference implementation
Related Servers
SharePoint MCP Server
Browse and interact with Microsoft SharePoint sites and documents.
Excel MCP Server
An MCP server for manipulating and managing Excel files.
Sharepoint
Provides access to organizational SharePoint sites and files.
YaraFlux
An MCP server for YARA scanning, enabling LLMs to analyze files using YARA rules.
Filesystem MCP Server
A secure server for filesystem operations with controlled access to specified directories.
Vulcan File Ops
MCP server that gives Claude Desktop and other desktop MCP clients filesystem powers—read, write, edit, and manage files like AI coding assistants.
Local Utilities
Provides essential utility tools for text processing, file operations, and system tasks.
File Convert MCP Server
Convert files between various formats, including images, documents, audio, video, and more.
MCP Excel Reader
Read large Excel files with automatic chunking and pagination support.
Everything Search
Fast Windows file search using Everything SDK