mcp-file-managerbeta

MCP File Manager

A local MCP client/server pair that gives an LLM safe, tool-mediated access to your filesystem, straight from the terminal.

PythonFastMCPMCP SDKGoogle Gemini API
0
MCP tools exposed
0
retries before graceful fallback
0
LLM-driven prompts
0
dynamic file resource

A terminal-native MCP client and server pair that lets Gemini read, write, and clean up files in any directory — no copy-pasting code into a browser chatbot.

01

Context & problem

Getting an LLM's help on a piece of code usually meant copying it out of my editor and pasting it into a browser tab — losing directory context, and repeating the round trip for every file.

I wanted Gemini to read, summarize, and clean up code directly from the filesystem I was already working in, without leaving the terminal.

And I wanted it built on a protocol another client could reuse, instead of a one-off script wired straight to an API.

02

Solution

01Overview

I built both sides of the exchange: an MCP server that exposes the filesystem, and an MCP client that connects it to Gemini.

02The server (FastMCP)

Exposes three kinds of capability:

  • Five filesystem tools — list_directory, read_file, write_file, delete_file, update_file.
  • A file:// resource for attaching file contents.
  • Two prompts — summarize_file and clean_up_code.

03The client

Spawns the server as a subprocess over stdio and forwards its tool schema to Gemini as function declarations. It then drives the tool-call loop:

  • Gemini requests a tool.
  • The client executes it and feeds the result back.
  • This repeats until Gemini returns a final answer.

04Resilience

This is the part that took real engineering. Gemini calls sometimes fail outright and sometimes hang, so I split failures into two classes:

  • Retryable ServerErrors — exponential backoff, three attempts.
  • Terminal ClientErrors — fail fast.

Both fall back gracefully to the next prompt instead of taking the whole session down.

// how a request flows through mcp-file-manager
user
chat loop
MCP clientGemini function calling
Gemini APIfunction calling
MCP serverJSON-RPC over stdio
toolslist / read / write / delete / update
resourcesfile:// via @
promptssummarize / cleanup via /
zsh
$ python client.py
Connected to server. 5 tools available:
- list_directory
- read_file
- write_file
- delete_file
- update_file
You: /summarize_file server.py
[tool call] read_file({'path': 'server.py'})
[tool result] import os\n\nfrom mcp.server.fastmcp import FastMCP...
Gemini: This file defines an MCP server exposing 5 filesystem tools,
1 file:// resource, and 2 prompts (summarize_file, clean_up_code).
# on a Gemini 503, retries 3x with backoff before falling back gracefully
client.py
# retry Gemini calls, but never crash the chat loop
async def _call_gemini(self, contents):
for attempt in range(1, MAX_ATTEMPTS + 1):
try:
return self.genai_client.models.generate_content(...)
except ServerError as e:
if attempt == MAX_ATTEMPTS:
return None # give up, fall back to the prompt
await asyncio.sleep(2 ** attempt)
except ClientError as e:
return None # not retryable
03

Measurable impact

◆

Classified Gemini API failures into retryable (ServerError, exponential backoff, 3 attempts) versus terminal (ClientError, fail fast) so an overloaded or slow model never crashes the chat session — it falls back to the next prompt instead.

◆

Exposes 5 filesystem tools, 1 dynamic file:// resource, and 2 LLM-driven prompts (summarize_file, clean_up_code) through the standard MCP tool-calling protocol, so any MCP-compatible client can drive it, not just this one.

◆

Replaced copy-pasting code into a browser chatbot with a single @filename mention that attaches the file as a resource directly in the terminal.

$ ./say-hello.sh

Let's talk about your backend.

Open to backend and platform engineering roles, and to interesting infrastructure problems. Fastest reply is by email.

© 2026 Elyas BromandBuilt with ♥ by Elyas Bromand↑ back to top