# Подключение Windsurf / Continue MCP

Настройка Codeium Windsurf и Continue.dev для вызова tools 1C MCP Gateway.

## Prerequisites

- Windsurf IDE или VS Code + расширение Continue.
- Node.js 22+, gateway repo `/var/www/mwi.yatsuk.pro`.
- MCP support в вашей версии клиента (Continue 0.9+ / Windsurf latest).
- Созданный профиль 1С ([QUICK_START.md](./QUICK_START.md)).

## Пошаговая настройка — Windsurf

### 1. MCP config

Windsurf: Settings → MCP → Edit Config (`~/.codeium/windsurf/mcp_config.json` или аналог):

```json
{
  "mcpServers": {
    "1c-mcp-gateway": {
      "command": "npm",
      "args": ["run", "dev:gateway"],
      "cwd": "/var/www/mwi.yatsuk.pro",
      "env": {
        "ONEC_MCP_DATA_DIR": "/var/www/mwi.yatsuk.pro/.data",
        "ONEC_MCP_ACTOR": "local-ai-agent"
      }
    }
  }
}
```

### 2. HTTP mode (Cascade + remote gateway)

```json
{
  "mcpServers": {
    "1c-mcp-gateway": {
      "serverUrl": "http://127.0.0.1:3000/mcp",
      "headers": {
        "Authorization": "Bearer <issued-http-mcp-token>",
        "X-MCP-Client-ID": "windsurf"
      }
    }
  }
}
```

Backend: `ONEC_MCP_HTTP_TOKEN="..." npm run dev:http`

## Пошаговая настройка — Continue

### 1. `~/.continue/config.yaml`

```yaml
mcpServers:
  - name: 1c-mcp-gateway
    command: npm
    args:
      - run
      - dev:gateway
    cwd: /var/www/mwi.yatsuk.pro
    env:
      ONEC_MCP_DATA_DIR: /var/www/mwi.yatsuk.pro/.data
      ONEC_MCP_ACTOR: local-ai-agent
```

### 2. HTTP (Continue remote)

```yaml
mcpServers:
  - name: 1c-mcp-gateway-http
    url: http://127.0.0.1:3000/mcp
    transport: streamable-http
    headers:
      Authorization: Bearer <issued-http-mcp-token>
      X-MCP-Client-ID: continue
```

### 3. Правила агента (optional)

В `.continuerules` или project rules:

```
Перед анализом 1С всегда вызывай list_profiles и get_active_profile.
При смене базы — switch_active_profile. Не выдумывай имена объектов метаданных.
```

## Copy-ready config

```bash
cd /var/www/mwi.yatsuk.pro
npm ci && npm run build
npm run dev:gateway   # stdio
# или
npm run dev:http      # HTTP + Web Console :3000
```

Token для HTTP:

```bash
curl -s -X POST http://localhost:3000/api/mcp-tokens \
  -H "Content-Type: application/json" \
  -d '{"title":"windsurf","scopes":["mcp:call"],"allowedClients":["windsurf"]}'
```

## Проверка tools/list

- **Windsurf**: MCP panel → connected → expand tools.
- **Continue**: Chat → hammer icon / MCP tools list.

Тест: попросите модель вызвать `list_profiles` — ответ должен быть structured JSON.

## Первый тестовый prompt

```
Используй MCP 1c-mcp-gateway: switch_active_profile на dev-edt-main,
form_get_context для формы справочника Контрагенты (если есть в метаданных),
перечисли команды формы и связанные обработчики в модуле формы.
```

## Типовые ошибки

| Симптом | Решение |
|---------|---------|
| YAML parse error | Отступы в `config.yaml`, кавычки в paths |
| Windsurf не видит npm | Full path: `"command": "/usr/bin/npm"` |
| Continue stale tools | Reload Window, restart Continue |
| HTTP CORS | MCP client native — CORS не нужен; проверьте bind host |
| Rate limit 429 | Увеличьте `rateLimit` на token или снизьте частоту calls |

## Security warning

- Continue может отправлять контекст файлов + tool results в cloud LLM — проверьте data policy org.
- Локальные модели (см. [LOCAL_MODELS_MCP.md](./LOCAL_MODELS_MCP.md)) снижают утечку кода.
- Не commit `mcp_config` с embedded tokens — используйте env substitution где поддерживается.

## Related docs

- [LOCAL_MODELS_MCP.md](./LOCAL_MODELS_MCP.md) — offline LLM
- [VSCODE_COPILOT_MCP.md](./VSCODE_COPILOT_MCP.md) — VS Code variant
- [MCP_CONNECTION.md](./MCP_CONNECTION.md) — agent workflow
- [CLAUDE_MCP_SETUP.md](./CLAUDE_MCP_SETUP.md)
