Skip to main content
Glama
osamaloup

MCP File & Git Manager Server

by osamaloup
README.md
# MCP File & Git Manager Server

A Model Context Protocol (MCP) server that provides file and git operations for n8n workflows.

## Features

### File Operations
- **read_file**: Read file contents
- **write_file**: Create or update files
- **list_files**: List files and directories (with recursive option)
- **delete_file**: Delete files or directories
- **create_directory**: Create new directories

### Git Operations
- **git_status**: Check repository status
- **git_add**: Stage files for commit
- **git_commit**: Create commits
- **git_push**: Push to remote repository
- **git_pull**: Pull from remote repository
- **git_log**: View commit history
- **git_diff**: Show file differences

### Search
- **search_in_files**: Search for text patterns in files

## Quick Start

### Local Development

```bash
# Install dependencies
npm install

# Build TypeScript
npm run build

# Start server
npm start
```

### Docker

```bash
# Build image
docker build -t mcp-file-git-server .

# Run container
docker run -d \
  --name mcp-file-git-server \
  -p 3001:3001 \
  -e PROJECT_ROOT=/workspace \
  -v /path/to/your/project:/workspace:rw \
  mcp-file-git-server
```

### Docker Compose

Add to your `docker-compose.yml`:

```yaml
services:
  mcp-server:
    build: ./mcp-file-git-server
    container_name: mcp-file-git-server
    environment:
      - PROJECT_ROOT=/workspace
      - PORT=3001
      - NODE_ENV=production
    ports:
      - "3001:3001"
    volumes:
      - /path/to/your/project:/workspace:rw
      - ~/.gitconfig:/root/.gitconfig:ro
      - ~/.ssh:/root/.ssh:ro
    networks:
      - n8n-traefik_default
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "wget", "-q", "--spider", "http://localhost:3001/health"]
      interval: 30s
      timeout: 10s
      retries: 3
```

## Configuration

### Environment Variables

- `PROJECT_ROOT`: Path to project directory (default: `/workspace`)
- `PORT`: Server port (default: `3001`)

### Endpoints

- **Health Check**: `GET http://localhost:3001/health`
- **SSE Endpoint**: `POST http://localhost:3001/sse` (for n8n-nodes-mcp)
- **Message Endpoint**: `POST http://localhost:3001/message`

## n8n Integration

### Create MCP Credential in n8n

1. Go to **Credentials** → **New**
2. Search for **"MCP"**
3. Configure:
   - **Transport**: `SSE` (Server-Sent Events)
   - **URL**: `http://mcp-file-git-server:3001/sse`
4. Save

### Use in Workflow

1. Add **MCP Client** node
2. Select your MCP credential
3. Choose operation (List Tools, Call Tool, etc.)
4. Connect to **AI Agent Tool** via `ai_tool` connection

## Testing

### Test Health Endpoint

```bash
curl http://localhost:3001/health
```

### Test SSE Endpoint

```bash
curl -X POST http://localhost:3001/sse \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}'
```

## Troubleshooting

### Permission Denied

Ensure the mounted project directory has correct permissions:

```bash
sudo chown -R $(id -u):$(id -g) /path/to/your/project
```

### Git Not Working

Initialize git in the project directory:

```bash
docker exec -it mcp-file-git-server sh
cd /workspace
git init
git config user.name "Your Name"
git config user.email "your@email.com"
exit
```

### Connection Issues

Check Docker network connectivity:

```bash
# From n8n container
docker exec -it n8n-traefik-n8n-1 sh
wget -O- http://mcp-file-git-server:3001/health
exit
```

## License

MIT