Skip to main content
Glama
tokportal

tokportal-mcp

Official
by tokportal

tokportal

PyPI Python license

TokPortal 是托管式社交基础设施 API:由 16 个以上国家/地区的人类账户管理员创建、预热并运营的真实 TikTok、Instagram 和 YouTube 账户——以 REST API 和 MCP 服务器形式提供。无需每个账户的 OAuth,无每日 25 条帖子限制,无需应用审核。

文档 https://developers.tokportal.com · API 基础地址 https://app.tokportal.com/api/ext · OpenAPI https://developers.tokportal.com/openapi.json · MCP 远程 https://app.tokportal.com/api/ext/mcp · 获取 API 密钥 https://app.tokportal.com/developer/api-keys · llms.txt https://developers.tokportal.com/llms.txt


tokportal 是 TokPortal API 的官方 Python SDK(Python 3.9+,带类型注解,仅使用标准库)。每个公开操作都可以作为资源方法使用,或通过生成的 request_operation 映射调用。

安装

pip install tokportal

Related MCP server: tiktok-mcp

30 秒快速入门

import os
from tokportal import TokPortal

client = TokPortal(api_key=os.environ["TOKPORTAL_API_KEY"])

# 1. Create a bundle: a fresh managed TikTok account in the USA + 1 video slot.
#    Credits are debited now; the account manager is assigned at publish time.
bundle = client.bundles.create({
    "bundle_type": "account_and_videos",
    "platform": "tiktok",
    "country": "USA",
    "title": "US launch",
    "videos_quantity": 1,
})
bundle_id = bundle["data"]["id"]

# 2. Upload the video straight from disk -> public_url
upload = client.uploads.video_direct("./launch.mp4", bundle_id, content_type="video/mp4")

# 3. Configure the account profile and video slot 1, then publish
client.bundles.configure_account(bundle_id, {
    "username": "mybrand.us",
    "visible_name": "My Brand",
    "biography": "Official account",
})
client.bundles.configure_video(bundle_id, 1, {
    "video_type": "video",
    "video_url": upload["data"]["public_url"],
    "description": "Day 1 - launching in the US #launch",
    "target_publish_date": "2026-09-01",
})
client.bundles.publish(bundle_id)

# 4. Later (webhook `account.in_review` / `account.finalized`, or polling):
#    saved_account_id is the real delivered account -> read it back
current = client.bundles.get(bundle_id)["data"]
if current.get("saved_account_id"):
    account = client.accounts.get(current["saved_account_id"])["data"]
    print(account["username"], account["profile_url"])

方法名称遵循生成的资源映射(bundlesuploadsaccountsanalyticswebhooks)。如果某个操作没有对应的辅助方法,请使用 client.request_operation("<operationId>", path=..., query=..., body=...)

完整示例

import os
from tokportal import TokPortal, TokPortalApiError

client = TokPortal(api_key=os.environ["TOKPORTAL_API_KEY"])

me = client.me()

bundle = client.bundles.create({
    "bundle_type": "account_and_videos",
    "country": "USA",
    "videos_quantity": 5,
})

csv = client.analytics.export_videos(account=["saved-account-id"])
image = client.uploads.image_from_url({
    "url": "https://cdn.example.com/photo.jpg",
    "bundle_id": bundle["data"]["id"],
})

print(me["data"]["email"], bundle["data"], csv, image["data"])

直接的多部分上传使用相同的结构化错误和幂等性支持:

uploaded = client.uploads.video_direct(
    "./video.mp4",
    bundle["data"]["id"],
    content_type="video/mp4",
    idempotency_key="video-upload-123",
)

从最新的原子报价管理 TokPortal 覆盖范围。零信用额度报价同样有效,但仍需显式调用重新激活:

coverage = client.accounts.coverage("saved-account-id")
quote = coverage["data"]["reactivation_quote"]

if quote:
    client.accounts.reactivate_coverage(
        "saved-account-id",
        {
            "expected_credits": quote["credits"],
            "expected_current_period_end": quote["current_period_end"],
            "expected_lock_version": quote["lock_version"],
        },
        idempotency_key="coverage-reactivate-saved-account-id-v4",
    )

client.accounts.pause_coverage(
    "saved-account-id",
    idempotency_key="coverage-pause-saved-account-id-v4",
)

凭证揭示和验证码访问使用相同的不可逆两步策略流程。首次调用时若不接受,将收到 HTTP 428 和 error.details.policy_version;然后向账户所有者展示这些条款,并使用该确切版本重试。已接受的请求可能会扣除信用额度并永久解绑账户。这些包含机密的响应永远不会被存储以供重放,因此这些辅助方法有意不接受 idempotency_key。在传输结果不确定后,先协调安全的账户状态,再决定是否在不带密钥的情况下再次调用端点:

