# API keys and raw MCP

URL: https://docs.sigment.ai/connect/api-keys

Call the Sigment MCP server from scripts and headless agents with an API key.

Create a key in **Sigment → Settings → AI agents → API keys**. Keys start with `ak_`, are approved automatically, and can be revoked on the same page. Send the key on every request:

```http
Authorization: Bearer ak_...
```

## Use an MCP client library

The easiest route is an official MCP SDK with the Streamable HTTP transport. For example, in Python (`pip install "mcp>=2"`):

```python
import asyncio, httpx2
from mcp import ClientSession
from mcp.client.streamable_http import streamable_http_client

async def main():
    http = httpx2.AsyncClient(headers={"Authorization": "Bearer ak_..."}, timeout=60)
    async with http, streamable_http_client("https://api.sigment.ai/mcp", http_client=http) as (read, write, *_):
        async with ClientSession(read, write) as session:
            await session.initialize()
            print(await session.call_tool("get_account", {}))

asyncio.run(main())
```

## Raw JSON-RPC

The server is **stateless**: every request is a plain `POST` that returns JSON, so no session ID or SSE stream is needed. `GET /mcp` returns `405`. Send both `Accept` types:

```bash
curl -s https://api.sigment.ai/mcp \
  -H "Authorization: Bearer $SIGMENT_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'
```

Call a tool:

```bash
curl -s https://api.sigment.ai/mcp \
  -H "Authorization: Bearer $SIGMENT_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{"jsonrpc":"2.0","id":2,"method":"tools/call",
       "params":{"name":"quote_cost","arguments":{"action":"discovery"}}}'
```

Tool errors come back as a normal result with `"isError": true` and a message that tells the agent what to do next. See [Errors](https://docs.sigment.ai/guides/errors).
