Skip to content

feat: 新增统一适配 SDK 与 MCP/Dify 平台适配#388

Open
shifang0511 wants to merge 1 commit into
TencentCloud:mainfrom
shifang0511:feat/cross-platform-adapters
Open

feat: 新增统一适配 SDK 与 MCP/Dify 平台适配#388
shifang0511 wants to merge 1 commit into
TencentCloud:mainfrom
shifang0511:feat/cross-platform-adapters

Conversation

@shifang0511

@shifang0511 shifang0511 commented Jul 3, 2026

Copy link
Copy Markdown

概述

Resolves #235

本 PR 将现有 Gateway 边界抽象为一套统一适配 SDK,并基于这套 SDK 新增 MCP 与 Dify 两个平台适配,让“为新平台接入 TDAI Memory”变得更简单、更统一,部分平台可以做到主要依赖配置完成接入。

本次实现覆盖 issue 中的四档验收要求:架构说明、单平台读写适配、双平台适配与对比文档、统一适配 SDK。

验收标准对照

阶段 交付物
基础:架构图 + 数据流 docs/adapters/ARCHITECTURE.md:说明核心 TdaiCore 能力、现有适配器关系,以及 recall/capture 数据流图
进阶:一个平台的读写适配 src/adapters/mcp/:提供 MCP stdio server,暴露 tdai_memory_searchtdai_conversation_searchtdai_recalltdai_capture 等能力
深入:至少两个平台 + 对比文档 新增 src/adapters/dify/ Dify OpenAPI 自定义工具适配,并补充 docs/adapters/COMPARISON.md
拓展:统一适配 SDK 新增 src/sdk/docs/adapters/ADDING-A-PLATFORM.md,沉淀统一接口和新增平台接入指南

主要变更

src/sdk:统一适配 SDK

  • 新增 TdaiGatewayClient:为 Gateway 各接口提供类型化、无额外依赖的 HTTP client,支持超时、有限重试、Bearer 鉴权和类型化 TdaiGatewayError
  • 新增 MemoryAdapter 接口与 GatewayMemoryAdapter:统一抽象 recallsearchMemoriessearchConversationscaptureendSessionhealth 等能力。
  • 新增 buildMemoryTools():生成与宿主无关的工具描述,包括工具名、描述、JSON Schema 和非抛错式 invoke,可映射到 MCP、Dify、Vercel AI SDK、OpenAI functions 等平台。

src/adapters/mcp:MCP 平台适配

  • 新增基于 stdio 的 JSON-RPC 2.0 MCP server。
  • 暴露 TDAI Memory 的检索、会话检索、回忆和写入能力。
  • 提供 tdai-memory-mcp bin 入口和不同宿主的配置示例。
  • 支持关闭时等待进行中的请求完成,避免 stdio 响应被截断。

src/adapters/dify:Dify 平台适配

  • 新增 OpenAPI 3.0 schema,可直接作为 Dify 自定义工具导入。
  • 补充 agent tools 和 workflow 使用指南,覆盖基于 sys.conversation_id 的 recall/capture 流程。

docs/adapters:文档补充

  • 新增适配架构说明和数据流图。
  • 新增 OpenClaw、Hermes、MCP、Dify 的适配方式对比和选择建议。
  • 新增“如何新增一个平台”的接入指南,并提供示例。

测试验证

  • 新增 43 个测试,覆盖 SDK client 映射、重试、错误处理、工具参数转换、MCP 协议行为、stdio framing 和请求 drain 等流程。
  • 完整测试套件通过:110 个测试通过。
  • 已进行真实端到端验证:启动 Gateway 后通过 MCP server 写入一轮记忆,并在新的 tdai_conversation_search 进程中检索到对应内容,验证 MCP -> SDK -> Gateway -> Core 的完整读写链路。
  • TypeScript 在 strict + nodenext 配置下类型检查通过。
  • npm pack 已确认包含新增源码并排除测试文件,产物大小约 675 KB,低于 CI 的 2 MB 限制。

其他说明

  • 现有核心链路保持稳定:未修改 TdaiCore、Gateway、OpenClaw/Hermes 适配器。
  • 本次新增能力位于现有 HTTP 边界之上,便于后续继续扩展更多平台。
  • MCP、Dify、OpenClaw、Hermes 可共享同一个 Gateway 和同一个 memory store。

Resolve issue TencentCloud#235 (cross-platform adapters for the memory plugin) by
distilling the Gateway boundary into a reusable SDK and adding two new
platform integrations on top of it.

- src/sdk: TdaiGatewayClient (typed, retrying HTTP client), the MemoryAdapter
  interface + GatewayMemoryAdapter, and buildMemoryTools() neutral tool
  descriptors — the single interface a new platform implements/consumes.
- src/adapters/mcp: pure JSON-RPC 2.0 stdio MCP server exposing memory as
  tools; one server unlocks Claude Code, Codex, Cursor, and Cline.
  New bin: tdai-memory-mcp.
- src/adapters/dify: OpenAPI schema for Dify custom tools (declarative, no glue).
- docs/adapters: architecture + recall/capture data-flow diagrams, an
  OpenClaw/Hermes/MCP/Dify comparison, and an "add a platform in ~30 lines" guide.

Covers all four acceptance tiers (architecture → one platform → two platforms
+ comparison → unified SDK). 43 new tests; full suite 110 passing. Verified
end-to-end against a live Gateway: MCP capture then search round-trips real data.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@shifang0511 shifang0511 changed the title feat: unified adapter SDK + MCP and Dify platform adapters (#235) feat: 新增统一适配 SDK 与 MCP/Dify 平台适配 Jul 3, 2026
@Maxwell-Code07

Copy link
Copy Markdown
Collaborator

Thank you for submitting this PR and participating in Tencent Rhino-bird Open-source Training Program!
We have successfully received your submission. The program is currently in full swing, and we will complete the Code Review for you as soon as possible. Please keep an eye on the status notifications for this PR so you can follow up promptly once the review feedback is provided.
Thanks again for your contribution and open-source spirit! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cross-Platform Adapters for the Memory Plugin

2 participants