npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

dify-doc-mcp-server

v1.0.0

Published

MCP Server for Dify Knowledge Base integration

Readme

Dify Doc MCP Server

一个用于集成Dify知识库的MCP (Model Context Protocol) Server,允许AI助手直接访问和检索Dify知识库中的内容。

技术选型

  • 语言: TypeScript
  • 运行环境: Node.js v18+
  • MCP框架: @modelcontextprotocol/sdk
  • HTTP客户端: axios
  • 数据验证: zod
  • 传输方式: StdioServerTransport (标准输入输出)

主要架构

本项目实现了三个核心工具:

  1. dify_retrieve_knowledge - 知识库检索
  2. dify_list_datasets - 获取知识库列表
  3. dify_get_dataset_detail - 获取知识库详情

通过MCP协议与Dify REST API集成,支持语义检索、关键字检索、全文检索和混合检索等多种检索方式。

安装

全局安装

npm install -g dify-doc-mcp-server

或使用npx(无需安装)

npx dify-doc-mcp-server

快速开始

方式一:使用npx(推荐)

# 直接运行,无需安装
DIFY_BASE_URL="http://your-dify-host:8031" DIFY_API_KEY="your-api-key" npx dify-doc-mcp-server

方式二:本地开发

# 1. 克隆项目
git clone <repository-url>
cd difydocmcpserver

# 2. 安装依赖
npm install

# 3. 配置环境变量
export DIFY_BASE_URL="http://localhost:8031"
export DIFY_API_KEY="your-dify-api-key"

# 4. 构建和运行
npm run build
npm start

可用工具

dify_list_datasets

获取Dify知识库列表

  • keyword (可选): 搜索关键词
  • limit (可选): 返回条数 (1-100,默认20)

dify_get_dataset_detail

获取Dify知识库详细信息

  • dataset_id (必需): 知识库ID

dify_retrieve_knowledge

从Dify知识库中检索相关内容

  • dataset_id (必需): 知识库ID
  • query (必需): 检索查询内容
  • search_method (可选): 检索方法 (semantic_search/keyword_search/full_text_search/hybrid_search)
  • top_k (可选): 返回结果数量 (1-20,默认3)
  • score_threshold (可选): 相似度阈值 (0-1,默认0)

MCP客户端配置

{
  "mcpServers": {
    "dify-doc": {
      "command": "npx",
      "args": ["dify-doc-mcp-server"],
      "env": {
        "DIFY_BASE_URL": "http://your-dify-host:8031",
        "DIFY_API_KEY": "your-dify-api-key"
      }
    }
  }
}

API密钥获取

  1. 登录Dify控制台
  2. 进入"设置" → "知识库" → "API" → "API密钥"
  3. 创建新的API密钥
  4. 复制密钥并设置到环境变量中

测试

# 设置环境变量并运行测试
DIFY_BASE_URL="http://your-dify-host:8031" DIFY_API_KEY="your-api-key" DATASET="your-dataset-name" QUERY="引导" node test-mcp.js

测试脚本会验证:

  • MCP Server连接
  • 工具列表获取
  • 知识库列表、详情和检索功能

相关链接