ragflow知识mcp服务器
项目概况:
RAGFlow知识库的简单MCP服务器。
这个项目是一个基于Python的MCP(模型上下文协议)服务器,用于RAGFlow知识库。 它提供了一组与RAGFlow交互的工具,允许用户搜索知识、列出可用的知识库并检索有关特定知识库的信息。 服务器是使用 mcp 库,可以配置为使用 stdio 或 sse 为了运输。 服务器是通过YAML文件配置的(config.yaml)以及环境变量。
支持的RAGFlow版本: 0.17.2 ~ 0.19.0
另请参见 infiniflow/ragflow/blob/main/mcp/server/server.py
1.可用工具
1.动态知识库搜索工具
在中启用动态知识库搜索工具 config.yaml,另请参见 服务器配置:
datasets:
- dataset-id: 00000000000000000000000000000000
search-tool-name: search_xxx_knowledge
#search-tool-description: "Search knowledge about XXX(中文说明)."
#search-tool-result: simple
search-tool-description: "Search knowledge about XXX(中文说明). Results in JSON format, knowledge in the 'content' property."
search-tool-result: json2. list_knowledge_bases (默认禁用)
启用 list_knowledge_bases 工具在 config.yaml:
list-bases-enabled: true- 默认描述:
列出知识库。
- 输入属性:
- page,str:列出基础的页码,可选,默认为1。 - limit,str:要列出的知识库的最大数量,可选,默认为20。 - timeout,int:动态超时参数,由启用 timeout-param-enabled,可选,默认为60秒。
3. get_knowledge_base_info (默认禁用)
启用 get_knowledge_base_info 工具在 config.yaml:
get-base-enabled: true- 默认描述:
获取指定知识库ID的信息,结果包括知识库名称、描述和其他信息。
- 输入属性:
- knowledge_base_id,str:要查询的知识库的ID。 - timeout,int:动态超时参数,由启用 timeout-param-enabled,可选,默认为60秒。
2.安装并运行
2.1.使用pip安装
# Uninstall the previous version
pip uninstall --yes ragflow-knowledge-mcp-server
pip install ragflow-knowledge-mcp-server --upgrade --force-reinstall --extra-index-url http://127.0.0.1:8081/repository/pypi-group/simple --trusted-host 127.0.0.12.2.从源代码安装
cd /path/to/project
pip install .
# Or install using pytools.sh
./pytools.sh reinstall-system2.3.跑
export SIMP_LOGGER_LOG_FILE=/path/to/mcp.log
export SIMP_LOGGER_LOG_LEVEL=DEBUG
# This server can be run directly from the command line:
ragflow-knowledge-mcp-server --config=/path/to/config.yaml
# Alternatively, it can be run as a Python module:
python -m ragflow_knowledge_mcp_server --config=/path/to/config.yaml
# This server can also be run using `uv`:
uv run ragflow-knowledge-mcp-server --config=/path/to/config.yaml2.4.使用Docker或Docker Compose运行
- 码头工人
- 导出 EXTRA_INDEX_URL 环境变量,然后运行 要构建映像,请根据需要修改构建脚本或手动构建。 - 然后参考 运行容器。
- Docker Compose
- 修改 .env 文件。 - 修改 config.yaml 文件。 - 跑 要启动容器,请根据需要修改启动脚本或手动运行。
2.4.测试
# The project uses `pytest` for testing. To run the tests, first install the test dependencies:
python -m venv .venv
. .venv/bin/activate
uv sync --no-install-project --extra test
# Then run pytest:
pytest3.服务器配置
- 格式:
示例配置 yaml,有关完整配置,请参阅 MCPServer属性.py:
server-name: ragflow-knowledge-base
default-base-url: http://127.0.0.1:9388/api/v1
default-api-key: ragflow-00000000000000000000000000000000
timeout: 60
timeout-param-enabled: false
# SSE
transport: sse # Defaults to stdio
sse-port: 41106
list-bases-enabled: false
get-base-enabled: false
datasets:
- dataset-id: 00000000000000000000000000000000
search-tool-name: search_xxx_knowledge
search-tool-description: "Search knowledge about XXX(中文说明). Results in JSON format, knowledge in the 'content' property."
- enabled: false
id-param-enabled: true
search-tool-name: search_knowledge
search-tool-description: "Search knowledge from specified knowledge base('knowledge_base_id')."或者为每个数据集和工具配置基本URL和API密钥:
server-name: ragflow-knowledge-base
timeout: 60
timeout-param-enabled: false
# SSE
transport: sse # Defaults to stdio
sse-port: 41106
list-bases-enabled: false
list-bases-base-url: http://127.0.0.1:9388/api/v1
list-bases-api-key: ragflow-00000000000000000000000000000000
get-base-enabled: false
datasets:
- dataset-id: 00000000000000000000000000000000
base-url: http://127.0.0.1:9388/api/v1
api-key: ragflow-00000000000000000000000000000000
# Other properties...- 可用环境变量:
| Yaml | 环境变量名称 | 默认值 | 说明 |
|---|---|---|---|
RAGFLOW_KNOWLEDGE_MCP_SERVER_CONFIG | config.yaml | 配置文件路径,也可在CLI选项中使用 --config=/path/to/config.yaml. | |
default-base-url | DEFAULT_RAGFLOW_KNOWLEDGE_BASE_URL | - | 知识库的默认基本URL。 |
default-api-key | DEFAULT_RAGFLOW_KNOWLEDGE_API_KEY | - | 知识库的默认API键。 |
server-name | RAGFLOW_KNOWLEDGE_MCP_SERVER_NAME | RAGFlow知识库 | MCP服务器的名称。 |
transport | RAGFLOW_KNOWLEDGE_MCP_SERVER_TRANSPORT | stdio | 传输类型。可以是 stdio 或 sse. |
sse-transport-endpoint | RAGFLOW_KNOWLEDGE_MCP_SERVER_SSE_TRANSPORT_ENDPOINT | /messages/ | SSE传输端点。 |
sse-bind-host | RAGFLOW_KNOWLEDGE_MCP_SERVER_SSE_BIND_HOST | 0.0.0.0 | 绑定SSE传输的主机。 |
sse-port | RAGFLOW_KNOWLEDGE_MCP_SERVER_SSE_PORT | 41106 | 苏格兰和南方能源公司运输的港口。 |
sse-debug-enabled | RAGFLOW_KNOWLEDGE_MCP_SERVER_SSE_DEBUG_ENABLED | False | 是否为SSE启用调试模式。 |
timeout | RAGFLOW_KNOWLEDGE_MCP_SERVER_TIMEOUT | 60 | 服务器超时。 |
timeout-param-enabled | RAGFLOW_KNOWLEDGE_MCP_SERVER_TIMEOUT_PARAM_ENABLED | False | 是否启用超时参数。 |
timeout-param-description | RAGFLOW_KNOWLEDGE_MCP_SERVER_TIMEOUT_PARAM_DESCRIPTION | The total timeout for one calling, in seconds, optional, defaults to {self.timeout} seconds. | 超时参数的描述。 |
- 可用环境变量
simp-logger:
| 变量名称 | 默认值 | 说明 |
|---|---|---|
SIMP_LOGGER_LOG_FILE_ENABLED | True | 是否启用文件日志记录。 |
SIMP_LOGGER_LOG_CONSOLE_ENABLED | True | 是否启用控制台日志记录。 |
SIMP_LOGGER_LOG_LEVEL | 信息 | 日志级别。 |
SIMP_LOGGER_LOG_FILE | ~/logs/simp-logger.log | 日志文件路径。 |
SIMP_LOGGER_LOG_PATTERN | %(asctime)s %(levelname)s [%(threadName)s]: %(message)s | 日志模式。 |
SIMP_LOGGER_LOG_MAX_BYTES | 10485760(10MB) | 日志文件的最大大小。 |
SIMP_LOGGER_LOG_BACKUP_COUNT | 5 | 要保留的备份文件数。 |
SIMP_LOGGER_LOG_ROTATION_TYPE | size | 日志轮换的类型。可以是 size 或 time. |
SIMP_LOGGER_LOG_ROTATION_WHEN | 午夜 | 一天中轮换日志文件的时间。 |
SIMP_LOGGER_LOG_ROTATION_INTERVAL | 1 | 日志轮换的间隔。 |
SIMP_LOGGER_LOG_CLEANUP_DISABLED | False | 是否禁用记录器清理。 |
4.MCP配置
4.1.上海证券交易所
示例端点: http://127.0.0.1:41106/sse
4.2。标准
简单命令行:
uv run ragflow-knowledge-mcp-server --config=/path/to/config.yamlJSON:
{
"ragflow-knowledge-base": {
"type": "stdio",
"command": "uv",
"args": [
"run",
"ragflow-knowledge-mcp-server",
"--config=/path/to/config.yaml"
],
"env": {
"SIMP_LOGGER_LOG_CONSOLE_ENABLED": false,
"SIMP_LOGGER_LOG_FILE": "/path/to/mcp.log",
"SIMP_LOGGER_LOG_LEVEL": "DEBUG"
}
}
}YAML:
ragflow-knowledge-base:
type: stdio
command: uv
args:
- run
- ragflow-knowledge-mcp-server
- "--config=/path/to/config.yaml"
env:
SIMP_LOGGER_LOG_CONSOLE_ENABLED: false
SIMP_LOGGER_LOG_FILE: /path/to/mcp.log
SIMP_LOGGER_LOG_LEVEL: DEBUG5.开发惯例
- 该项目遵循标准的Python打包约定。
- 代码被组织成模块
src/ragflow_knowledge_mcp_server目录。 - 服务器逻辑在
server.py,配置属性在中定义properties/MCPServerProperties.py,并且用于与RAGFlow API交互的服务位于service目录。 - 该项目使用
setuptools用于建筑和setuptools_scm用于版本控制。 - 该项目使用
simp-logger用于日志记录,可以通过环境变量进行配置。
