filesystem-gitignore
A professional MCP server that provides filesystem operations while automatically respecting .gitignore patterns, enabling efficient and token-friendly file access for Claude.
README
ποΈ MCP Filesystem Server
Un servidor MCP (Model Context Protocol) profesional que proporciona operaciones de sistema de archivos mientras respeta automΓ‘ticamente los patrones de .gitignore.
π― ΒΏQuΓ© problema resuelve?
Cuando Claude trabaja con proyectos que tienen venv/, node_modules/, o .git/, intentar leer todo el directorio puede:
- β οΈ Agotar el lΓmite de tokens leyendo 50k+ archivos innecesarios
- β±οΈ Ser extremadamente lento al procesar directorios gigantes
- π€― Ser confuso mezclando cΓ³digo fuente con dependencias
Este servidor resuelve eso respetando .gitignore automΓ‘ticamente, igual que Git. Claude solo ve lo que realmente importa: tu cΓ³digo.
β¨ CaracterΓsticas
- β
Respeta
.gitignoreautomΓ‘ticamente: Excluyevenv/,node_modules/,__pycache__/, etc. - β Optimizado para tokens: Solo lee archivos relevantes de tu proyecto
- β Operaciones completas: Leer, escribir, listar, buscar, y crear archivos/directorios
- β Seguridad por diseΓ±o: Solo accede a directorios explΓcitamente permitidos
- β
Caracteres especiales: Maneja espacios,
#,@, y otros caracteres en nombres - β
Cache inteligente: Cachea patrones
.gitignorecon invalidaciΓ³n automΓ‘tica - β Type-safe: Completamente tipado con dataclasses y type hints
- β Production-ready: Tests, logging, manejo de errores robusto
ποΈ Arquitectura
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β MCP Protocol Layer β
β (server.py - Adaptador que traduce MCP β FileSystemService)β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββ
β Business Logic Layer β
β(filesystem_service.py - Orquesta validaciΓ³n + operaciones) β
ββββββββ¬βββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββ
β β
βΌ βΌ
ββββββββββββββββββββ ββββββββββββββββββββββββ
β Path Validation β β .gitignore Manager β
β (path_validator) β β (ignore_manager) β
β β β β
β - URL decoding β β - Pattern matching β
β - Security check β β - Intelligent cache β
ββββββββββββββββββββ ββββββββββββββββββββββββ
β β
ββββββββββββββββ¬ββββββββββββββββ
β
ββββββββββββββββΌβββββββββββββββββββ
β Data Access Layer β
β (filesystem_operations.py) β
β β
β - Pure I/O operations β
β - No business logic β
βββββββββββββββββββββββββββββββββββ
Responsabilidades por capa:
-
MCP Protocol Layer (
server.py):- Traduce requests MCP a llamadas del service
- Serializa responses a JSON
- Maneja el protocolo stdio
-
Business Logic Layer (
filesystem_service.py):- Orquesta validaciΓ³n + filtering + operaciones
- Punto de entrada pΓΊblico del sistema
- Combina mΓΊltiples componentes para cada operaciΓ³n
-
Support Components:
path_validator: Normaliza y valida paths (seguridad)ignore_manager: Cache y matching de.gitignorefilesystem_operations: I/O puro, sin lΓ³gica de negocio
-
Foundation:
config.py: ConfiguraciΓ³n centralizadaerrors.py: Excepciones tipadasmodels.py: Dataclasses para type safety
Beneficios de esta arquitectura:
- β Cada capa es testeable independientemente
- β FΓ‘cil cambiar implementaciΓ³n de una capa sin afectar otras
- β SeparaciΓ³n clara de responsabilidades
- β CΓ³digo reutilizable (el service puede usarse fuera de MCP)
π Requisitos
- Python 3.10+
- Compatible con clientes MCP como Claude Desktop, Zed, Sourcegraph Cody y otros que implementen el estΓ‘ndar Model Context Protocol.
π InstalaciΓ³n RΓ‘pida
# 1. Clonar y navegar al proyecto
cd "C:\DesarrolloPython\MCP FileSystem"
# 2. Instalar dependencias de desarrollo
make.bat install-dev
# 3. Ejecutar tests para verificar
make.bat test
Configurar Claude Desktop
Edita el archivo de configuraciΓ³n:
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"filesystem-gitignore": {
"command": "python",
"args": [
"-m",
"mcp_filesystem"
],
"env": {
"ALLOWED_DIRECTORIES": "C:\\DesarrolloPython;C:\\MisProyectos"
}
}
}
}
Notas:
- Usa paths absolutos
- Windows: separa directorios con
; - Unix/Mac: separa directorios con
:
Reinicia Claude Desktop para aplicar cambios.
π§ Uso
Herramientas Disponibles
1. read_file - Leer archivo de texto
read_file(path="C:\\DesarrolloPython\\proyecto\\src\\main.py")
2. write_file - Escribir archivo
write_file(
path="C:\\DesarrolloPython\\nuevo_archivo.py",
content="print('Hello, World!')"
)
3. list_directory - Listar contenido (no recursivo)
# Por defecto respeta .gitignore
list_directory(path="C:\\DesarrolloPython\\proyecto")
# Forzar mostrar TODO (incluso venv)
list_directory(path="C:\\DesarrolloPython\\proyecto", respect_gitignore=False)
4. directory_tree - Γrbol recursivo
directory_tree(
path="C:\\DesarrolloPython\\proyecto",
max_depth=5,
respect_gitignore=True # Default
)
5. search_files - Buscar archivos
search_files(
path="C:\\DesarrolloPython",
pattern="config", # Case-insensitive
respect_gitignore=True
)
6. get_file_info - InformaciΓ³n detallada
get_file_info(path="C:\\DesarrolloPython\\proyecto\\README.md")
7. create_directory - Crear directorio
create_directory(path="C:\\DesarrolloPython\\nuevo_proyecto\\src")
π Decisiones de DiseΓ±o
ΒΏCΓ³mo se maneja .gitignore?
- Parseo con pathspec: Usamos la librerΓa
pathspecque implementa el mismo algoritmo que Git - Cache inteligente:
- Cada
.gitignorese parsea una sola vez y se cachea - El cache se invalida automΓ‘ticamente cuando el
.gitignorecambia (detecta pormtime) - Cache por directorio (cada dir tiene su propio
.gitignore)
- Cada
- Matching preciso:
- Convierte paths a formato POSIX (forward slashes)
- Agrega
/al final de directorios (convenciΓ³n de Git) - Usa
gitwildmatchpara matching exacto
ΒΏCΓ³mo se optimiza el consumo de tokens?
- Filtrado temprano: Los archivos ignorados ni siquiera se listan
- Control de profundidad:
directory_treelimita profundidad mΓ‘xima (default: 5) - Sin lectura de contenido: Solo lista nombres, no lee contenidos
- Respeto opcional: Todas las herramientas tienen
respect_gitignoreflag (default:True)
ComparaciΓ³n:
# β Sin .gitignore (50k+ archivos en venv):
directory_tree("C:\\proyecto") # π₯ Consume 100k+ tokens
# β
Con .gitignore (solo archivos de proyecto):
directory_tree("C:\\proyecto") # β
~2k tokens
Seguridad: ΒΏPor quΓ© directorios permitidos?
- Previene acceso a archivos sensibles del sistema
- Claude solo puede trabajar en tus proyectos
- ValidaciΓ³n en cada operaciΓ³n (no se puede "escapar" con
../../../)
π§ͺ Testing
# Ejecutar todos los tests
make.bat test
# Solo tests unitarios
make.bat test-unit
# Solo tests de integraciΓ³n
make.bat test-integration
# Con reporte de coverage
make.bat test-cov
π οΈ Desarrollo
# Formatear cΓ³digo
make.bat format
# Linters
make.bat lint
# Limpiar archivos generados
make.bat clean
π Troubleshooting
"ALLOWED_DIRECTORIES environment variable must be set"
SoluciΓ³n: Configura la variable de entorno en Claude Desktop config.
"Access denied"
Causa: El path no estΓ‘ en ALLOWED_DIRECTORIES
SoluciΓ³n: Agrega el directorio a la lista.
No respeta .gitignore
Verifica:
- ΒΏExiste
.gitignoreen el directorio? - ΒΏLos patrones estΓ‘n bien escritos?
- ΒΏEstΓ‘s usando
respect_gitignore=True? (es el default)
Consume muchos tokens
SoluciΓ³n:
- Crea/mejora tu
.gitignore - Reduce
max_depthendirectory_tree
# .gitignore recomendado para Python:
venv/
env/
__pycache__/
*.pyc
.git/
.pytest_cache/
.mypy_cache/
htmlcov/
π Referencias
π€ Contribuciones
Β‘Las contribuciones son bienvenidas!
Antes de hacer PR:
- β
Ejecuta
make.bat test(todos los tests deben pasar) - β
Ejecuta
make.bat lint(sin warnings) - β
Ejecuta
make.bat format(cΓ³digo formateado) - β Agrega tests para nueva funcionalidad
π Licencia
MIT License - Γsalo libremente.
Desarrollado con β€οΈ para optimizar la interacciΓ³n de Claude con proyectos reales
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.