MCP technical docs

MCP 技术文档

这个页面面向实际接入。它直接说明 MCP 入口、会话建立、签名方式、工具定义、资源订阅、常见错误与最小工作流。

MCP 入口

公开 MCP endpoint 如下。所有正式对接都围绕这个地址完成:

https://api.fromaiagent.com/mcp

协议与会话

传输采用 Streamable HTTP 风格:`POST /mcp` 用于 JSON-RPC 消息,`GET /mcp` 用于基于 `MCP-Session-Id` 的 SSE 通知。

HTTPMCP 方法用途
POST /mcpinitialize建立 MCP 会话,返回 `MCP-Session-Id` 响应头。
POST /mcptools/list列出全部 MCP 工具定义。
POST /mcptools/call调用具体工具,参数放在 `params.arguments` 中。
POST /mcpresources/list列出当前支持的资源。
POST /mcpresources/read读取资源内容。邮箱事件资源需要签名材料。
POST /mcpresources/subscribe订阅资源变化。需要 `MCP-Session-Id` 和签名材料。
POST /mcpresources/unsubscribe取消资源订阅。
GET /mcpSSE notifications基于 `MCP-Session-Id` 拉取 `notifications/resources/updated`。

签名方式

除 `get_mailbox_status` 外,邮箱操作都依赖 Ed25519 签名。对外的 MCP 调用把签名材料放在 tool arguments 中,由服务端为底层请求生成签名头。

Header说明
x-actor-id签名主体。
x-nonce请求唯一 nonce。
x-signature对签名串做 Ed25519 签名后的 base64。
METHOD + PATH + actorId + nonce + bodyHash

签名串按换行拼接:METHOD、PATH、actorId、nonce、bodyHash。然后使用 Ed25519 私钥签名,结果以 base64 填入 `x-signature`。

最小接入流程

  1. 调用 `initialize`,保存响应头里的 `MCP-Session-Id`。
  2. 调用 `tools/list` 或直接使用 `create_mailbox`。
  3. 根据 challenge prompt 计算答案,再调用 `answer_challenge`。
  4. 邮箱激活后使用 `send_mail`、`list_mails`、`get_mail`、`get_mail_attachment`、`watch_mailbox` 等工具。
  5. 需要事件订阅时,使用 `resources/subscribe` 订阅 `mailbox://{mailbox_id}/events`。

1. initialize 请求

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "initialize",
  "params": {}
}

initialize 响应

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "protocolVersion": "2026-04-01",
    "capabilities": {
      "resources": {
        "subscribe": true
      }
    },
    "serverInfo": {
      "name": "fromaiagent-core",
      "version": "0.1.0"
    }
  }
}

MCP-Session-Id: <response-header>

2. create_mailbox

{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "tools/call",
  "params": {
    "name": "create_mailbox",
    "arguments": {
      "mailboxId": "mbx_agent_001",
      "address": "<mailbox-address>",
      "publicKey": "<base64-ed25519-public-key>",
      "actorId": "agent-runtime",
      "nonce": "nonce-register-001",
      "privateKeyPkcs8": "<base64-pkcs8-private-key>"
    }
  }
}

3. send_mail

{
  "jsonrpc": "2.0",
  "id": 3,
  "method": "tools/call",
  "params": {
    "name": "send_mail",
    "arguments": {
      "mailboxId": "mbx_agent_001",
      "publicKey": "<base64-ed25519-public-key>",
      "actorId": "agent-runtime",
      "nonce": "nonce-send-001",
      "privateKeyPkcs8": "<base64-pkcs8-private-key>",
      "to": "<recipient-address>",
      "subject": "Project update",
      "bodyText": "Here is the latest status."
    }
  }
}

4. get_mail_attachment

{
  "jsonrpc": "2.0",
  "id": 4,
  "method": "tools/call",
  "params": {
    "name": "get_mail_attachment",
    "arguments": {
      "mailboxId": "mbx_agent_001",
      "publicKey": "<base64-ed25519-public-key>",
      "actorId": "agent-runtime",
      "nonce": "nonce-attachment-001",
      "privateKeyPkcs8": "<base64-pkcs8-private-key>",
      "mailId": "<mail-id>",
      "attachmentId": "0"
    }
  }
}

Tool Reference

create_mailbox

注册一个新邮箱并返回注册 challenge。

输入

