I built an MCP server for TikTok — 10 tools in ~880 lines, and the bug I only found while writing this
说明与用途
为 TikTok 构建了一个包含 10 个工具的 MCP 服务器,但趋势工具因 API 路径过时和优雅回退而静默失败。通过更新端点、同步国家列表并添加每日对生产环境的契约测试来修复。发布现在通过 npm、Anthropic Registry 和 Glama 自动化。
问题
The MCP server’s trends tool silently failed due to API endpoint drift and a graceful fallback that hid the error, leading to stale or missing trend data for users.
结果
The MCP server now reliably fetches TikTok trends, with accurate API calls, synchronized country data, and a contract test that prevents silent failures. Publishing is automated across npm, Anthropic Registry, and Glama, ensuring the server is always up‑to‑date.
工作流
- 1. Identify the tool needing improvement (get_tiktok_trends_by_country).
- 2. Inspect the API call and note the outdated endpoint.
- 3. Update the endpoint to the current /api/trends?country=US&category=videos format.
- 4. Add a daily contract test that calls the live endpoint and verifies the response is not the fallback.
- 5. Synchronize the country enum with the site’s supported countries.
- 6. Rebuild and redeploy the MCP server.
- 7. Publish to npm, Anthropic Registry, and Glama using mcp-publisher.
- 8. Monitor logs for any fallback usage and adjust as needed.
证据
The tool was calling tiktapdown.com/api/trends/US. The web app's route is /api/trends?country=US&category=videos.
Add a contract test that hits production once a day and fails if any tool that touches the site returns its fallback.
The MCP tool doesn't know any of this. It gets the same JSON the site gets.
- 记录日期: 2026-09-21T20:00:32.449Z