如果已接受的调用返回 HTTP 409 并带有 CREDENTIAL_REVEAL_QUOTE_CHANGED,则不会发生扣费或揭示操作。从 error.details 中读取当前策略和 expected_credit_cost,向所有者展示新条款,获取新的同意,然后使用新版本重试。切勿自动重试 409 错误。

try:
    client.accounts.reveal_credentials("saved-account-id")
except TokPortalApiError as error:
    if error.status_code != 428:
        raise

    policy_version = str(error.details["policy_version"])
    credentials = client.accounts.reveal_credentials(
        "saved-account-id",
        acceptance={
            "acknowledge_support_forfeit": True,
            "policy_version": policy_version,
        },
    )

同样的不可重放规则适用于 webhooks.createuploads.imageuploads.videoanalytics.create_report,因为它们会返回签名密钥、签名上传能力或报告访问令牌。这些辅助方法不接受 idempotency_key,而 request_operation 会在本地拒绝所有六个敏感操作 ID 的该参数。

无需降级到原始 HTTP 即可发现和操作 webhook:

catalog = client.webhooks.events()
endpoints = client.webhooks.list(event="bundle.published")
retry = client.webhooks.retry_delivery(endpoints["data"][0]["id"], "delivery-id")

每个 OpenAPI 操作也可以通过生成的操作映射访问:

same_retry = client.request_operation(
    "retryWebhookDelivery",
    path={"id": endpoints["data"][0]["id"], "delivery_id": "delivery-id"},
)

csv_again = client.request_operation(
    "exportAnalyticsVideos",
    query={"account": ["saved-account-id"]},
)

SDK 在 API 请求中发送 X-TokPortal-Client: tokportal-python/0.1.0,用于可观测性和支持诊断。

使用确切的原始请求体验证签名的 webhook 投递:

from tokportal import verify_webhook_signature

valid = verify_webhook_signature(
    raw_body,
    request.headers["TokPortal-Signature"],
    os.environ["TOKPORTAL_WEBHOOK_SECRET"],
)
from tokportal import TokPortalApiError

try:
    client.bundles.create({
        "bundle_type": "account_and_videos",
        "country": "USA",
        "videos_quantity": 5,
    })
except TokPortalApiError as error:
    print(error.status_code, error.code, error.details, error.request_id)
    if error.retryable:
        wait_seconds = error.retry_after_seconds or 1
        # Retry with backoff.
        pass
    print(error.rate_limit)

API 密钥采用 sk_ 后跟 64 个小写十六进制字符的格式。TokPortal 仅存储密钥的 SHA-256 哈希值,并在创建时显示一次原始密钥。

事实来源

本包是根据 TokPortal 公共 OpenAPI 模式(https://developers.tokportal.com/openapi.json)在私有 TokPortal 单体仓库中生成的。生成的文件(tokportal/_generated.py)会在每次发布时被覆盖——请勿手动编辑。关于我们接受的 PR 类型,请参阅 CONTRIBUTING.md;关于漏洞报告,请参阅 SECURITY.md

链接

MIT © TokPortal

Install Server
A
license - permissive license
B
quality
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    B
    quality
    -
    maintenance
    A comprehensive MCP server that enables AI assistants to search, download, and analyze TikTok content while also performing active tasks like publishing videos and interacting with posts. It provides full automation capabilities for TikTok through browser session management and anti-detection features.
    12
    2
  • F
    license
    B
    quality
    C
    maintenance
    MCP server for TikTok that enables searching videos, users, hashtags, and fetching trending content, user profiles, and video details via official API or public scraping.
    8
  • A
    license
    A
    quality
    B
    maintenance
    MCP server for TikTok that publishes videos to your own TikTok account and retrieves video performance metrics through TikTok's official Content Posting and Display APIs.
    6
    MIT
  • A
    license
    B
    quality
    B
    maintenance
    MCP server for TikTok that lets AI agents connect accounts, post and schedule videos, follow users, manage profiles, and analyze performance—all via QR login with no API keys.
    16
    1
    MIT

View all related MCP servers

Related MCP Connectors

  • Managed LinkedIn MCP server for AI agents: search, connect, message and enrich on accounts you own.

  • MCP server for Wan AI video generation

  • MCP server for ByteDance Seedance AI video generation

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/tokportal/tokportal-python'

If you have feedback or need assistance with the MCP directory API, please join our Discord server