/** * 文档页(/docs,v2.7.0):MCP 与 Console API(/api/v1)的使用说明。 * 纯静态展示,接口地址按当前访问 origin 动态拼接;顶栏文档图标进入。 */ import { Alert, Card, Space, Table, Tag, Typography } from "antd"; import { KeyOutlined, ApiOutlined, CodeOutlined } from "@ant-design/icons"; /** # 成员变量: 接口基地址与 MCP 端点(跟随当前访问域名) **/ const API_BASE = `${window.location.origin}/api/v1`; const MCP_URL = `${window.location.origin}/api/v1/mcp`; /** # 成员变量: MCP 工具清单(与 /api/v1/mcp tools/list 一致) **/ const MCP_TOOLS = [ { name: "list_domains", params: "—", desc: "列出可用域名(创建邮箱的 domain_id 由此获取)" }, { name: "list_mailboxes", params: "—", desc: "列出所有邮箱(域名、catch-all 标记、保留秒数)" }, { name: "list_emails", params: "mailbox_id? / limit?", desc: "列出未过期邮件,limit 默认 20、最大 100" }, { name: "get_email", params: "id", desc: "单封邮件详情(正文 + 附件元数据);过期邮件报错" }, { name: "create_mailbox", params: "domain_id? / address / retention_seconds? / webhook?", desc: "创建邮箱;省略 domain_id 时随机分配一个已启用 Email Workers 的域名(address 须为本地部分)" }, { name: "delete_mailbox", params: "id", desc: "删除邮箱" }, ]; /** # 成员变量: REST API 端点清单(与 routes/apiv1.ts 一致) **/ const API_ENDPOINTS = [ { method: "GET", path: "/accounts", desc: "账号列表(不含已撤销)" }, { method: "GET", path: "/domains", desc: "域名列表" }, { method: "GET", path: "/mailboxes", desc: "邮箱列表" }, { method: "POST", path: "/mailboxes", desc: "创建邮箱,body: { address, domain_id?, retention_seconds?, webhook? };省略 domain_id 随机分配;409 已存在/无可用域名" }, { method: "DELETE", path: "/mailboxes/:id", desc: "删除邮箱" }, { method: "GET", path: "/emails", desc: "未过期邮件列表,query: mailbox_id? / limit / offset" }, { method: "GET", path: "/emails/:id", desc: "邮件详情 + 附件元数据;410 已过期" }, ]; /** # 函数 * 方法名 -> 彩色 Tag */ function MethodTag({ method }: { method: string }) { const color = method === "GET" ? "blue" : method === "POST" ? "green" : "red"; return {method}; } /** # 函数 * 文档页:认证说明 + MCP 接入(客户端配置、工具清单)+ REST API(端点清单、curl 示例) */ export function DocsPage() { return ( 认证 } > Console API 与 MCP 共用同一个 API/MCP Key(wmh_ 前缀):右上角头像 →{" "} 设置 → API / MCP Key 生成。明文仅在生成时显示一次;生成新 Key 后旧 Key 立即失效。 所有请求携带请求头:Authorization: Bearer wmh_xxxxxxxx MCP 接入(Model Context Protocol) } > 端点:{MCP_URL}(Streamable HTTP,JSON-RPC 2.0,协议版本 2025-06-18;仅接受 POST,无 SSE 流) MCP 客户端配置示例:
{`{
  "mcpServers": {
    "wmailhub": {
      "type": "http",
      "url": "${MCP_URL}",
      "headers": { "Authorization": "Bearer wmh_你的Key" }
    }
  }
}`}
{v} }, { title: "参数", dataIndex: "params", width: 260, render: (v: string) => {v} }, { title: "说明", dataIndex: "desc" }, ]} dataSource={MCP_TOOLS} /> REST API } > 基地址:{API_BASE}
, }, { title: "路径", dataIndex: "path", width: 220, render: (v: string) => {v}, }, { title: "说明", dataIndex: "desc" }, ]} dataSource={API_ENDPOINTS} /> curl 示例:
{`# 列出邮箱
curl -H "Authorization: Bearer wmh_你的Key" ${API_BASE}/mailboxes

# 创建邮箱(保留 7 天)
curl -X POST -H "Authorization: Bearer wmh_你的Key" \\
  -H "Content-Type: application/json" \\
  -d '{"domain_id":"dom_xxx","address":"hello","retention_seconds":604800}' \\
  ${API_BASE}/mailboxes

# 最新 10 封未过期邮件
curl -H "Authorization: Bearer wmh_你的Key" "${API_BASE}/emails?limit=10"`}
  • 邮件读取强制检查未过期:列表不返回过期邮件,详情对已过期邮件返回 410 Gone。
  • 邮箱保留时长默认 86400 秒(1 天);catch-all 邮箱地址形如 *@域名。
  • 常见状态码:401 未认证(Key 缺失或已失效)、404 资源不存在、409 邮箱已存在、410 邮件已过期。
  • } /> ); }