Skip to main content

MCP 接入文档

通过 Model Context Protocol 把 Hanakoi 的角色 / 剧情 / 生成能力接入你的 Claude Code、Claude Desktop 或任意 MCP 客户端。

端点信息

MCP 端点在 API 域名上,不是站点域名。填成站点域名会得到 404 ——Claude 客户端会显示「Couldn't determine the server settings」, 看起来像服务端故障,其实只是域名填错了。

MCP Endpoint(JSON-RPC 2.0 over HTTP)

https://api.hanakoi.ai/api/v1/mcp

Protected Resource Metadata(RFC 9728)

https://api.hanakoi.ai/.well-known/oauth-protected-resource

Authorization Server Metadata(RFC 8414)

https://api.hanakoi.ai/.well-known/oauth-authorization-server

获取 API Key

打开 /admin/mcp → API Keys tab,点击「创建 API Key」。

key 以 hk_ 前缀开头, 创建后立即复制明文(仅显示一次,关闭弹窗后无法再次获取)。

客户端配置

Claude Code(CLI)

claude mcp add --transport http hanakoi https://api.hanakoi.ai/api/v1/mcp \ --header "Authorization: Bearer hk_YOUR_API_KEY"

Claude Desktop / 通用 mcpServers 配置

{ "mcpServers": { "hanakoi": { "type": "http", "url": "https://api.hanakoi.ai/api/v1/mcp", "headers": { "Authorization": "Bearer hk_YOUR_API_KEY" } } } }

Claude.ai(Custom Connector)

打开 Claude.ai → Settings → Connectors → Add custom connector,填入上方 MCP Endpoint URL。 Claude.ai 会通过 Protected Resource Metadata 自动发现 OAuth 流程。

一键授权(Claude.ai / Codex / Cursor 等支持 OAuth 的客户端)

  1. 在客户端添加上方 MCP Endpoint URL,点击「连接」或「进行身份验证」。
  2. 浏览器会打开 Hanakoi 网页授权页;未登录时先登录 Hanakoi,登录后自动回到授权页。
  3. 核对申请授权的应用名与「授权后返回」的地址,点击「允许」,浏览器回到客户端即完成连接;点「拒绝」则不授权。

不需要创建或粘贴 API Key。授权链接 10 分钟内有效且只能使用一次,过期后回到客户端重新连接即可。 无法在浏览器登录时,可在授权页点「改用 API Key 授权」,粘贴 API Key(hk_...)完成授权。

鉴权方式

