Skip to content

Conversation

@nl8590687
Copy link
Contributor

@nl8590687 nl8590687 commented Aug 25, 2025

feat: 新增MCP Server功能,支持文档全局检索工具

由于依赖mcp-go依赖对go版本最低要求为 go 1.23,因此go build的最低版本将被升级到 go 1.23


已通过Dify v1.7.0版本进行自测试并验证通过:

  1. MCP服务对接验证
屏幕截图 2025-08-26 223605 屏幕截图 2025-08-26 223755
  1. MCP工具在AI Agent模式下调用能力测试
屏幕截图 2025-08-26 003642 屏幕截图 2025-08-26 003718
  1. MCP工具在AI Chatflow模式下调用能力测试
屏幕截图 2025-08-26 231647

其中,MCP配置为:

{
  "mindoc": {
    "transport": "streamable_http",
    "url": "http://10.0.10.104:8181/mcp/?api_key=demo-mcp-api-key",
    "headers":{},
    "timeout":600
  }
}

对应的app.conf配置为:

# MCP Server 功能
enable_mcp_server="${MINDOC_ENABLE_MCP_SERVER||true}"
mcp_api_key="${MINDOC_MCP_API_KEY||demo-mcp-api-key}"

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link

Copilot AI Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
pageIndex, _ := paramMap["pageIndex"].(int)
pageIndex := 1
if v, ok := paramMap["pageIndex"].(float64); ok {
pageIndex = int(v)
}

Copilot uses AI. Check for mistakes.
gsw945 and others added 2 commits September 22, 2025 17:26
@gsw945 gsw945 requested a review from Copilot September 22, 2025 09:33
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

gsw945
gsw945 previously approved these changes Sep 22, 2025
@gsw945 gsw945 merged commit df09353 into mindoc-org:master Sep 22, 2025
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants