AI PM Knowledge Hub

Dify Knowledge MCP 接入指南

为团队 Agent (OpenCode / Codex / Claude Desktop / Cursor / Claude Code) 提供 Dify 知识库直接检索与沉淀能力。

一键复制 Agent 完整接入指引
直接粘贴给 Agent 即可自动完成 MCP 配置与 Skill 安装

选择对应 Agent 平台,复制包含完整 MCP 配置、Skill 安装及工具使用规范的自闭环指引:

授权凭证配置

服务端已自动预填当前部署的 Token。下方所有接入配置已实时注入该凭证,直接点击复制即可使用。

第一步:接入 Agent 客户端

添加到项目根目录 .opencode/opencode.json 或全局配置 ~/.config/opencode/opencode.json

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "dify-knowledge": {
      "type": "remote",
      "url": "https://dify-mcp.speedstarsunblocked.online/mcp",
      "enabled": true,
      "headers": {
        "Authorization": "Bearer 2143777e9c6e7dcde76c2a0efd1b48ec79d2126953877060d62bbbbe80ac50d2"
      }
    }
  }
}

添加到 Codex 配置文件 ~/.codex/config.toml 或工作区 MCP 配置中:

[mcp_servers.dify_knowledge]
url = "https://dify-mcp.speedstarsunblocked.online/mcp"
type = "http"
http_headers = { "Authorization" = "Bearer 2143777e9c6e7dcde76c2a0efd1b48ec79d2126953877060d62bbbbe80ac50d2" }

添加到 claude_desktop_config.json 中的 mcpServers

{
  "mcpServers": {
    "dify-knowledge": {
      "url": "https://dify-mcp.speedstarsunblocked.online/mcp",
      "headers": {
        "Authorization": "Bearer 2143777e9c6e7dcde76c2a0efd1b48ec79d2126953877060d62bbbbe80ac50d2"
      }
    }
  }
}

在 Cursor Settings > Features > MCP 中点击 Add New MCP Server (或写入 .cursor/mcp.json):

Name: dify-knowledge
Type: sse / remote / http
URL: https://dify-mcp.speedstarsunblocked.online/mcp
Headers: Authorization=Bearer 2143777e9c6e7dcde76c2a0efd1b48ec79d2126953877060d62bbbbe80ac50d2

直接在终端执行添加命令:

claude mcp add dify-knowledge https://dify-mcp.speedstarsunblocked.online/mcp --header "Authorization: Bearer 2143777e9c6e7dcde76c2a0efd1b48ec79d2126953877060d62bbbbe80ac50d2"
第二步:安装 Agent Skill

安装 Skill 后,Agent 会自动遵守团队知识库分类规则、文档命名与检索策略。

curl -fsSL https://dify-mcp.speedstarsunblocked.online/install.sh | bash
irm https://dify-mcp.speedstarsunblocked.online/install.ps1 | iex

保存到 ~/.config/opencode/skills/dify-knowledge/SKILL.md 或 Codex 的 rules 目录:

---
name: dify-knowledge
description: Use when recalling relevant architecture decisions, team handbook rules, business logic, or syncing/updating documents in the team's central Dify Knowledge base via remote MCP.
---

# Team Dify Knowledge Assistant

You are connected to the team's central Dify Knowledge base via remote MCP.

## Available MCP Tools

1. dify_knowledge_search
   - When to use: Before writing project code, before writing PRs, during debugging, or when researching team standards, ADRs, architecture decisions, and business rules.
   - Arguments:
     - datasetName: "team-handbook" or "project-tuantuanrent"
     - query: Semantic or keyword search query
     - searchMode (optional): "semantic_search" | "hybrid_search" | "keyword_search"
     - scoreThreshold (optional): e.g. 0.6
     - topK (optional): e.g. 5

2. dify_knowledge_upsert_document
   - When to use: When creating, updating, or syncing documentation (ADR, Architecture, API spec, Runbook, Release notes, Business logic) directly to Dify Knowledge.
   - Arguments:
     - actor: { id: string, type: "agent" | "human" }
     - datasetName: Target dataset ("team-handbook" or "project-tuantuanrent")
     - sourceId: Unique document key (e.g. "ARCH-PAYMENT-001", "ADR-005", "HANDBOOK-CODE-STYLE")
     - title: Document title
     - content: Complete Markdown body
     - metadata (optional): { document_type?: string, owner?: string, status?: string, ... }

3. dify_knowledge_list_documents
   - When to use: To explore what documents exist in a dataset.
   - Arguments: { datasetName: string, limit?: number }

4. dify_knowledge_get_document_status
   - When to use: Check indexing status of a document by sourceId.

5. dify_knowledge_health
   - When to use: Verify connection and dataset availability.

## Dataset Guidelines

- team-handbook: Team-wide engineering standards, code conventions, git workflows, onboarding rules. Document prefix HANDBOOK-*.
- project-tuantuanrent: Tuantuan Rent business rules, architecture, ADRs, database designs, runbooks.
  - ARCH-*: Architecture specifications
  - ADR-*: Architecture Decision Records
  - API-*: API contracts and external integration notes
  - RUNBOOK-*: Operational runbooks and troubleshooting guides
  - BIZ-*: Business logic and domain models
  - RELEASE-*: Release notes and changelog summaries

## Best Practices for Agent

- Search first: Before implementing complex features or refactoring, search existing decisions to avoid breaking constraints.
- Write back: After concluding an important technical design or resolving a tricky incident, proactively offer to document it to Dify Knowledge using dify_knowledge_upsert_document.
第三步:Agent 常用提示词
1. 开发前主动检索团队技术规范 / 架构决策
让 Agent 在编写代码或设计方案前,查询相关业务与技术背景:
请调用 dify_knowledge_search 搜索知识库中关于【支付与退款状态流转】的技术规范与 ADR 决策,并总结关键约束。
2. 功能完成后沉淀技术方案 / ADR 决策到知识库
让 Agent 将本次开发的设计或架构沉淀进 Dify 知识库:
请将我们刚才完成的【押金扣除风控机制】设计整理为标准 ADR 文档,调用 dify_knowledge_upsert_document 写入到 project-tuantuanrent 知识库,sourceId 为 "ADR-DEPOSIT-RISK-001"。
3. 列出数据集文档
查看某个知识库中已有沉淀的文档清单:
请调用 dify_knowledge_list_documents 列出 datasetName: "team-handbook" 和 "project-tuantuanrent" 的最新文档。
知识库与命名规范速查
常用数据集 (datasetName)
  • team-handbook: 团队通用规范、代码守则、Git/发布流程
  • project-tuantuanrent: 团团租业务逻辑、架构设计、技术决策
推荐 Document ID 前缀 (sourceId)
ARCH-* (架构设计) ADR-* (决策记录) API-* (接口约定) RUNBOOK-* (运维排障) BIZ-* (业务规则) RELEASE-* (发版说明)
已复制到剪贴板