MCP endpoint 同时支持两种 Bearer Token:

  • OAuth 2.1 access_token(JWT,1 小时有效,30 天 refresh) — Claude.ai / Codex / Cursor 等客户端点「连接」后走 OAuth 授权:浏览器打开 Hanakoi 网页授权页,登录后点「允许」即可,无需粘贴 API Key(Issue #3118)。推荐方式。
  • Hanakoi API Key(hk_... 前缀) — Claude Desktop / Claude Code / 脚本直连场景,直接放 Bearer header。

验证连通性

配置完成后,用 curl 直接调 initialize 验证 API Key 是否生效:

curl -X POST https://api.hanakoi.ai/api/v1/mcp \ -H "Authorization: Bearer hk_YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","id":1,"method":"initialize"}'

列出所有可用工具:

curl -X POST https://api.hanakoi.ai/api/v1/mcp \ -H "Authorization: Bearer hk_YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","id":2,"method":"tools/list"}'

角色创建与人工确认流程

角色资料、候选图、关系阶段头像和故事都保留人工确认节点;Agent 不应在用户确认前自动绑定图片或创建故事。

  1. 先询问用户文本语言偏好,再调用 list_mcp_skills({ category: "character" }) 查看适用的角色创作规范并用 get_mcp_skill 读取正文(例如角色命名规范),按规范生成不缺字段的完整角色资料与至少一条 opening_suggestions;生日 persona.birthday 为选填(MM-DD,只记月 / 日),用户提到或角色设定里有生日时一并填写;greeting 可自由书写,也可选用 *旁白* 格式区分旁白与对白,然后调用 create_character 创建无图角色文档。
  2. 创建成功后调用 get_character,把角色信息打印给用户审阅。
  3. 再用 generate_media 生成候选角色图,角色图一律优先使用 GPT-Image-2:纯文字生图用 openai_gpt_image_2_t2i,有参考图用 openai_gpt_image_2_i2i,只有用户明确点名其他模型时才换(并行创建多个角色时必须带 characterId,阶段图再带 purpose,服务端据此判定图片归属);任务完成后必须向用户展示图片或 URL,并等待用户明确确认,未确认不得绑定图片或生成关系阶段图。
  4. 用户不满意时先询问具体修改意见(风格、外观、服装、构图等)再重新生成;用户确认候选图后,在同一次 update_character(并行创建时带 expected_name 核对角色名)中把候选图 URL 写入 display_image_url、stage_avatars.acquaintance[0]、source_image_url;不在当前 R2_CDN_URL 下的图片会由服务端自动转存到 Hanakoi CDN,不需要先调用 upload_image。
  5. 以 source_image_url 为参考图,使用 image_to_image(模型 openai_gpt_image_2_i2i)分别生成 friend、flirty、lover、honeymoon 四个阶段各一张图;每张完成后展示结果,并用完整 stage_avatars 结构更新,支持按用户反馈换图。
  6. 全部角色字段与图片完成后再次调用 get_character,打印完整角色信息,并询问用户要修改字段、修改图片,还是添加故事或秘密篇章;未经用户同意不要自动创建故事或秘密篇章。
  7. 用户同意添加故事后,先调用 list_mcp_skills({ category: "story" }) 读取适用的故事创作规范,再讨论或提出故事方案,再使用 create_story_chapter 创建;完成后调用 list_story_chapters 打印故事信息,并询问用户是否需要修改故事的标题、正文、解锁条件、场景头或剧情节拍。
  8. 用户同意添加秘密篇章后,先按秘密篇章的定义(需要累积羁绊才能解锁的角色隐藏故事,写角色不轻易外露的一面,例如深埋心底的回忆、节日限定的甜蜜番外、关系里程碑触发的惊喜桥段)与用户讨论篇章方向,再确认篇章标题、正文、解锁所需的会话好感度(越私密门槛越高)与是否发布,再调用 upsert_secret_chapter 新增(不传 id);需要修改时先调用 list_secret_chapters 取得篇章 ID 与当前内容,再带 id 调用 upsert_secret_chapter;完成后调用 list_secret_chapters 打印篇章信息与审核状态。

平台创作规范(MCP Skill)与重名提示

Hanakoi 管理员在后台维护一组创作规范(MCP Skill),分为角色与故事两类,例如完整角色资料(含命名规范)、故事大纲、章节完整创作等。 Agent 生成角色字段或写故事前会先调用 list_mcp_skills 查看适用规范,再用 get_mcp_skill 读取正文并照着写; 规范更新后最多 60 秒生效,无需重新连接。

  • 想换一种风格时直接点名,例如「用西幻角色资料」「按悬疑向故事写」,Agent 会切换到对应规范。
  • 作用于整个工具的规范与只管某个字段的规范叠加使用,同一字段有冲突时以字段规范为准。
  • 起名后 Agent 会用 search_characters 查平台公开角色是否重名;重名只提示并给出备选,是否改名由你决定,不会阻止创建。
  • 规范只约束写法,内容审核、年龄分级与扣费规则照常生效。

工具语言

MCP 客户端里看到的工具标题、介绍与服务器说明支持简体中文和英语,默认简体中文。 登录后在「设置 → MCP」的「MCP 工具语言」里切换并保存。

  • 保存后需在 MCP 客户端里重新连接 Hanakoi,客户端才会重新拉取工具列表。
  • 只影响工具的说明文字;工具名、参数和返回结果不变,角色文本的语言仍按你在创建角色时的选择。

工具清单(21 个)

以下清单由后端 MCP 服务定义(TOOLS 数组)自动生成并保持同步,可直接在客户端里调用。

  • get_taskGet Task Status只读

    Read the status of an async task. status=2000 means success, 5xxx means failure, anything else is still in progress. The server waits up to about 25 seconds; when terminal=false, call again later instead of polling rapidly. Once the task finishes it returns all image, video or audio outputs.

    必填参数:id

  • get_model_paramsGet Model Parameters只读

    Read the basic and advanced parameter definitions of a model alias, such as aspect ratio, duration, frame count and size. Pass an alias id returned by list_model_aliases as modelId; use it before filling generate_media parameters to check the model's special input requirements.

    必填参数:modelId

  • list_model_aliasesList Model Aliases只读

    List the model_aliases single source of truth. Both the generate_media modelId and the get_model_params modelId must use an alias id returned here; choose by mcp_description, type, cost and maximum number of reference images rather than by list order.

  • list_charactersList Characters只读

    List the characters owned by the current user, returning character id, name, description, character images and status. Use it to confirm the character id before updating a character, writing chapters or binding generated images.

  • create_characterCreate Character Document有副作用 / 扣积分

    Create a complete character document with no missing fields and no images, without calling any media generation model. Before calling, you must ask the user for their language preference and record it in language; name, every text field in persona and the required opening_suggestions must use that language. greeting is free text and may optionally use *narration* to separate narration from dialogue; the server does not enforce a format. After it is created, show the character fields first, then call generate_media to generate candidate images and wait for the user to confirm; do not generate images before creating the character. display_image_url is a legacy-client compatibility field and the new flow should not fill it in this call; if it is filled with an image outside the current R2_CDN_URL, the server copies it to the Hanakoi CDN before creating the document, and the whole creation fails if the copy fails. Birthday persona.birthday is optional, format MM-DD (month and day only, 02-29 is valid), display only, and is not sent to the chat prompt. Characters created through MCP are always private: visibility can only be private, and public is rejected. character_id, user_id and counters are generated by the server. Before generating character fields, call list_mcp_skills({ category: "character" }) to see the applicable platform writing guides and read their body with get_mcp_skill; when several guides target the same thing use the one with is_default, and switch by title when the user names one. Guides that apply to a whole tool and guides that apply to a single field are combined; when they conflict on the same field, the field guide wins.

    必填参数:namepersonais_minoraudiencevisibilitycategory_idstagslanguage

  • update_characterUpdate Character Fields有副作用 / 扣积分

    Partially update the business fields of a character owned by the current user: only the fields you provide are overwritten, everything else stays unchanged. Supports persona, basic text, curation info, content rating, display image and stage avatars; greeting is free text and may optionally use *narration* to separate narration from dialogue, the server does not enforce a format. Birthday persona.birthday uses MM-DD; pass null or an empty string to clear it. The character id only locates the document; system fields such as user_id, status and counters cannot be changed. Character image URLs outside the current R2_CDN_URL are copied to the Hanakoi CDN before any write, so stored values are always CDN URLs; if a copy fails the whole update is rejected before any write, with no partial update. After the user first confirms a candidate image, write its URL into display_image_url, source_image_url and stage_avatars.acquaintance[0] in the same update_character call; every later stage image update must submit the complete stage_avatars structure including existing images. Read the character before updating text and keep its original language unless the user explicitly asks for a translation. Before generating character fields, call list_mcp_skills({ category: "character" }) to see the applicable platform writing guides and read their body with get_mcp_skill; when several guides target the same thing use the one with is_default, and switch by title when the user names one. Guides that apply to a whole tool and guides that apply to a single field are combined; when they conflict on the same field, the field guide wins.

    必填参数:id

  • create_story_chapterCreate Story Chapter有副作用 / 扣积分

    Create a story chapter for a character owned by the current user; this is the tool that generates and saves character stories, there is no separate generate_character_story. Title and body go through content moderation. You can set reading order, relationship stage threshold, unlock rule, composite conditions, scene header and story beats; a story beat can be marked track: side as a side promise the character makes (it must carry a promise in the character's voice), runs in parallel with the main line, is not penalized when missed, and only rewards story and relationship. The whole story must keep at least one free or gift-point chapter. Before writing an outline or chapter body, call list_mcp_skills({ category: "story" }) to see the applicable story writing guides and read their body with get_mcp_skill; when several guides target the same thing use the one with is_default, and switch by title when the user names one. Guides that apply to a whole tool and guides that apply to a single field are combined; when they conflict on the same field, the field guide wins.

    必填参数:characterIdtitlecontent

  • update_story_chapterUpdate Story Chapter有副作用 / 扣积分

    Partially update an existing story chapter; this is the tool for updating character stories, there is no separate update_character_story. Only the fields you provide are overwritten; pass condition: null to remove the composite gate; changing the title or body re-runs content moderation. Story beats also support track: side promises (with a promise in the character's voice, running in parallel with the main line and not penalized when missed). Before writing an outline or chapter body, call list_mcp_skills({ category: "story" }) to see the applicable story writing guides and read their body with get_mcp_skill; when several guides target the same thing use the one with is_default, and switch by title when the user names one. Guides that apply to a whole tool and guides that apply to a single field are combined; when they conflict on the same field, the field guide wins.

    必填参数:chapterId

  • list_story_chaptersList Story Chapters只读

    List all chapters of a character from the author's view, with full body, order and unlock conditions. Read the current values before editing a chapter so you can submit an accurate partial update.

    必填参数:characterId

  • delete_story_chapterDelete Story Chapter有副作用 / 扣积分

    Permanently delete one of your own story chapters; this cannot be undone. Chapters that readers have already unlocked cannot be deleted, and a deletion that would leave only paid chapters is rejected.

    必填参数:chapterId

  • get_characterGet Character Details只读

    Get the complete profile of a character owned by the current user by character id, including persona, curation info, content rating, display_image_url, source_image_url, reference_sheet_url and the five stage avatars. Call it after creating or updating a character, print the result for the user to review, then ask whether to change fields, change images or add a story.

    必填参数:id

  • list_creationsList Generation History只读

    List the current user's single-step generation records (generate_media and similar tasks) newest first, including model type, prompt, outputs and status, so finished images or videos can be reused. Music tasks are stored separately and are not listed here.

  • list_categoriesList Character Categories只读

    List the platform's active character categories and their category_id. Call this before setting category_ids when creating or updating a character; never guess category ids.

  • get_credit_balanceGet Credit Balance只读

    Read the current user's available Hanakoi credits and subscription info, from the same credit balance (credit_balances) that charging deducts from. Total available is daily_credit + subscription_credit + onetime_purchase_credit; check the balance before starting generation that costs credits.

  • upload_imageUpload Image有副作用 / 扣积分

    Copy a local base64 image or a remote image to Hanakoi public storage and return a stable URL under the current R2_CDN_URL. When an admin provides a reference image, call this tool first, then put the returned URL into generate_media.imageUrls for image-to-image. Image fields of the character document are copied automatically by create_character / update_character before writing, so you do not need this tool for them. Supports jpeg, png, webp and gif, up to 10MB per image.

  • generate_mediaGenerate Image, Video or Audio有副作用 / 扣积分

    Run one image, video or audio generation; this is also the only tool for character image generation and rerolls. Pick an alias with list_model_aliases first; for character images (candidates and relationship stage images) always prefer GPT-Image-2: openai_gpt_image_2_t2i for text-only images and openai_gpt_image_2_i2i with a reference image, and switch to another model only when the user explicitly asks for it; turn external reference images into stable URLs with upload_image first; use text_to_image for text-only images and image_to_image for stage avatars, putting the character's source_image_url into imageUrls. MiniMax music models (minimax_music_*) are not supported and cannot be used for songs or BGM. The task costs credits and is refunded automatically on failure; it returns a taskId, then use get_task to fetch the result. When candidate character images are ready you must show the images or URLs to the user and wait for explicit confirmation, never bind them automatically; if the user is not satisfied, first collect changes to style, appearance, outfit or composition before regenerating.

    必填参数:modelIdmodelType

  • list_mcp_skillsList Writing Guides只读

    Read-only, available to all users, costs no credits. Lists metadata of the enabled writing guides (MCP Skills) configured by platform admins: id, slug, category (character / story), title, when to use it, target tools and fields, default or not, and version; no body. Can be filtered by category, tool and field; guides that apply to a whole tool (no field set) apply to every field of that tool and are also returned when filtering by field. Call this before generating character fields or writing a story, then read the applicable guide body with get_mcp_skill; when several target the same thing prefer is_default, and switch by title when the user names one; whole-tool and field guides are combined, and the field guide wins on conflict.

  • get_mcp_skillRead Writing Guide只读

    Read-only, available to all users, costs no credits. Reads the body (Markdown) and version of an enabled writing guide by id or slug, and write according to it; returns MCP_SKILL_NOT_FOUND when it is disabled or does not exist. Guides only shape how you write; server-side content moderation, age rating and charging rules still apply.

  • search_charactersSearch Public Characters只读

    Read-only, available to all users, costs no credits. Search the platform's public characters by name or keyword, returning id, name, a one-line intro and whether it exactly matches the query name (exact_name_match, insensitive to Traditional / Simplified Chinese, full / half width and punctuation). Same rules as app search: hides adult characters based on the caller's age, filters characters the caller blocked, and does not write search history. Use it to check for duplicates after naming: on an exact match tell the user and offer alternatives, and let the user decide whether to rename; a duplicate name does not block creation.

    必填参数:q

  • list_secret_chaptersList Secret Chapters只读

    A secret chapter is a hidden character story that unlocks only after building up a bond (the bond is the session affinity between the user and the character in a given chat room). This tool lists, from the author's view, all secret chapters (including drafts) of characters owned by the current user, returning chapter id, publish status, title, body, image, unlock affinity, review status and rejection reason, and whether it is currently visible to users. Read existing chapters before adding one to avoid repeated themes and to plan rising unlock affinity; call this before editing a chapter to get its current values and id. Only the character owner can call it.

    必填参数:character_id

  • upsert_secret_chapterCreate or Update Secret Chapter有副作用 / 扣积分

    Definition: A secret chapter is a hidden character story that unlocks only after building up a bond. Creators shape the plot freely, so every character's chapters are different: a memory buried deep in the heart, a sweet holiday-only side story, or a surprise scene triggered by a relationship milestone. Each one shows a side the character rarely reveals. Time spent together brings you closer, and the more trust there is, the more the character is willing to share - slowly stepping into their own world is what makes it special. Writing requirements: the chapter shows a side the character rarely reveals, and the creator chooses the theme freely, for example a memory buried deep in the heart, a sweet holiday-only side story, or a surprise scene triggered only when the relationship reaches a milestone; the content must fit the character's existing persona, background and speaking style and use the character's text language, not a generic template or a plot summary. Unlocking: "building up a bond" means the user's session affinity with the character in a chat room reaches unlock_affinity, after which it unlocks in that chat room. The more trust, the more of their inner self the character is willing to share: the more private and personal the chapter, the higher unlock_affinity should be; set rising thresholds by privacy across a character's chapters instead of using the same value for all. Usage: omit id to create; pass an id returned by list_secret_chapters to update (the whole chapter is overwritten, title / body / image not passed are treated as empty, so read the current values first). publish_status=draft is a draft invisible to users; published publishes it, and then title (up to 30 characters), body (up to 700 characters) and unlock affinity (an integer from 0 to 9999, 0 = unlocked directly in any chat room) are required. image_url is optional and must be an https URL. Each character can have at most 50 chapters. When the character is public, published changes go to automatic review first and become visible to users only after approval; when the character is private they are saved directly (visible only to the author, clearing the previous review result), and each chapter is reviewed separately when the character is submitted for listing. Button copy can only be changed in the operations console. Do not create secret chapters automatically without the user agreeing; when done, call list_secret_chapters to show the result to the user.

    必填参数:character_idpublish_status

参考链接

© 2026 Hanakoi