# MCP server

> Give an agent the whole API in one line.

tikdataapi.com serves a hosted [MCP](https://modelcontextprotocol.io) server at `https://api.tikdataapi.com/mcp`.
Transport is Streamable HTTP. Nothing to install, nothing to run, and on most clients nothing to paste:
the server implements the MCP authorization flow, so a client signs you in through a browser and gets
its own credential. A key in the header works too, and is what a client with no browser needs.

Every tool call is one REST request under the hood, at the same price, through the same cache and rate limit.
The agent sees `credits_charged` and `balance_remaining` in every result.

## Connect [#connect]

**Claude Code**

```bash
claude mcp add --transport http tikdataapi https://api.tikdataapi.com/mcp
```

**Claude.ai and Claude Desktop**

Add `https://api.tikdataapi.com/mcp` as a custom connector in Settings. These clients have no field for a
request header, so this is the only route that reaches them.

**Cursor, Windsurf, and other clients with an MCP config file**

```json
{
  "mcpServers": {
    "tikdataapi": {
      "url": "https://api.tikdataapi.com/mcp"
    }
  }
}
```

**Clients that speak stdio only**

The [mcp-remote](https://www.npmjs.com/package/mcp-remote) bridge speaks stdio to the client and
Streamable HTTP to us, and signs in on the client's behalf.

```json
{
  "mcpServers": {
    "tikdataapi": {
      "command": "npx",
      "args": ["-y", "mcp-remote", "https://api.tikdataapi.com/mcp"]
    }
  }
}
```

## Connect with a key instead [#connect-with-a-key-instead]

A client that cannot open a browser — a server, a container, a CI job — sends the key in the same header
the REST API takes, or as `Authorization: Bearer tt_live_...`.

```bash
claude mcp add --transport http tikdataapi https://api.tikdataapi.com/mcp --header "x-api-key: tt_live_..."
```

```json
{
  "mcpServers": {
    "tikdataapi": {
      "url": "https://api.tikdataapi.com/mcp",
      "headers": { "x-api-key": "tt_live_..." }
    }
  }
}
```

For mcp-remote, pass the key through the environment. The header is written with no space after the
colon: mcp-remote splits the argument on the first colon, and a space there arrives as part of the key.

```json
{
  "mcpServers": {
    "tikdataapi": {
      "command": "npx",
      "args": ["-y", "mcp-remote", "https://api.tikdataapi.com/mcp", "--header", "x-api-key:${TIKDATAAPI_KEY}"],
      "env": { "TIKDATAAPI_KEY": "tt_live_..." }
    }
  }
}
```

## Signing in, for people writing clients [#signing-in-for-people-writing-clients]

An unauthenticated call to `/mcp` answers `401` with a pointer to the discovery chain, which is all a
client needs to obtain its own credential:

| Step | Where |
|---|---|
| The challenge | `WWW-Authenticate: Bearer resource_metadata="..."` on the 401 |
| Protected resource (RFC 9728) | `https://api.tikdataapi.com/.well-known/oauth-protected-resource` |
| Authorization server (RFC 8414) | `https://tikdataapi.com/.well-known/oauth-authorization-server` |
| Register a client (RFC 7591) | `https://tikdataapi.com/api/oauth/register` |
| Approve | `https://tikdataapi.com/oauth/authorize` |
| Exchange the code | `https://tikdataapi.com/api/oauth/token` |
| Disconnect (RFC 7009) | `https://tikdataapi.com/api/oauth/revoke` |

Clients are public and PKCE is required, with `S256` only. There are no scopes to choose: every tool is
read-only and there is one level of access.

What the exchange returns is an ordinary API key named after the app. It appears in the
[dashboard](https://tikdataapi.com/dashboard/keys) beside keys you made by hand, spends the same balance
at the same prices, and stops the moment you revoke it. It does not expire, and there is no refresh
token: it is the same class of credential you mint yourself, with the same revocation story.

## Tools [#tools]

| Tool | Arguments | Credits |
|---|---|---|
| `get_user` | `user` (username or sec_uid) | 1 |
| `get_users` | `usernames[]`, up to 100 | 1 per profile found |
| `get_user_videos` | `user`, `count` (default 16, up to 50), `cursor` | 1 per video |
| `get_users_videos` | `users[]` (usernames or sec_uids), up to 20, `count` 1 to 16 (default 3) | 1 per video |
| `get_video` | `id` | 1 |
| `get_videos` | `ids[]`, up to 100 | 1 per video found |
| `get_comments` | `video_id`, `count` (default 20, up to 50), `cursor` | 1 per comment |
| `get_comment_replies` | `video_id`, `comment_id`, `count` (default 20, up to 50), `cursor` | 1 per reply |
| `get_hashtag` | `name` | 1 |
| `get_hashtag_videos` | `name`, `count` (default 30, up to 50), `cursor` | 1 per video |
| `search_videos` | `query`, `count` (default 12, up to 50), `cursor` | 1 per video |
| `search_users` | `query`, `count` (default 10, up to 50), `cursor` | 1 per account |
| `get_user_followers` | `user`, `count` (default 30, up to 50), `cursor` | 1 per profile |
| `get_user_following` | `user`, `count` (default 30, up to 50), `cursor` | 1 per profile |
| `get_user_reposts` | `user`, `count` (default 16, up to 50), `cursor` | 1 per video |
| `get_user_playlists` | `user`, `count` (default 20, up to 50), `cursor` | 1 per playlist |
| `get_playlist_videos` | `playlist_id`, `count` (default 30, up to 50), `cursor` | 1 per video |
| `get_music` | `music_id` | 1 |
| `get_music_videos` | `music_id`, `count` (default 30, up to 50), `cursor` | 1 per video |
| `get_related_videos` | `video_id`, `count` (default 16, up to 16) | 1 per video |
| `get_trending_videos` | `count` (default 16, up to 50) | 1 per video |
| `search_music` | `query`, `count` (default 12, up to 50), `cursor` | 1 per sound |
| `search_live` | `query`, `count` (default 12, up to 50), `cursor` | 1 per room |
| `get_user_live` | `user` | 1 |
| `get_video_transcript` | `video_id`, `lang` (optional) | 1 |
| `search_hashtags` | `query`, `count` (default 10, up to 30) | 1 per hashtag |
| `get_balance` | | free |

Every tool takes `fresh: true` to bypass the cache: 2x for an item that has a cached copy, the normal price
for one that has none. All tools are read-only and idempotent, and are
annotated as such, so clients that auto-approve read-only tools do not prompt on every call.

`search_videos` uses the general ("Top") search of TikTok and finds videos only. `search_users` uses the account
search of TikTok (the "Users" tab) and gives short profiles; `get_user` or `get_users` gives the full, exact
profile. `search_music` uses the sound search of TikTok, and `search_live` its live search. TikTok gives a logged-out
visitor no hashtag search of its own, so `search_hashtags` reads about 24 videos of the general search and ranks
their hashtags, with no next page; its `result_videos` and `result_plays` count those videos only, not the totals
of TikTok, which `get_hashtag` gives. A sound is read by its id: the `id` of the `music` of a video, or the
number at the end of the address of a sound. `get_related_videos` gives one page with no cursor.
`get_trending_videos` gives the explore feed of TikTok for a logged-out visitor: no cursor, and a new set of
videos on each read of TikTok. `get_user_live` tells whether an account is live now; a live room is data, with no
stream URL. `get_video_transcript` gives the subtitles of a video; a video with no subtitles is a `not_found`
error and costs nothing. Search, the follower lists, sounds, reposts, playlists, related videos, trending videos,
live, transcripts and hashtag search are new, and their limits are not measured yet. See [What you can read](/docs/coverage).

## Notes [#notes]

- The server is stateless. Each request carries the key; there is no session to expire.
- A REST error (`not_found`, `no_credits`, `rate_limited`) comes back as a tool error with the same JSON body,
  so the agent can read the `code` and act on it.
- Results are the same flat `User`, `Video`, `Comment`, `Hashtag`, `MusicDetail`, `MusicSummary`, `Playlist`,
  `LiveRoom`, `Transcript` and `HashtagSummary` objects as the REST API, as JSON text.
- Keys are per account. Create one key per agent in the [dashboard](https://tikdataapi.com/dashboard) so you can
  revoke it alone.
