> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bridger.kr/llms.txt
> Use this file to discover all available pages before exploring further.

# GET /mcp/sse

> Bridger Gateway 실시간 이벤트 스트림 — Server-Sent Events 기반 도구 실행 알림.

`/mcp/sse`는 Gateway에서 발생한 도구 실행 결과를 실시간으로 받는 SSE 엔드포인트입니다.
대시보드 라이브 뷰, 멀티 클라이언트 협업, 외부 옵저버블리티 연동에 사용됩니다.

## Request

```http theme={null}
GET /mcp/sse HTTP/1.1
Accept: text/event-stream
x-api-key: dk_live_...
```

## 이벤트 종류

### `event: ready`

연결 직후 1회 발행. `clientId`(`sse_` 접두사)로 추후 식별 가능합니다.

```text theme={null}
event: ready
data: {"ok":true,"clientId":"sse_3f2a1c9b-..."}
```

### Heartbeat

주기적으로 SSE 주석(`: keepalive`)이 전송되어 NAT/프록시 타임아웃을 방지합니다.

```text theme={null}
: keepalive
```

### `event: message` — `gateway/toolResult`

`tools/call` 실행 결과가 **해당 클라이언트(테넌트)에게만** 전송됩니다. 교차 테넌트 데이터 유출을
막기 위해 전체 브로드캐스트하지 않습니다. 클라이언트를 지정하려면 `tools/call` 시
`_clientId`를 함께 전달합니다.

```text theme={null}
event: message
data: {
  "jsonrpc": "2.0",
  "method": "gateway/toolResult",
  "params": {
    "tool": "getultrashortcast",
    "upstream": {
      "method": "GET",
      "url": "https://apis.data.go.kr/...",
      "status": 200
    }
  }
}
```

### `event: byoapi`

BYOAPI 등록 작업의 진행 상태가 등록을 요청한 클라이언트에게 전송됩니다.

```text theme={null}
event: byoapi
data: {"jobId":"...","status":"registered","job":{ ... }}
```

## cURL

```bash theme={null}
curl -N https://mcp.datari.kr/mcp/sse \
  -H "x-api-key: $DATA_BRIDGE_API_KEY" \
  -H "Accept: text/event-stream"
```

`-N`(--no-buffer) 플래그로 실시간 출력을 받습니다.

## Node.js (EventSource)

```javascript theme={null}
import EventSource from "eventsource";

const es = new EventSource("https://mcp.datari.kr/mcp/sse", {
  headers: { "x-api-key": process.env.DATA_BRIDGE_API_KEY },
});

es.addEventListener("ready", (e) => {
  console.log("connected", JSON.parse(e.data));
});

es.addEventListener("message", (e) => {
  const ev = JSON.parse(e.data);
  if (ev.method === "gateway/toolResult") {
    console.log("tool result", ev.params);
  }
});
```

## 운영 노트

* 이벤트는 연결한 클라이언트(테넌트)에게만 전송되며, 다른 테넌트로 새지 않습니다.
* 5xx 발생 시 클라이언트가 자동 재연결하도록 EventSource 또는 동등 라이브러리 사용 권장.
