# Servidor MCP

O `herald-mcp` deixa bots de chat e agentes usarem o Herald. Ele funciona com OpenBot, OpenClaw,
Hermes, Claude Desktop, Claude Code e n8n; cada um tem uma receita em
[`docs/integrations/README.md`](integrations/README.md).

## Ferramentas para bots

| Ferramenta | O que faz |
|---|---|
| `herald_briefing(date?, language?, category?)` | O briefing mais recente ou o de um dia; inteiro ou só uma categoria |
| `herald_history_search(query, days?)` | Busca notícias já publicadas, em qualquer idioma de saída; cada resultado tem `texts`: `{language: {headline, summary}}` |
| `herald_categories()` | Todas as categorias e se você segue cada uma |
| `herald_follow(categories)` / `herald_unfollow(categories)` | Muda o que você segue (ids ou grupos como `br`, `sports`) |

## Ferramentas para agentes

Ferramentas para agentes que conduzem uma execução etapa por etapa: `herald_fetch`,
`herald_prefilter`, `herald_cluster`, `herald_score`, `herald_select`, `herald_enrich`,
`herald_render`, `herald_run`, `herald_get_run` e `herald_list_runs`.

## Transportes

Há dois transportes:
- stdio (padrão), para um bot na mesma máquina: o próprio bot inicia o `herald-mcp`;
- HTTP, para um bot em outro lugar: `herald-mcp --http [--host 127.0.0.1] [--port 8765]` serve
  `http://HOST:PORT/mcp`. Ele se recusa a iniciar sem `HERALD_MCP_TOKEN` (16 caracteres ou mais,
  no `.env`), e toda requisição precisa enviar `Authorization: Bearer <token>`. Se o bot estiver em
  outra máquina, mantenha o servidor em `127.0.0.1`, atrás de um proxy reverso com TLS.

## Receitas

**OpenClaw:**

```bash
# same machine (stdio)
openclaw mcp set herald '{"command":"/path/to/herald/.venv/bin/herald-mcp",
  "env":{"HERALD_CONFIG":"/path/to/herald/config.json"}}'
# remote (HTTP); HERALD_MCP_TOKEN must be set in OpenClaw's environment
openclaw mcp set herald '{"url":"https://herald.example.com/mcp","transport":"streamable-http",
  "headers":{"Authorization":"Bearer ${HERALD_MCP_TOKEN}"}}'
openclaw mcp doctor herald --probe
```

**Hermes** (`~/.hermes/config.yaml`, depois `/reload mcp`):

```yaml
mcp_servers:
  herald:
    command: "/path/to/herald/.venv/bin/herald-mcp"
    env:
      HERALD_CONFIG: "/path/to/herald/config.json"
  # or remote:
  # herald:
  #   url: "https://herald.example.com/mcp"
  #   headers:
  #     Authorization: "Bearer ${HERALD_MCP_TOKEN}"   # token in ~/.hermes/.env
```

**Claude Desktop / Claude Code:**

```json
{ "mcpServers": { "herald": { "command": "/path/to/herald/.venv/bin/herald-mcp",
  "env": { "HERALD_CONFIG": "/path/to/herald/config.json" } } } }
```

## Entrega por um bot

Para entregar o briefing por um bot num horário fixo, agende no bot um job que chame
`herald_briefing` e envie o resultado para o canal dele. A execução do próprio Herald precisa
terminar antes desse horário.
