# MCP Server

Omnia Exchange provides an MCP (Model Context Protocol) server for AI and LLM agent integration. The server implements the [Model Context Protocol](https://modelcontextprotocol.io/) revision `2026-07-28` over Streamable HTTP, enabling agents to discover and invoke exchange tools programmatically.

The server is stateless: there is no `initialize` handshake, no sessions, and no batching. Every request is a self-describing JSON-RPC message.

### Endpoint

- **Demo/UAT** - `https://api.demo.omniaexchange.com/api/mcp`
- **Production** - `https://api.production.omniaexchange.com/api/mcp`

`POST` — Send a JSON-RPC request

### Protocol Version

The server implements MCP protocol version `2026-07-28` only.

### Requests

Every request is a single JSON-RPC 2.0 object posted to `/api/mcp` with these headers:

- `MCP-Protocol-Version` - required, must be `2026-07-28`
- `Mcp-Method` - required, must equal the JSON-RPC `method` in the body
- `Mcp-Name` - required for `tools/call`, must equal the tool name in `params.name`
- `Accept` - required, must include `application/json` or `text/event-stream`

The body must mirror the protocol version: `params._meta["io.modelcontextprotocol/protocolVersion"]` must be present and equal the `MCP-Protocol-Version` header.

Tool names outside the HTTP header character set use the base64 sentinel form `=?base64??=` in the `Mcp-Name` header. The decoded value must still equal `params.name`.

Example `tools/call` request:

```http
POST /api/mcp
MCP-Protocol-Version: 2026-07-28
Mcp-Method: tools/call
Mcp-Name: market.get_price
Accept: application/json

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "market.get_price",
    "arguments": { "sellingAsset": "ETH", "buyingAsset": "USDC" },
    "_meta": {
      "io.modelcontextprotocol/protocolVersion": "2026-07-28",
      "io.modelcontextprotocol/clientCapabilities": {}
    }
  }
}
```

### Methods

Any MCP-capable agent harness can connect over Streamable HTTP with no setup beyond the endpoint URL. The market tools `market.get_assets` and `market.get_price` are callable with no `Authorization` header, so a connection is useful before any credentials exist. Everything else requires a Bearer token, see Authentication.

- `server/discover` - server metadata: supported protocol versions, capabilities, and usage instructions. Call this first. No authentication required. Cacheable for one hour.
- `tools/list` - tool definitions with names, descriptions, and input schemas. Scoped to the caller: without a token only the two market tools are listed; with a valid token, the market tools plus every tool the token's permissions allow. Cacheable for five minutes.
- `tools/call` - invoke a tool. The market tools require no authentication; all other tools require a Bearer token, see Authentication.

Requests without an `id` are notifications: the server answers `202` with no body and does not dispatch them. Batch requests (JSON arrays) are rejected with `400` and error code `-32600`.

### Authentication

The market tools `market.get_assets` and `market.get_price` require no authentication: any agent harness can call them with no `Authorization` header. Everything else, including account data, order history, trading, and withdrawals, requires a Bearer token.

The server implements [OAuth 2.0 Client Credentials](https://datatracker.ietf.org/doc/html/rfc6749#section-4.4) for authentication, following the MCP authorization specification.

**Discovery endpoints:**

- `GET /.well-known/oauth-protected-resource` - returns the resource metadata (scopes, authorization servers)
- `GET /.well-known/oauth-authorization-server` - returns the authorization server metadata (token endpoint, supported grants)

**Obtaining a token:**

`POST /oauth/token` with form parameters:
- `grant_type` = `client_credentials`
- `client_id` = your API key ID
- `client_secret` = your API key secret

The response includes an `access_token`, `token_type`, `expires_in`, and granted `scope`.

**Usage:** Include the token as `Authorization: Bearer ` on requests to the authenticated tools. The market tools also accept the header, but a token that fails validation is rejected with `401` rather than falling back to anonymous access, so an expired token never silently loses privileges. `server/discover` never requires authentication; `tools/list` works without a token, scoped to the market tools.

### Tools

Tools span market data, account data, order history, trading, and withdrawals:

- `market.get_assets` - list available assets for a source
- `market.get_price` - indicative price for a trading pair
- `account.get_balances` - balances with available and total amounts per asset
- `account.get_settings` - account settings and configuration
- `orders.get_history` - historical orders with date filtering and pagination
- `orders.get_status` - status of one order by instruction ID
- `withdrawals.list` - historical withdrawals with date filtering and pagination
- `trading.submit_order` - submit a swap order
- `withdrawals.create` - create an offchain withdrawal to a whitelisted location

Read-only tools carry the `readOnlyHint` annotation. `trading.submit_order` and `withdrawals.create` carry `destructiveHint`.

### Server Card

`GET /.well-known/mcp/server-card.json` returns the server card: server name and version, description, endpoint, and transport.

## MCP JSON-RPC

`POST /mcp`

Send a JSON-RPC request to the MCP server (server/discover, tools/list, tools/call). See the MCP Server section description for full protocol details including required headers, authentication, and tool discovery.

**Responses**

- **200**: JSON-RPC response

**Example**

```bash
curl -X POST "https://api.demo.omniaexchange.com/api/mcp"
```

---

