mcpdoc 是一个用于加载和管理文档源的工具,支持通过多种方式配置文档服务器,能方便地查询文档信息。
通过以下命令启动文档服务器:
mcpdoc --urls LangGraph:https://langchain-ai.github.io/langgraph/llms.txt
此命令将加载并提供 LangGraph Python 文档。
启动服务器后,可以通过以下方式查询文档:
/mcp query "请列举所有支持的模型"
使用 pip 安装:
pip install mcpdoc
文档服务器支持多种配置方式,可以灵活地添加和管理文档源。
创建 sample_config.yaml
文件:
# Sample configuration for mcpdoc server
# Each entry must have a llms_txt URL and can optionally include a name
- name: LangGraph Python
llms_txt: https://langchain-ai.github.io/langgraph/llms.txt
启动服务器时指定 YAML 配置文件:
mcpdoc --yaml sample_config.yaml
创建 sample_config.json
文件:
[
{
"name": "LangGraph Python",
"llms_txt": "https://langchain-ai.github.io/langgraph/llms.txt"
}
]
启动服务器时指定 JSON 配置文件:
mcpdoc --json sample_config.json
可以通过 --urls
参数直接指定文档源的 URL,格式为 name:url
。例如:
mcpdoc --urls LangGraph:https://langchain-ai.github.io/langgraph/llms.txt --urls LangChain:https://python.langchain.com/llms.txt
可以将 YAML、JSON 配置文件和 --urls
参数组合使用:
mcpdoc --yaml sample_config.yaml --json sample_config.json --urls LangGraph:https://langchain-ai.github.io/langgraph/llms.txt --urls LangChain:https://python.langchain.com/llms.txt
--follow-redirects
:是否跟随 HTTP 重定向(默认为 False)--timeout SECONDS
:HTTP 请求超时时间,以秒为单位(默认为 10.0)示例:
mcpdoc --yaml sample_config.yaml --follow-redirects --timeout 15
from mcpdoc.main import create_server
# 创建服务器实例,指定文档源
server = create_server(
[
{
"name": "LangGraph Python",
"llms_txt": "https://langchain-ai.github.io/langgraph/llms.txt",
},
# 可以添加多个文档源
# {
# "name": "Another Documentation",
# "llms_txt": "https://example.com/llms.txt",
# },
],
follow_redirects=True,
timeout=15.0,
)
# 启动服务器
server.run(transport="stdio")