|
|
MCP File System Server with ADK
Author: Venkata Sudhakar
ADK agents that need to read reports, write summaries, or search through documents benefit from a dedicated file system MCP server. Rather than giving the agent direct file system access, the MCP server acts as a controlled gateway - it sandboxes all operations to a specific directory, validates paths, and exposes only the operations the agent actually needs. This separation makes the system auditable and prevents path traversal attacks.
The file system MCP server exposes tools for listing files, reading content, writing new files, and searching file contents by keyword. All paths are validated against a base directory before any operation executes. The ADK agent uses these tools to work with documents as naturally as if it had direct file access, but all I/O flows through the controlled MCP interface.
The below example shows a ShopMax India MCP server managing a reports directory, with an ADK agent that reads and summarises monthly sales reports.
Now connect an ADK agent to work with the file system via MCP,
It gives the following output,
I found 2 reports: march_2026_sales.txt and april_2026_sales.txt.
Combined Summary:
- March 2026: Revenue Rs 18,42,000 | Top: Laptop | Best City: Mumbai
- April 2026: Revenue Rs 21,15,000 | Top: TV | Best City: Delhi
- Growth: +14.8% month-on-month
- Returns improved from 0.8% to 0.4%
Summary saved to summary.txt.
The sandbox validation in safe_path() is critical - always resolve the full path and check it starts with BASE_DIR before any file operation. In production, run the MCP file server with a dedicated OS user that has read/write access only to the reports directory. For large document collections, add a vector search tool alongside the keyword search to let the agent find semantically similar content across hundreds of files. Use write_file for agent-generated summaries, audit reports, and automated responses that feed back into downstream workflows.
|
|