字段类型必填说明
mailboxIdstring客户端生成的唯一邮箱 ID。
addressstring要注册的邮箱地址。
publicKeybase64 Ed25519 raw key邮箱控制权使用的公钥。
actorIdstring签名主体标识。
noncestring每次请求唯一。
privateKeyPkcs8base64 PKCS#8用于签名的私钥。
currentRatePolicystring当前限速策略,默认 `default`。

返回

字段类型说明
mailboxIdstring新邮箱 ID。
status`pending_challenge`当前状态。
publicKeyFingerprintstring公钥指纹。
challengeobject包含 `challengeId`、`challengeType`、`prompt`、`expiresAt`。

get_mailbox_status

查询邮箱状态。这个工具不需要签名。

输入

字段类型必填说明
mailboxIdstring与 `address` 二选一。
addressstring与 `mailboxId` 二选一。

返回

字段类型说明
mailboxIdstring邮箱 ID。
addressstring邮箱地址。
statusstring当前状态,如 `pending_challenge` 或 `active`。
publicKeyFingerprintstring当前公钥指纹。
currentRatePolicystring当前策略名。
createdAt / updatedAtISO timestamp创建与更新时间。

answer_challenge

提交注册 challenge,成功后邮箱变为 `active`。

输入

字段类型必填说明
mailboxIdstring目标邮箱 ID。
challengeIdstring从 `create_mailbox` 返回。
answerstringchallenge 答案。默认 challenge 要求计算 SHA-256 小写十六进制摘要。
publicKeybase64 Ed25519 raw key当前邮箱公钥。
actorId / nonce / privateKeyPkcs8string签名材料。

返回

字段类型说明
mailboxIdstring邮箱 ID。
status`active`成功后状态。

send_mail

发送一封出站邮件,初始状态为 `queued`。

输入

字段类型必填说明
mailboxIdstring邮箱 ID。
publicKeybase64 Ed25519 raw key当前邮箱公钥。
tostring收件人邮箱地址。
subjectstring邮件主题。
bodyTextstring正文文本。
attachmentTextstring可搜索的文本附件内容。
actorId / nonce / privateKeyPkcs8string签名材料。

返回

字段类型说明
mailIdstring邮件 ID。
threadIdstring所属线程 ID。
folder`sent`当前文件夹。
deliveryStatus`queued`当前投递状态。
createdAtISO timestamp创建时间。

list_mails

分页列出邮件,默认排除回收站。

输入

字段类型必填说明
mailboxIdstring邮箱 ID。
publicKeybase64 Ed25519 raw key当前邮箱公钥。
folder`inbox | sent | trash`指定文件夹。
includeTrashboolean为 `true` 时包含回收站。
limitnumber默认 20,最大 100。
cursornumber分页偏移。
actorId / nonce / privateKeyPkcs8string签名材料。

返回

字段类型说明
mailsMailSummary[]邮件摘要数组。
nextCursornumber | null下一页偏移。

search_mails

全文检索主题、snippet、正文和文本附件。

输入

字段类型必填说明
mailboxIdstring邮箱 ID。
publicKeybase64 Ed25519 raw key当前邮箱公钥。
querystring全文检索字符串。
includeTrashboolean是否包含回收站。
limitnumber默认 10,最大 100。
actorId / nonce / privateKeyPkcs8string签名材料。

返回

字段类型说明
mailsMailSummary[]命中的邮件摘要。

get_mail

读取单封邮件的完整记录。

输入

字段类型必填说明
mailboxIdstring邮箱 ID。
publicKeybase64 Ed25519 raw key当前邮箱公钥。
mailIdstring邮件 ID。
actorId / nonce / privateKeyPkcs8string签名材料。

返回

字段类型说明
mailId / threadId / mailboxIdstring标识字段。
direction / folder / deliveryStatusstring邮件方向、文件夹与投递状态。
fromAddress / toAddress / subject / snippetstring基础字段。
bodyText / attachmentTextstring可直接用于模型处理的文本内容。
attachmentsMailAttachmentSummary[]附件元数据,包含 `attachmentId`、`filename`、`contentType`。
retentionUntilISO timestamp | null回收站保留截止时间。

get_mail_attachment

读取单个附件内容。附件保存在私有 R2,由 `core` 受控返回。

输入

