feat: 新增MCP Server功能,支持文档全局检索工具#1010
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds MCP (Model Context Protocol) Server functionality to MinDoc, enabling global document search capabilities. The implementation provides a streamable HTTP server that exposes document search tools for AI agents to query MinDoc's content repository.
Key changes:
- New MCP server package with authentication middleware and global search tools
- HTTP routing and filtering integration for MCP endpoints
- Go version upgrade from 1.18 to 1.23 to support mcp-go dependency
Reviewed Changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| routers/router.go | Adds MCP server routing with conditional enablement |
| routers/filter.go | Integrates MCP authentication middleware into request filtering |
| mcp/middleware.go | Implements API key authentication for MCP requests |
| mcp/mcp.go | Core MCP server setup and tool registration |
| mcp/handler.go | Global search tool implementation and request handling |
| go.mod | Updates Go version to 1.23 and adds mcp-go dependency |
| conf/app.conf.example | Adds MCP server configuration options |
| commands/daemon/daemon.go | Minor import formatting adjustment |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
mcp/handler.go
Outdated
| // GlobalSearchMcpHandler 全局搜索的mcp处理函数 | ||
| func GlobalSearchMcpHandler(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) { | ||
| paramMap := request.Params.Arguments.(map[string]any) | ||
| pageIndex, _ := paramMap["pageIndex"].(int) |
There was a problem hiding this comment.
Type assertion assumes pageIndex is an int, but the tool definition uses mcp.WithNumber which may provide a float64. This could cause the assertion to fail and default to 0. Use type assertion to float64 and convert to int, or handle the conversion properly.
| pageIndex, _ := paramMap["pageIndex"].(int) | |
| pageIndex := 1 | |
| if v, ok := paramMap["pageIndex"].(float64); ok { | |
| pageIndex = int(v) | |
| } |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
This reverts commit 71ba7b6.
* feat: i18n国际化语言支持完全可配置,并新增俄语支持 * feat: 新增MCP Server功能,支持文档全局检索工具
feat: 新增MCP Server功能,支持文档全局检索工具
由于依赖
mcp-go依赖对go版本最低要求为 go 1.23,因此go build的最低版本将被升级到 go 1.23已通过Dify v1.7.0版本进行自测试并验证通过:
其中,MCP配置为:
{ "mindoc": { "transport": "streamable_http", "url": "http://10.0.10.104:8181/mcp/?api_key=demo-mcp-api-key", "headers":{}, "timeout":600 } }对应的
app.conf配置为: