# Kotib Analytics MCP API: API keys for your own agents

**Version 1.1 · 11 November 2026**

This guide explains how to connect your own AI agents and integrations to Kotib Analytics with an API key. It covers authentication, security, limits, errors and the full tool reference.

## Contents

1. [Overview](#1-overview)
2. [Quickstart](#2-quickstart)
3. [Authentication and key format](#3-authentication-and-key-format)
4. [Security best practices](#4-security-best-practices)
5. [Key lifecycle: expiry, rotation, revocation](#5-key-lifecycle-expiry-rotation-revocation)
6. [IP allow-list](#6-ip-allow-list)
7. [Rate limits and quotas](#7-rate-limits-and-quotas)
8. [Errors](#8-errors)
9. [Tools reference](#9-tools-reference)
10. [Data conventions](#10-data-conventions)
11. [Versioning and changelog](#11-versioning-and-changelog)
12. [Support](#12-support)

---

## 1. Overview

The Kotib Analytics MCP server gives your AI agents **read-only** access to your company's call-center data: analysed calls, transcripts, scores, rule violations, employees, call topics and month overviews. It uses the open [Model Context Protocol](https://modelcontextprotocol.io) (MCP), so it works with any MCP client that supports remote servers over Streamable HTTP and a custom `Authorization` header. Examples are OpenClaw, Hermes, Claude Desktop, Cursor, and your own code built on an MCP SDK.

| | |
|---|---|
| Endpoint | `https://mcp.kotib.ai/mcp` |
| Transport | MCP Streamable HTTP (stateless, JSON responses) |
| Authentication | `Authorization: Bearer kak_…` header |
| Access | Read-only. A key cannot change or delete anything in Kotib. |
| Scope | One company. A key sees every branch, department and call of the company it was created in, and nothing else. |
| Time zone | Asia/Tashkent (UTC+05:00) |

**Key facts**

- **One key = one company.** If you work with several companies in Kotib, create a key in each company. Their data never mixes.
- **The key is not a person.** It reads as the company's read-only service account, not as the owner. Changing the owner's password or employees does not affect the key.
- **Only the company owner** can create, change and revoke keys, from their own account.
- **AI connectors must be turned on** for the company (Settings → AI connectors → «Allow AI connectors in this company»).

## 2. Quickstart

### Step 1. Create a key

1. Sign in to Kotib Analytics as the company owner.
2. Open **Settings → AI connectors**, then the **API keys for your own agents** section.
3. Click **Create key**. Enter a name that says who will use the key and what for (for example, «OpenClaw — sales team»), choose how long it is valid, and optionally list the IP addresses it may be used from (see [section 6](#6-ip-allow-list)).
4. **Copy the key right away.** It is shown only once. Kotib stores only a hash of the key, so a lost key cannot be recovered: revoke it and create a new one.

Put the key in an environment variable or in your secret manager, for example:

```bash
export KOTIB_API_KEY="kak_…"
```

### Step 2. Configure your MCP client

Every client needs the same three things: the URL `https://mcp.kotib.ai/mcp`, the Streamable HTTP transport, and the header `Authorization: Bearer <your key>`. The file, the field names and the syntax for environment variables differ between clients. This is the format of Claude Code (`.mcp.json`), which reads the key from the `KOTIB_API_KEY` environment variable:

```json
{
  "mcpServers": {
    "kotib": {
      "type": "http",
      "url": "https://mcp.kotib.ai/mcp",
      "headers": { "Authorization": "Bearer ${KOTIB_API_KEY}" }
    }
  }
}
```

Other clients:

| Client | Where | What differs |
|---|---|---|
| Cursor | `~/.cursor/mcp.json` or `.cursor/mcp.json` | No `type`; the variable is written `${env:KOTIB_API_KEY}`. |
| VS Code (Copilot) | `.vscode/mcp.json` | The top-level key is `servers`, not `mcpServers`; `"type": "http"`. For the key use an `inputs` entry with `"password": true` and `${input:…}`. |
| OpenClaw | `~/.openclaw/openclaw.json` | Under `mcp.servers.kotib`: `url`, `headers` and `"transport": "streamable-http"` (without it OpenClaw uses SSE, which this server does not offer). `${KOTIB_API_KEY}` is expanded. |
| Hermes Agent | `~/.hermes/config.yaml` | YAML: `mcp_servers:` → `kotib:` → `url:` and `headers:`; `${KOTIB_API_KEY}` is expanded. |
| Claude Desktop, claude.ai | Settings → Connectors → Add custom connector | Not in `claude_desktop_config.json` (that file is for local servers only). Enter the URL, and under **Request headers** add `Authorization` = `Bearer kak_…`. These connectors call Kotib from Anthropic's servers, not from your computer (see [section 6](#6-ip-allow-list)). |
| MCP Inspector (CLI) | command line | `npx @modelcontextprotocol/inspector --cli https://mcp.kotib.ai/mcp --transport http --header "Authorization: Bearer $KOTIB_API_KEY" --method tools/list`. Its `--config` file does not expand `${…}`. |

Check your client's own documentation for remote MCP servers. If your client does not expand environment variables, use its own secret or credential storage. Do not paste the key into a configuration file that is shared or committed to a repository. A request whose header holds no valid `kak_` key (for example an unexpanded `${KOTIB_API_KEY}`) gets `401` with an OAuth sign-in hint, so some clients then try to open a browser sign-in: check the header first.

### Step 3. Check the connection

Ask your agent: *"Which Kotib company am I connected to?"* The agent calls the `get_my_scope` tool and answers with your company name, its branches and departments.

### Python (official MCP SDK)

Tested with the `mcp` Python package 2.x:

```python
import asyncio
import os

from mcp import ClientSession
from mcp.client.streamable_http import create_mcp_http_client, streamable_http_client

URL = "https://mcp.kotib.ai/mcp"


async def main():
    http = create_mcp_http_client(headers={"Authorization": f"Bearer {os.environ['KOTIB_API_KEY']}"})
    async with http, streamable_http_client(URL, http_client=http) as (read, write):
        async with ClientSession(read, write) as session:
            await session.initialize()
            tools = await session.list_tools()
            print([t.name for t in tools.tools])
            result = await session.call_tool("get_my_scope", {})
            print(result.structured_content)


asyncio.run(main())
```

With the older 1.x SDK (1.8 or later), three things differ: the function is `streamablehttp_client`, it gives three values, and result fields are camelCase. The rest of the example above stays the same:

```python
from mcp.client.streamable_http import streamablehttp_client

async def main():
    headers = {"Authorization": f"Bearer {os.environ['KOTIB_API_KEY']}"}
    async with streamablehttp_client(URL, headers=headers) as (read, write, _):
        async with ClientSession(read, write) as session:
            await session.initialize()
            result = await session.call_tool("get_my_scope", {})
            print(result.structuredContent)      # 1.x: structuredContent, isError
```

### curl (raw JSON-RPC)

The server is stateless: every request is a single HTTP `POST` with one JSON-RPC message, and no session header is needed.

```bash
# initialize
curl -sS https://mcp.kotib.ai/mcp \
  -H "Authorization: Bearer $KOTIB_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"curl","version":"1.0"}}}'

# list the tools
curl -sS https://mcp.kotib.ai/mcp \
  -H "Authorization: Bearer $KOTIB_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "MCP-Protocol-Version: 2025-06-18" \
  -d '{"jsonrpc":"2.0","id":2,"method":"tools/list"}'

# call a tool
curl -sS https://mcp.kotib.ai/mcp \
  -H "Authorization: Bearer $KOTIB_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "MCP-Protocol-Version: 2025-06-18" \
  -d '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"search_calls","arguments":{"limit":5}}}'
```

A tool result has the data twice: as JSON in `result.structuredContent`, and as the same JSON text in `result.content[0].text`. A failed call has `result.isError: true` (see [section 8](#8-errors)).

## 3. Authentication and key format

Send the key in the `Authorization` header of **every** request:

```
Authorization: Bearer kak_ab12cd_<40 letters and digits>
```

- **Header only.** A key in a query string (`?api_key=…`) or in the URL path is never accepted: the request is refused with `401` (or `404` for a path other than `/mcp`).
- **Format:** `kak_` + 6 lowercase letters or digits + `_` + 40 letters and digits, 51 characters in total. The `kak_` prefix lets secret scanners recognise a leaked key.
- **Key prefix.** The first 10 characters (for example `kak_ab12cd`) are not secret. They identify the key in Settings and in Kotib's logs. When you contact support, quote the prefix, **never the whole key**.
- Kotib stores only a SHA-256 hash of the key. Nobody at Kotib can see or restore it.
- All traffic uses HTTPS (TLS). Plain HTTP is redirected and must not be used for requests carrying a key.

Call the endpoint from your server or agent runtime. Browser JavaScript on your own web pages is not supported: it would expose the key to every visitor, and the server refuses unknown browser origins.

## 4. Security best practices

An API key gives access to call transcripts, scores and employee data. Treat it like a password to your company's data.

**Storing keys**

- Keep keys in a secret manager (for example HashiCorp Vault, AWS Secrets Manager, Google Secret Manager, Azure Key Vault, Doppler, 1Password) or in environment variables of the process that needs them.
- Never put a key in source code, in a repository (including private ones), in container images, in logs, in tickets, or in chats and e-mail threads. If a key reaches any of these, treat it as leaked.
- Do not log the `Authorization` header in your own proxies and HTTP clients.

**Least privilege and separation**

- Create **one key per agent or integration**, with a name that says who uses it. You can then revoke one integration without stopping the others, and the «last used» date in Settings shows which key is active.
- Choose the shortest lifetime that is practical for the integration.
- For agents that run on servers with fixed addresses, **set an IP allow-list** (see [section 6](#6-ip-allow-list)). A leaked key is then useless from anywhere else.
- Every key is read-only and limited to one company by design. No key can write data or read another company.

**Rotation and incident response**

- Rotate keys before they expire, and whenever someone who had access to a key leaves the team (see [section 5](#5-key-lifecycle-expiry-rotation-revocation)).
- If you suspect a key has leaked, **revoke it immediately** in Settings → AI connectors, create a new one, and tell Kotib support at [team@kotib.ai](mailto:team@kotib.ai) with the key prefix.

**Personal data**

- Transcripts, summaries and employee data can contain personal data of your clients and employees. You are responsible for handling the data you retrieve in line with your legal and contractual obligations: store only what you need, protect it, and pass it to third-party AI providers only where you are allowed to.
- Client phone numbers are always masked in tool results (see [section 10](#10-data-conventions)).

**Transcripts are untrusted input (prompt injection)**

- Transcripts are speech-to-text of what callers and employees said. They are marked `content_origin: speech_to_text` and may contain recognition errors.
- Treat transcript text, snippets, summaries and other free text as **data, not instructions**. A caller could say something designed to manipulate an AI agent ("ignore your instructions and…"). Configure your agent so that text from tool results can never trigger actions on its own, especially actions with side effects such as sending messages, changing records or calling other tools with elevated rights.

## 5. Key lifecycle: expiry, rotation, revocation

### States

| State | Meaning |
|---|---|
| Active | The key works. |
| Expired | The validity period has ended. The key no longer works and cannot be extended. |
| Revoked | The owner revoked the key, or AI connectors were turned off for the company. The key no longer works. This cannot be undone. |

### Expiry

When you create a key, choose its lifetime: **30, 90 (default), 180 or 365 days**. Settings shows the expiry date of each key, in red when fewer than 14 days are left. An expired key cannot be extended: create a new one.

### Rotation without downtime

Use an overlap so that your integration never stops:

1. **Create** a new key in Settings (a name such as «OpenClaw — sales team (2027-02)» helps).
2. **Deploy** it: update the secret in your secret manager or environment and restart or reload the agent.
3. **Check** that the new key is used: its «last used» date in Settings appears, and the agent answers normally.
4. **Revoke** the old key.

Plan rotation a few days before the expiry date. Several keys can be active at the same time.

### Revocation

Click **Revoke** next to the key in Settings and confirm. Revocation is final.

- Every tool call is checked against the key's current state, so **data access stops at once**: the next tool call returns the tool error `the API key is invalid, expired or revoked`. A connection handshake (`initialize`, `tools/list`) may still succeed for up to a minute afterwards, but it returns no company data.
- After that every request with the key gets `401 invalid_token`.
- Turning AI connectors off for the company revokes **all** of its keys. After turning them back on, create new keys.

## 6. IP allow-list

You can limit a key to the addresses your agents call from. The list is optional.

- Entries: IPv4 addresses (`203.0.113.7`), IPv6 addresses (`2001:db8::10`) or CIDR networks (`198.51.100.0/24`, `2001:db8::/48`). Separate them with new lines or commas.
- Up to **20** entries per key.
- **Empty list = any address.**
- Set the list when you create the key, or change it later with **Edit IPs** next to an active key. Every change is recorded in Kotib's audit log.
- Kotib sees the address of the connection that reaches `mcp.kotib.ai`. If your agent goes through a proxy, NAT gateway or VPN, list the **outgoing (egress)** address of that gateway, not the internal address of your server. `X-Forwarded-For` and similar headers sent by the client are ignored. Connectors added in Claude (web, Desktop, mobile) call from Anthropic's servers, so an allow-list there must hold Anthropic's published egress addresses.
- A request from an address outside the list is refused with `403 ip_not_allowed`. The answer does not reveal anything about the key or its list. A change to the list applies to the next tool call at once; a connection that is already open gets the tool error `This request's IP address is not allowed for this API key.`

Use the allow-list for every key that runs on servers with fixed addresses. For agents on laptops or other changing networks, leave it empty and rely on short lifetimes and quick revocation.

## 7. Rate limits and quotas

| Limit | Value | When exceeded |
|---|---|---|
| Requests per key | **60 a minute**, counted per calendar minute: every tool call, plus the key check of the connection (about once a minute) | During a tool call, a tool error with `retry_after` (seconds); when a connection is opened, HTTP `429` with `Retry-After` |
| Client-phone searches (`search_calls` with `client_phone`) | **60 an hour per key**; period of at most **93 days** | Tool error; the budget resets at the start of the next hour |
| Transcript searches (`find_calls_mentioning`) | **2 at the same time** and **20 an hour**, shared by all API keys of the company | Tool error; the hourly budget resets at the start of the next hour |
| One tool call | **25 seconds** | Tool error: narrow the period or the scope (one branch, department or employee) |
| One tool result | **60,000 characters** | Lists are shortened, with `truncated: true` and a `truncated_note`; page with `limit` / `offset` or narrow the filters |
| Transcript page (`get_call`) | **20,000 characters** | Read the next page with `transcript_offset` = `transcript.next_offset` |
| Period of one request | at most **366 days** | Tool error |
| Request body | 1 MB | HTTP `413` |

Recommendations:

- On `429`, wait the number of seconds in `Retry-After` before retrying. For other temporary failures (`503`, network errors) retry with exponential backoff and jitter, for example 1 s, 2 s, 4 s, up to about 60 s.
- Do not poll more often than you need. For keeping a copy of calls up to date, use the incremental feed in [section 10](#10-data-conventions) every few minutes instead of re-reading whole periods.
- Prefer filters (`branch_id`, `department_id`, `employee_id`, shorter periods) over large scans.

## 8. Errors

There are two kinds of errors:

1. **HTTP errors** happen before a tool runs: the key, the address or the rate is refused. The body is JSON `{"error": "...", "error_description": "..."}` (except `413`, which has no JSON body).
2. **Tool errors** happen inside a successful HTTP `200` response: `result.isError` is `true`, and the message is in `result.content[0].text` and in `result.structuredContent.error`.

### HTTP errors

| HTTP | `error` | Cause | What to do |
|---|---|---|---|
| 401 | `invalid_token` | No `Authorization` header, or the key is unknown, expired or revoked (turning AI connectors off revokes every key), or it was sent outside the header | Check that the header is `Authorization: Bearer kak_…`. If the key expired or was revoked, create a new one. |
| 403 | `access_denied` | AI connectors are turned off for the company while the key is still active (rare: turning them off normally revokes every key, which gives `401`) | The owner turns them on in Settings → AI connectors and creates a new key. |
| 403 | `ip_not_allowed` | The key has an IP allow-list, and the request came from another address | Call from an allowed address (check your egress IP), or the owner changes the list. |
| 413 | | The request body is larger than 1 MB | Send smaller requests. |
| 429 | `rate_limited` | More than 60 requests a minute on this key | Wait `Retry-After` seconds, then retry. |
| 503 | `temporarily_unavailable` | Kotib is temporarily unavailable | Retry after `Retry-After` seconds, with backoff. |

Every response carries an `X-Request-ID` header. You may send your own `X-Request-ID` (up to 64 characters) to correlate requests with your logs. Quote it when you contact support.

### Tool errors

| Message (beginning) | Cause | What to do |
|---|---|---|
| `Invalid argument …` | An argument does not match the tool's JSON schema (wrong type, unknown name, out of range) | Fix the argument; `tools/list` returns each tool's schema. |
| `Unknown tool: …` | No tool with this name | Use a name from `tools/list`. |
| `… must be a date in the form YYYY-MM-DD` / `date_from is after date_to` / `The period may be at most 366 days` | Bad period | Fix the dates. |
| `Not found, or not visible with your access: …` | The id does not exist in this company | Use ids returned by the other tools. |
| `With client_phone the period may be at most 93 days` | Phone search over too long a period | Shorten the period. |
| `This connection has used its 60 client-phone searches of this hour …` | Phone search budget used up | Wait until the next hour. |
| `2 transcript searches are already running …` / `You have used the 20 transcript searches of this hour …` | Transcript search limits | Wait for running searches to finish, or until the next hour. `search_calls` and `get_call` still work. |
| `This took longer than 25 seconds and was stopped …` | The request was too heavy | Narrow the period or the scope. |
| `Too many requests to Kotib on this connection; try again in N seconds.` | Rate limit reached during the call; `structuredContent.retry_after` has the seconds | Wait, then retry. |
| `Kotib is temporarily unavailable; try again shortly.` / `Kotib could not complete this request …` | A temporary failure | Retry with backoff. If it persists, contact support with the `X-Request-ID`. |
| `the API key is invalid, expired or revoked` | The key was revoked or expired during the session | Create a new key. |
| `This request's IP address is not allowed for this API key.` | The key's IP allow-list was changed during the session | Call from an allowed address, or the owner changes the list. |

## 9. Tools reference

All tools are read-only and idempotent (`readOnlyHint: true`, `destructiveHint: false`). Arguments are validated against the JSON schema in `tools/list`; unknown arguments are refused. Results are JSON objects.

**Common arguments.** Many tools take a period and scope filters:

| Argument | Type | Meaning |
|---|---|---|
| `date_from` | string `YYYY-MM-DD` | First day (Asia/Tashkent). Default: 29 days before `date_to`. |
| `date_to` | string `YYYY-MM-DD` | Last day, included. Default: today; with only `date_from`, 29 days after `date_from` (never later than today). Without both dates, the last 30 days (today included) are used. |
| `branch_id` | integer | Only this branch (ids from `get_my_scope`). |
| `department_id` | integer | Only this department or store (ids from `get_my_scope`). |
| `employee_id` | integer | Only this employee (ids from `find_employee` or `rank_employees`). |

Most results also return the `period` (`date_from`, `date_to`) that was actually used.

### Overview of the 14 tools

| Tool | What it returns |
|---|---|
| `get_my_scope` | The company, its branches and departments, today's date |
| `get_kpis` | Top-line KPIs of a period with change against the previous period |
| `search_calls` | Analysed calls with filters; client-phone filter; incremental feed of changes |
| `get_call` | One call in full: scores, AI summary, violations, transcript |
| `find_calls_mentioning` | Calls whose transcript contains a word or phrase |
| `rank_employees` | Employees ranked by average score |
| `find_employee` | Employees by name, phone or external code |
| `get_employee` | One employee's performance portrait |
| `get_violations` | Rule violations: summary or list of calls |
| `get_call_topics` | What clients called about |
| `get_criterion` | The scoring criteria and their rubrics |
| `get_month_overview` | One month against the previous month |
| `get_lost_deal_reasons` | Why clients did not book or buy |
| `rank_employees_by_criterion` | Employees ranked on one criterion |

### `get_my_scope`

Who the key reads as and which data it can see. No arguments. Call it first to get the branch and department ids for the filters.

Returns: `user` (`id`, `name`, `role`: `viewer` for an API key), `company` (`id`, `name`), `access` (`company` for an API key: every call of the company), `access_note`, `branches` and `departments` (`id`, `name`; up to 500 each), `today` (`YYYY-MM-DD`), `timezone` (`Asia/Tashkent`).

### `get_kpis`

Top-line numbers of the calls analysed in a period.

Arguments: period and scope filters.

Returns: `period`, `kpis` with `quality_index` (average call score), `quality_index_delta_pct`, `call_count`, `call_count_delta_pct`, `total_minutes`, `employee_count`, and `kpis.period` (`start_time`, `end_time`, `previous_start_time`, `previous_end_time`). The `…_delta_pct` values are the relative change, in percent, against the previous period of the same length.

### `search_calls`

Analysed calls, one row per call. It does not search what was said; for that use `find_calls_mentioning`.

Arguments:

| Argument | Type | Meaning |
|---|---|---|
| period and scope filters | | See above |
| `employee_name` | string, up to 100 | Part of the employee's name (names only; a phone number here is refused) |
| `external_code` | string, 1–64 | The employee's external code (see [section 10](#10-data-conventions)), exact match |
| `min_score`, `max_score` | number | Total score range |
| `order` | `newest` (default), `oldest`, `lowest_score`, `highest_score` | Sort order |
| `limit` | integer 1–50, default 20 | Rows per page |
| `offset` | integer 0–10000, default 0 | Rows to skip; use `next_offset` from the previous page |
| `client_phone` | string, 9–32 | Only calls with this client phone number, in any format (`+998 90 123-45-67`, `901234567`). A filter only: numbers in the results stay masked. Period of at most 93 days; 60 searches an hour per key. |
| `updated_since` | string, ISO 8601 | Only calls whose analysis was created or updated after this moment (`2026-11-09T10:00:00+05:00`; without an offset, Tashkent time). Oldest change first. See the incremental feed in [section 10](#10-data-conventions). |
| `cursor` | string | `next_cursor` from the previous `updated_since` page |

Each call: `call_id`, `date` (call start), `employee`, `external_code`, `branch`, `department`, `total_score`, `direction`, `analysed_at`, `call_url`.

Paging: `next_offset` (null on the last page). With `updated_since` or `cursor`: `updated_since`, `next_cursor`, `has_more` and a `note` instead of `next_offset`. With `client_phone`: `client_phone_filter: "applied (numbers in results stay masked)"`.

### `get_call`

One analysed call by `call_id`.

Arguments: `call_id` (integer, required; from `search_calls`, `find_calls_mentioning` or `get_violations`), `include_transcript` (boolean, default `false`), `transcript_offset` (integer, default 0).

Returns: `call_id`, `call_url`, `date`, `duration_sec`, `employee`, `department`, `external_code`, `topic`, `client_phone` (masked), `direction`, `analysed_at`, `is_real_conversation`, `total_score`, `summary`, `final_feedback`, `recommendations`, `criteria` (each: `criterion`, `score`, `max_score`, `is_violation`, `feedback`), `violations` (each: `rule`, `score`, `feedback`).

Without the transcript: `transcript_chars` (its length). With `include_transcript: true`: `transcript` with `content_origin: "speech_to_text"`, `text` (up to 20,000 characters), `offset`, `next_offset` (null on the last page) and `total_chars`.

### `find_calls_mentioning`

Calls whose transcript contains a word or phrase. Latin and Cyrillic spellings are both matched. Transcript searches have their own limits (see [section 7](#7-rate-limits-and-quotas)).

Arguments: `query` (string 2–100, required), period and scope filters (**default period: the last 7 days**), `limit` (1–50, default 20), `max_calls` (1–200, default 150: how many calls to read at most, newest first).

Returns: `period`, `query`, `calls` (each: `call_id`, `date`, `employee`, `branch`, `department`, `total_score`, `snippet`, `call_url`), `match_count`, `coverage` (`scanned`, `total`, `capped`, `fetch_errors`), `note`, `snippet_origin: "speech_to_text"`. When `coverage.capped` is `true`, not every call of the period was read: narrow the period or the scope for a complete answer.

### `rank_employees`

Employees ranked by their average call score in a period.

Arguments: period and scope filters, `order` (`best_first` default, `worst_first`), `limit` (1–100, default 20).

Returns: `period`, `order`, `employees` (each: `employee_id`, `name`, `external_code`, `avg_score`, `calls`, `avg_duration_sec`).

### `find_employee`

Employees by name (Latin or Cyrillic, close spellings too) or phone, or by external code. Give `query`, `external_code` or both.

Arguments: `query` (string 2–100), `external_code` (string 1–64, exact match), `limit` (1–50, default 20).

Returns: `employees` (each: `id` (use it as `employee_id`), `name`, `phone` (masked), `external_code`, `branch_id`, `department_id`).

### `get_employee`

Performance portrait of one employee in a period, as on the employee page in Kotib Analytics.

Arguments: `employee_id` (integer, required), `date_from`, `date_to`.

Returns: `period`, `employee_id`, `external_code`, `profile` with `employee` (`id`, `name`, `external_code`, `branch`, `departments`), `summary` (`analyzed_calls`, `inbound_calls`, `outbound_calls`, `average_score`, `average_calls_per_day`, `average_duration` in seconds), `criteria` (each: `prompt_id`, `name`, `avg_score`, `max_score`, `percentage`, `samples`, `is_violation`), `strengths` and `weaknesses` (`name`, `percentage`, `avg_score`, `max_score`), `best_audios` and `worst_audios` (up to 5 calls each, with `audio_file_id` = `call_id` and `final_score`).

### `get_violations`

Rule violations in a period.

Arguments: period and scope filters, `mode` (`summary` default, `list`), `limit` (1–50, default 20), `offset` (for `list`).

Returns, `mode: "summary"`: `by_criterion` (each: `criterion`, `violations`), `violations_sampled`, `records_scanned`, `coverage_capped`, `note`.

Returns, `mode: "list"`: `calls` (each: `call_id`, `date`, `employee`, `branch`, `department`, `penalty_total`, `violations` (each: `name`, `note`, `score`), `call_url`), `next_offset`, `records_scanned`, `coverage_capped`, `note`.

### `get_call_topics`

What clients called about in a period: the company's topic charts.

Arguments: period and scope filters.

Returns: `period`, `charts` (each: `chart`, `chart_id`, `total`, `topics` (each: `topic`, `item_id`, `count`, `pct`)).

### `get_criterion`

The company's scoring criteria.

Arguments: `criterion_id` (integer, optional).

Returns: without `criterion_id`, `criteria` (each: `id`, `name`). With `criterion_id`, `criterion` with `id`, `name`, `rubric` (the evaluation text, up to 4,000 characters; a longer one is cut and ends with `…(truncated)`), `max_score`, `is_violation` (whether it is a violation rule), `chart_type`.

### `get_month_overview`

One month against the previous month. A running month is compared as month-to-date with the same days of the previous month.

Arguments: `month` (`YYYY-MM`, default: the current month), `branch_id`, `department_id`, `employee_id`.

Returns: `comparison` (`month_to_date` or `calendar_months`), `comparison_label`, `this_period` and `previous_period` (`date_from`, `date_to`, `analyzed_calls`), `small_sample`, `kpis` (`calls`, `quality_index`, `minutes`, `active_employees`, each with `this`, `previous`, `change`, `change_pct`), `violation_calls`, `biggest_drops`, `biggest_gains`, `weakest_criteria`, `most_violated_rules`, `client_portrait_shifts`, `biggest_problem` (with `example_calls`), `note`.

### `get_lost_deal_reasons`

Why clients did not book or buy in a period, from the loss-reason field of the company's client portrait.

Arguments: period and scope filters, `max_reasons` (1–5, default 3).

Returns: `has_reason_field`. If the company has no such field: `portrait_fields` and a `note`. Otherwise: `field`, `date_from`, `date_to`, `answers_total`, `reasons_total`, `small_sample`, `distribution` (up to 10 rows: `reason`, `count`, `pct_of_answers`, `pct_of_reasons`, `is_reason`), `top_reasons` (the same fields plus `calls_tagged` and `example_calls`: up to 3 newest calls with `call_id`, `date`, `call_url`), `note`. To read what the client said, call `get_call` with `include_transcript: true`.

### `rank_employees_by_criterion`

Every employee's average score on one criterion, worst first, with AI comments on their weakest calls.

Arguments: `criterion_id` (integer, required; from `get_criterion`), period and scope filters, `min_calls` (1–100, default 5), `limit` (1–100, default 20).

Returns: `criterion`, `criterion_id`, `max_score`, `is_violation_rule`, `date_from`, `date_to`, `team_avg`, `team_pct`, `team_calls`, `min_calls`, `employees` (each: `employee_id`, `name`, `calls`, `avg`, `pct`, `small_sample`, `weakest_call_comments`, `worst_call_url`; for a violation rule also `violations` and `violation_rate_pct`), `too_few_calls` (employees with fewer than `min_calls` scored calls: `name`, `calls`), `note`.

## 10. Data conventions

### Time

- All dates and times are in **Asia/Tashkent (UTC+05:00)**.
- Dates are `YYYY-MM-DD`. Every date-time in a result is ISO 8601 with the offset, for example `2026-11-09T10:15:30+05:00`.
- `date_from` / `date_to` are Tashkent calendar days; `date_to` is included.
- `updated_since` accepts ISO 8601 with or without an offset; without one it is read as Tashkent time.

### Identifiers and links

- `call_id` identifies a call everywhere (`get_call`, `call_url`). Ids are integers and are stable.
- `call_url` opens the call page in Kotib Analytics; it requires a Kotib sign-in. Results never contain links to audio files.

### Client phone numbers

- Client phone numbers are **masked** in every result: all digits except the last two are replaced with `*` (`+998901234567` → `+**********67`). This also applies to phone numbers that appear in free text such as transcripts and summaries.
- `search_calls` with `client_phone` lets you find the calls of a number you already know, without revealing other numbers.

### Call fields

- `direction`: `incoming`, `outgoing` or `unknown` (as reported by the telephony integration; `unknown` for badges, meetings and uploaded files).
- `analysed_at`: when the call's analysis was created or last updated. A call can be analysed again later (for example after the scoring criteria change).
- `total_score`: the call's total score on the company's own scoring scale; per-criterion scores come with their `max_score`.
- `is_real_conversation` (`get_call`): whether the recording is a real conversation.
- Only completed analyses are returned.

### External code («Код»)

`external_code` is the id your company gives an employee in its other systems (CRM, HR, 1C). It is set in Kotib Analytics on the employee's card and is returned verbatim. Use it to join Kotib data with your own systems: `search_calls` and `find_employee` filter by it (exact match).

### Pagination

- `search_calls` (without `updated_since`) and `get_violations` (`mode: "list"`) page with `limit` / `offset`; pass `next_offset` from the previous page. `next_offset: null` means the last page.
- `get_call` pages the transcript with `transcript_offset`.
- The incremental feed pages with `cursor`.

### Incremental sync: new and re-analysed calls

To keep your own copy of calls up to date (a data warehouse, a CRM, a BI tool), use `search_calls` with `updated_since` and then `cursor`:

1. First run: call `search_calls` with `updated_since` set to the moment you want to start from, and `limit: 50`.
2. Store `next_cursor` from every answer, even an empty one.
3. While `has_more` is `true`, call again at once with `cursor` = the stored `next_cursor`.
4. When `has_more` is `false`, wait (for example 5 minutes) and call again with the stored cursor.
5. Store each call by `call_id` (insert or update): a call that is analysed again appears in the feed again, with a newer `analysed_at`. Use `get_call` for the details you need.

Properties of the feed:

- Ordered by `analysed_at`, oldest first.
- The cursor continues exactly after the last call returned: no call is skipped or repeated within one pass.
- Changes of the last 60 seconds are held back until the next poll, so an analysis that is still being saved is never missed.
- Only completed analyses of real conversations are included. `date_from` / `date_to` are optional and filter by call date; the scope filters also apply.
- The cursor is opaque: store it as it is and do not build it yourself.

Example in Python (with the MCP SDK 2.x session from [section 2](#2-quickstart); with 1.x read `result.isError` and `result.structuredContent`):

```python
import asyncio


async def sync_calls(session, cursor, save_call, save_cursor):
    """Fetch every change after `cursor` (or start from a date), then poll every 5 minutes."""
    while True:
        args = {"cursor": cursor, "limit": 50} if cursor else {
            "updated_since": "2026-11-01T00:00:00+05:00", "limit": 50}
        result = await session.call_tool("search_calls", args)
        if result.is_error:
            raise RuntimeError(result.content[0].text)
        page = result.structured_content
        for call in page["calls"]:
            save_call(call)              # upsert by call["call_id"]
        cursor = page["next_cursor"]
        save_cursor(cursor)              # persist, so a restart continues from here
        if not page["has_more"]:
            await asyncio.sleep(300)
```

## 11. Versioning and changelog

The tool set described here is **version 1** and is stable.

- **Additive changes** can happen at any time without notice: new tools, new optional arguments, new fields in results, new values in descriptive text. Build your integration to ignore fields and tools it does not know.
- **Breaking changes** (removing or renaming a tool, an argument or a result field, or changing its meaning) are announced in advance and recorded in this changelog.
- `tools/list` always returns the current tools with their JSON schemas.

### Changelog

| Date | Version | Change |
|---|---|---|
| 2026-11-11 | 1.1 | Guide corrections after testing (no change to the API): client configuration for each MCP client; MCP Python SDK 1.x example; revocation: the handshake may succeed for up to a minute; default `date_to` with only `date_from`; rate-limit counting; errors `401` after AI connectors are turned off and the IP tool error; `average_duration` in seconds. |
| 2026-11-10 | 1.0 | First public version: API keys (create, expiry, IP allow-list, revocation) in Settings → AI connectors; 14 read-only tools; client-phone filter and incremental feed (`updated_since` / `cursor`) in `search_calls`; `direction` and `analysed_at` on calls; employee external code. |

## 12. Support

- Telegram: [@kotibsupport](https://t.me/kotibsupport)
- E-mail: [team@kotib.ai](mailto:team@kotib.ai)

When you write to us, include the key **prefix** (for example `kak_ab12cd`, never the whole key), the time of the request, the tool name and the `X-Request-ID` of the response. To report a leaked key or a security issue, revoke the key first, then write to [team@kotib.ai](mailto:team@kotib.ai).

Terms of use for AI connectors: [analytics.kotib.ai/legal/ai-connectors](https://analytics.kotib.ai/legal/ai-connectors).
