Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Support Model Context Protocol (MCP) https://github.com/siyuan-note/siyuan/issues/13795

Danielaa1ed1ee81fb
diff --git a/kernel/server/serve.go b/kernel/server/serve.go
index cd15a92f8b..fa981d27ac 100644
--- a/kernel/server/serve.go
+++ b/kernel/server/serve.go
@@ -45,6 +45,7 @@ import (
"github.com/siyuan-note/siyuan/kernel/api"
"github.com/siyuan-note/siyuan/kernel/cmd"
"github.com/siyuan-note/siyuan/kernel/mcp"
+ mcpclient "github.com/siyuan-note/siyuan/kernel/mcp/client"
"github.com/siyuan-note/siyuan/kernel/model"
"github.com/siyuan-note/siyuan/kernel/server/proxy"
"github.com/siyuan-note/siyuan/kernel/util"
@@ -237,6 +238,12 @@ func Serve(fastMode bool, cookieKey string) {
go util.HookUILoaded()
+ // 启动后自动连接已配置的 MCP server,让用户首次使用 AI Agent 时工具已就绪。
+ // EnsureMCPConnected 是异步的,不阻塞 HTTP 监听;内置 mcpConnecting 标志防止重复连接。
+ if model.Conf.AI != nil && model.Conf.AI.MCP != nil {
+ go mcpclient.EnsureMCPConnected(model.Conf.AI.MCP.Servers)
+ }
+
go func() {
time.Sleep(1 * time.Second)
go proxy.InitFixedPortService(host, certPath, keyPath)