# MCP gateway

Godelgate exposes a single MCP endpoint at `/mcp` using the Streamable HTTP transport. To clients it looks like one MCP server whose tools are the combined tools of every connected server.

## Authentication

Every request must carry a user key:

```http
Authorization: Bearer <user key>
```

Requests without a valid key get `401`. Keys and groups are defined in [Users and keys](/docs/users-and-keys).

## Sessions

1. A client starts a session by sending an MCP `initialize` request without a session ID.
2. Godelgate creates the session for that user and returns its ID in the `Mcp-Session-Id` header.
3. Later requests send that header. A session can only be used with the key that opened it; another key gets `404`.
4. Sessions close when the client ends them, or after one hour without activity.

Each session has its own [trifecta](/docs/trifecta) markers, so what one conversation read never affects another.

## What happens on a tool call

1. Look up the tool by its namespaced name.
2. Decide using the [decision order](/docs/policy#decision-order): deny rule, quarantine, trifecta, matching rule, default.
3. Record the call in the [audit log](/docs/audit-log) with the decision and reason.
4. If the decision is `approve`, wait for a [human decision](/docs/approvals).
5. Forward allowed calls to the upstream server, with a 60-second timeout.
6. Update the session's trifecta markers from the tool's labels.
7. Record the result and return it unchanged to the client.

Denied calls never reach the upstream server. They return an MCP error result:

```json
{
  "isError": true,
  "content": [{ "type": "text", "text": "Blocked by Godelgate: <reason>" }]
}
```

## Limits

| Limit | Value |
| --- | --- |
| Request body | 4 MB |
| Upstream call timeout | 60 seconds |
| Idle session lifetime | 1 hour |
| Approval wait | `policy.approvalTimeoutSeconds`, default 300 |
