Java Filesystem Web
STDIOMCP server providing filesystem operations and web access tools for LLM agents.
MCP server providing filesystem operations and web access tools for LLM agents.
This project implements a Model Context Protocol (MCP) server that provides filesystem operations and web access tools for Large Language Model (LLM) agents. It enables AI assistants to interact with both the local filesystem and web resources through a set of well-defined operations.
The server provides the following operations:
These operations are exposed as tools for Large Language Models using the Model Context Protocol (MCP), allowing AI systems to safely interact with the filesystem and access web resources.
Build the project using Maven:
mvn clean package
Run the server using the following command:
java -jar target/devoxx-filesystem-0.0.1-SNAPSHOT.jar
The server uses STDIO for communication, so it doesn't expose any HTTP endpoints. It's designed to be launched by an MCP client.
readFile(String fullPathFile)
Reads the complete contents of a file from the file system. Handles various text encodings and provides detailed error messages if the file cannot be read.
writeFile(String path, String content)
Creates a new file or completely overwrites an existing file with new content. Creates parent directories if they don't exist.
editFile(String path, String edits, Boolean dryRun)
Makes line-based edits to a text file. Each edit replaces exact line sequences with new content. Returns a git-style diff showing the changes made. The dryRun
parameter allows viewing changes without applying them.
searchFiles(String path, String pattern)
Recursively searches for files and directories matching a pattern. Searches through all subdirectories from the starting path. The search is case-insensitive and matches partial names.
listDirectory(String path)
Gets a detailed listing of all files and directories in a specified path. Results clearly distinguish between files and directories with additional metadata.
grepFiles(String directory, String pattern, String fileExtension, Boolean useRegex, Integer contextLines, Integer maxResults, Boolean ignoreCase)
Searches for text patterns within files. Returns matching files with line numbers and context. Similar to the Unix 'grep' command but with additional features for context display. Supports regex patterns, case-insensitive search, and context lines before/after matches.
createDirectory(List<String> directories)
Creates new directories or ensures that directories exist. Can create multiple directories in one operation. If a directory already exists, the operation succeeds silently. Perfect for setting up directory structures for projects or ensuring required paths exist.
executeBash(String command, String workingDirectory, Integer timeoutSeconds)
Execute a Bash command in the system shell and return the output. This tool allows running system commands and capturing their standard output and error streams. Use with caution as some commands may have system-wide effects.
fetchWebpage(String url, Integer timeoutMs)
Fetches or reads a webpage from a URL and returns its content. The service uses jsoup to connect to the webpage and retrieve its content. The optional timeoutMs
parameter allows setting a custom connection timeout.
A comprehensive set of unit tests is provided for all service classes. Run them using:
mvn test
The tests use JUnit 5 and Mockito for mocking external dependencies like the jsoup library for web requests.
A test client is provided in ClientStdio.java
which demonstrates how to invoke the tools using the MCP protocol.
The application is configured via application.properties
:
spring.main.web-application-type=none spring.main.banner-mode=off logging.pattern.console= spring.ai.mcp.server.name=filesystem-server spring.ai.mcp.server.version=0.0.1 logging.file.name=,/JavaFileSystemMCP/target/filesystem-server.log
JavaFileSystemMCP/
src/
main/
java/
com/
devoxx/
mcp/
filesystem/
tools/
EditFileService.java
ReadFileService.java
WriteFileService.java
SearchFilesService.java
FetchWebpageService.java
ListDirectoryService.java
CreateDirectoryService.java
GrepFilesService.java
BashService.java
McpServerApplication.java
resources/
application.properties
test/
java/
com/
devoxx/
mcp/
filesystem/
tools/
ReadFileServiceTest.java
WriteFileServiceTest.java
EditFileServiceTest.java
SearchFilesServiceTest.java
FetchWebpageServiceTest.java
ListDirectoryServiceTest.java
CreateDirectoryServiceTest.java
GrepFilesServiceTest.java
ClientStdio.java
pom.xml
README.md
The project uses:
EditFileService
includes sophisticated diff generation for tracking changesSearchFilesService
supports glob patterns for flexible file matchingFetchWebpageService
includes configurable timeouts and robust error handling for web requestsThis server can be easily integrated with DevoxxGenie using the MCP (Model Context Protocol) support. Here's how to set it up:
Name: JavaFilesystem
(or any descriptive name)
Transport Type: STDIO
Command: Full path to your Java executable (e.g., /Library/Java/JavaVirtualMachines/liberica-jdk-23.jdk/Contents/Home/bin/java
)
Arguments:
-Dspring.ai.mcp.server.stdio=true
-Dspring.main.web-application-type=none
-Dlogging.pattern.console=
-jar
~/JavaFileSystemMCP/target/devoxx-filesystem-0.0.1-SNAPSHOT.jar
Enter each argument on a new line. You may need to change the path for -jar to point to where you've built the jar.
Once configured, DevoxxGenie will automatically discover the tools provided by this MCP server. The AI assistant can then use these tools to:
All operations will be performed with the permissions of the user running the DevoxxGenie application.
Edit your claude_desktop_config.json file with the following:
{ "mcpServers": { "filesystem": { "command": "/Library/Java/JavaVirtualMachines/liberica-jdk-23.jdk/Contents/Home/bin/java", "args": [ "-Dspring.ai.mcp.server.stdio=true", "-Dspring.main.web-application-type=none", "-Dlogging.pattern.console=", "-jar", "~/JavaFileSystemMCP/target/devoxx-filesystem-0.0.1-SNAPSHOT.jar" ] } } }
You may need to change the path for -jar to point to where you've built the jar.
When using this server, be aware that: