An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:sparkles: Support Model Context Protocol (MCP) https://github.com/siyuan-note/siyuan/issues/13795
Daniel186f0b4c13c7
diff --git a/kernel/mcp/tools/sync.go b/kernel/mcp/tools/sync.gonew file mode 100644index 0000000000..917d65c504--- /dev/null+++ b/kernel/mcp/tools/sync.go@@ -0,0 +1,81 @@+// SiYuan - Refactor your thinking+// Copyright (c) 2020-present, b3log.org+//+// This program is free software: you can redistribute it and/or modify+// it under the terms of the GNU Affero General Public License as published by+// the Free Software Foundation, either version 3 of the License, or+// (at your option) any later version.+//+// This program is distributed in the hope that it will be useful,+// but WITHOUT ANY WARRANTY; without even the implied warranty of+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+// GNU Affero General Public License for more details.+//+// You should have received a copy of the GNU Affero General Public License+// along with this program. If not, see <https://www.gnu.org/licenses/>.++package tools++import (+ "fmt"++ "github.com/siyuan-note/siyuan/kernel/model"+)++var SyncTool = &Tool{+ Name: "sync",+ Description: "Data sync operations for SiYuan.\n- perform: Trigger a full data sync (upload + download).\n- upload: Upload local data to cloud only.\n- download: Download cloud data to local only.\n- status: Get current sync status and configuration.",+ InputSchema: ToolSchema{+ Type: "object",+ Properties: map[string]Property{+ "action": {Type: "string", Description: "Operation", Enum: []string{"perform", "upload", "download", "status"}},+ },+ Required: []string{"action"},+ },+ Handler: syncHandler,+}++func init() {+ register(SyncTool)+}++func syncHandler(args map[string]interface{}) (CallToolResult, error) {+ action, _ := args["action"].(string)+ switch action {+ case "perform":+ return syncPerform(args)+ case "upload":+ return syncUpload(args)+ case "download":+ return syncDownload(args)+ case "status":+ return syncStatus(args)+ }+ return CallToolResult{+ Content: []ContentItem{{Type: "text", Text: "unknown action: " + action}},+ IsError: true,+ }, nil+}++func syncPerform(args map[string]interface{}) (CallToolResult, error) {+ model.SyncData(true)+ return CallToolResult{Content: []ContentItem{{Type: "text", Text: "sync done: " + model.Conf.Sync.Stat}}}, nil+}++func syncUpload(args map[string]interface{}) (CallToolResult, error) {+ model.SyncDataUpload()+ return CallToolResult{Content: []ContentItem{{Type: "text", Text: "sync upload done: " + model.Conf.Sync.Stat}}}, nil+}++func syncDownload(args map[string]interface{}) (CallToolResult, error) {+ model.SyncDataDownload()+ return CallToolResult{Content: []ContentItem{{Type: "text", Text: "sync download done: " + model.Conf.Sync.Stat}}}, nil+}++func syncStatus(args map[string]interface{}) (CallToolResult, error) {+ s := model.Conf.Sync+ return CallToolResult{Content: []ContentItem{{Type: "text", Text: fmt.Sprintf(+ "Sync Status:\n Enabled: %v\n Mode: %d (0/1=auto, 2=manual, 3=full-manual)\n Provider: %d\n Cloud: %s\n Perception: %v\n Interval: %ds\n Synced: %d\n Stat: %s",+ s.Enabled, s.Mode, s.Provider, s.CloudName, s.Perception, s.Interval, s.Synced, s.Stat,+ )}}}, nil+}