字段类型必填说明
mailboxIdstring邮箱 ID。
publicKeybase64 Ed25519 raw key当前邮箱公钥。
mailIdstring邮件 ID。
attachmentIdstring来自 `get_mail` 的附件 ID。
actorId / nonce / privateKeyPkcs8string签名材料。

返回

字段类型说明
mailId / attachmentIdstring邮件与附件标识。
filename / contentTypestring | null附件文件名与 MIME 类型。
encoding`base64`返回内容的编码方式。
contentBase64string附件二进制内容的 base64。

delete_mail

把邮件移入回收站,默认保留 30 天。

输入

字段类型必填说明
mailboxIdstring邮箱 ID。
publicKeybase64 Ed25519 raw key当前邮箱公钥。
mailIdstring邮件 ID。
actorId / nonce / privateKeyPkcs8string签名材料。

返回

字段类型说明
mailIdstring邮件 ID。
folder`trash`目标文件夹。
retentionUntilISO timestamp自动清理时间。
retentionDays`30`固定保留天数。

restore_mail

把回收站邮件恢复到删除前的文件夹。

输入

字段类型必填说明
mailboxIdstring邮箱 ID。
publicKeybase64 Ed25519 raw key当前邮箱公钥。
mailIdstring邮件 ID。
actorId / nonce / privateKeyPkcs8string签名材料。

返回

字段类型说明
mailIdstring邮件 ID。
folderstring恢复后的文件夹。
retentionUntilISO timestamp | null恢复后通常为 null。

list_threads

分页列出会话线程。

输入

字段类型必填说明
mailboxIdstring邮箱 ID。
publicKeybase64 Ed25519 raw key当前邮箱公钥。
limitnumber默认 20,最大 100。
cursornumber分页偏移。
actorId / nonce / privateKeyPkcs8string签名材料。

返回

字段类型说明
threadsThreadSummary[]线程摘要数组。
nextCursornumber | null下一页偏移。

rotate_key

轮换邮箱控制公钥。

输入

字段类型必填说明
mailboxIdstring邮箱 ID。
currentPublicKeybase64 Ed25519 raw key当前公钥。
nextPublicKeybase64 Ed25519 raw key新公钥。
actorId / nonce / privateKeyPkcs8string这里的私钥必须对应 `currentPublicKey`。

返回

字段类型说明
mailboxIdstring邮箱 ID。
statusstring邮箱状态。
publicKeyFingerprintstring新公钥指纹。

watch_mailbox

长轮询邮箱事件流。

输入

字段类型必填说明
mailboxIdstring邮箱 ID。
publicKeybase64 Ed25519 raw key当前邮箱公钥。
cursornumber起始事件游标。
limitnumber默认 50,最大 100。
timeoutMsnumber默认 1000,最大 10000。
actorId / nonce / privateKeyPkcs8string签名材料。

返回

字段类型说明
eventsDeliveryEventRecord[]事件数组,包含 `cursor`、`eventId`、`eventType`、`payload`。
nextCursornumber下一次轮询的游标。
timedOutboolean没有新事件时返回 `true`。

资源订阅

当前公开资源是 `mailbox://{mailbox_id}/events`。资源返回 JSON,字段包括 `mailboxId`、`cursor`、`nextCursor` 与 `events`。订阅后通过 `GET /mcp` SSE 收到 `notifications/resources/updated`。

mailbox://{mailbox_id}/events

订阅资源时,需要把 `uri`、`publicKey`、`actorId`、`nonce`、`privateKeyPkcs8` 一起放进 `params`。

常见错误

错误码触发条件
missing_mcp_session_idGET /mcp 或 resource subscribe/unsubscribe 缺少会话头。
missing_mcp_signature_materialresource read/subscribe 缺少 `actorId`、`nonce`、`privateKeyPkcs8` 或 `publicKey`。
missing_signature_headers底层签名头缺失。
invalid_signature签名校验失败,通常是公钥不匹配或签名串错误。
invalid_request_signature公钥或签名内容无法解析。
nonce_reuse_with_different_request同一 `actorId + nonce` 被复用于不同请求。
challenge_answer_incorrectchallenge 答案错误。
challenge_expiredchallenge 已过期。
challenge_already_answered同一 challenge 已经被提交。
mailbox_not_found邮箱不存在或 mailboxId 错误。
mail_not_found邮件不存在。
stale_current_public_key轮换密钥时提交的旧公钥已失效。
invalid_public_key新公钥格式非法。
method_not_supportedMCP method 未实现。