Instructions for AI agents working on this codebase.
This is a Go implementation of a Model Context Protocol (MCP) server providing secure filesystem operations. The server restricts access to explicitly allowed directories and implements security measures against symlink attacks, path traversal, and other filesystem vulnerabilities.
cmd/filesystem/ # Main entry point
internal/
pathutil/ # Path validation and security utilities
registry/ # Tool registry for MCP tools
security/ # Security validation logic
server/ # MCP server implementation
stream/ # Streaming utilities for large files
tools/ # Individual filesystem tool implementations
pkg/filesystem/ # Public filesystem package
| Command | Purpose |
|---|---|
make build |
Build the binary |
make test |
Run all tests |
make test-v |
Run tests with verbose output |
make test-cover |
Run tests with coverage report |
make lint |
Run all linting checks (fmt-check + vet) |
make fmt |
Format code with gofmt |
make vet |
Run go vet |
make clean |
Clean build artifacts |
make ci |
Run all CI checks (lint + test) |
- Follow standard Go idioms and conventions
- All paths must be validated against allowed directories before use
- Use the
pathutilpackage for path validation and security checks - File writes should be atomic (temp file + rename pattern)
- Symlinks must be resolved and validated before operations
- Tools are registered in the
registrypackage with proper MCP annotations
When modifying filesystem operations:
- Always validate paths using
pathutil.ValidatePath()or equivalent - Resolve symlinks before checking if path is within allowed directories
- Reject paths containing null bytes
- Prevent parent traversal (
..) from escaping allowed directories - Never delete allowed root directories
- Use atomic writes to prevent file corruption
- Run
make testafter any code changes - Run
make lintbefore committing - Add tests for new tools in corresponding
_test.gofiles