# elGIT MCP

Удалённый MCP-сервер для Cursor и других клиентов: поиск по репозиториям, чтение файлов и документации инстанса.

## Адрес

- Публичный host: `https://mcp.elgit.ru`
- Endpoint: `https://mcp.elgit.ru/mcp`
- Статус: включён

## Токен

1. elGIT → Профиль → Безопасность → API tokens  
2. Создайте токен с областью **mcp** (или **api**)  
3. Не коммитьте токен в git

## Cursor (`~/.cursor/mcp.json` или Settings → MCP)

```json
{
  "mcpServers": {
    "elgit": {
      "url": "https://mcp.elgit.ru/mcp",
      "headers": {
        "Authorization": "Bearer elgit_ВАШ_ТОКЕН"
      }
    }
  }
}
```

Лучше через переменную окружения:

```json
{
  "mcpServers": {
    "elgit": {
      "url": "https://mcp.elgit.ru/mcp",
      "headers": {
        "Authorization": "Bearer ${env:ELGIT_MCP_TOKEN}"
      }
    }
  }
}
```

## Локальный stdio (без HTTP)

На машине с доступом к серверу:

```bash
ELGIT_URL=https://elgit.ru \
ELGIT_TOKEN=elgit_… \
bun run /path/to/elGIT.server/src/mcp/stdio.ts
```

(stdio-режим сейчас обслуживает тот же протокол tools через локальный процесс — см. `src/mcp/stdio.ts`.)

## Tools

- `search` — USE FIRST for questions about the elGIT instance. Ranked search over projects/repos (name, slug, description, package.json, README index). Returns score, match, repoCount, topRepos, tips. Multi-word = OR. Commits OFF by default.
- `list_projects` — List projects (id, slug, name, description, repoCount).
- `list_repos` — List repos visible to token user. Optional projectId filter.
- `list_undocumented` — Projects/repos with empty description — fill these to improve search.
- `get_repo` — Repo metadata: description, default branch, package version.
- `list_tree` — List files/folders (ls-tree).
- `get_file` — Read text file. Secret paths (.env, keys) are blocked. Large files truncated.
- `grep` — git grep in a repository (source code). Prefer after search/get_repo. Secret paths filtered.
- `list_commits` — Recent commits on a ref (default branch).
- `diff` — Diff between two refs (base...head). Use nameOnly for file list. Truncated.
- `list_issues` — List issues in a repo (open/closed/all).
- `get_issue` — Get one issue by number (title, body, status).
- `create_issue` — Create issue (requires Admin MCP allowWrite + developer role).
- `list_mrs` — List merge requests in a repo.
- `get_mr` — Get MR by number + comments.
- `create_mr_comment` — Comment on MR (requires allowWrite + developer role).
- `list_actions` — List Action runs (pipeline status) for a repo.
- `get_action` — Get Action run details + truncated log.
- `get_rules` — Instance agent rules (Admin → MCP → Правила).

## Поиск (`search`)

- Короткие ключи: slug проекта, имя продукта, стек (`elwms`, `mcp`, `notifications`).
- Несколько слов = OR по токенам; выше score, если совпали все.
- В ответе: `score`, `match` (где нашли), `repoCount`, `topRepos`, `tips`.
- Коммиты выключены по умолчанию (`includeCommits: true` если нужны).
- Дальше: `list_repos` + `projectId` → `get_file` README.md.

## Resources

- `elgit://rules` — правила агента (настраиваются в этой вкладке)
- `elgit://docs` — эта документация

## Безопасность

- Доступ только с валидным Bearer (PAT/JWT)
- Репозитории фильтруются по ACL пользователя токена
- Секреты и бинарники через MCP не отдаются
- Пишите только read-only tools, пока «запись» выключена в настройках