Feature(Go): four local MCP read tools and a shared audit query package

Implement milestone M2 of the minimal MCP plan: the tools that answer from
the server's own state instead of opening a device channel.

- Extract the audit-log scanner from web into package auditquery so the
  admin page and get_audit_log share one implementation. The web handler
  keeps its 500-row cap, the MCP tool uses the protocol's 1000-row cap.
  Query gains json tags for the web snake_case wire format (device_id,
  warn_only) and reports TotalAll before filters.
- Add package buildinfo and inject Version/Commit with -X from build.ps1
  and the Makefile; go-winres refreshes Windows resources from the git tag
  when available. An unversioned build reports "", and only initialize
  substitutes "dev".
- list_hosts: online/offline pools, include_offline merge, every
  documented filter, limit/offset paging with total/totalAll/hasMore, and
  schema-named host fields (authStatus/tls/remark are never fabricated).
- get_host_detail: single id or a batch of up to 50, online lookup then
  the last history record, capabilities from protocol.SupportsCap plus the
  Windows/registry/virtual-desktop rules; v2 is not listed.
- get_server_status: version, uptime, online/offline counts, port and
  bind. sessions stays absent until the MCP session table lands in M3.
- get_audit_log: case-insensitive event substring, keyword, paging;
  hasMore turns false at the MaxOffset clamp so paging cannot loop.

Wire hub, history, audit path and listen address through mcp.Config from
cmd/main.go. Tests cover pools/filters/paging, capability bits, batch
failures, audit paging and the unversioned build.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-12 20:55:18 +01:00
1 parent 3f1957a9c9
commit 774c0d2545
16 files changed
+1952 -449

No files matched your search

+14 -3
View File
@@ -17,6 +17,7 @@ import (
"time"
"github.com/yuanyuanxiang/SimpleRemoter/server/go/auth"
"github.com/yuanyuanxiang/SimpleRemoter/server/go/buildinfo"
"github.com/yuanyuanxiang/SimpleRemoter/server/go/connection"
"github.com/yuanyuanxiang/SimpleRemoter/server/go/devicehistory"
"github.com/yuanyuanxiang/SimpleRemoter/server/go/hub"
@@ -1302,20 +1303,30 @@ func main() {
// MCP endpoint: a static bearer token independent of the web login. An
// empty YAMA_MCP_TOKEN leaves /mcp unregistered (404) — there is no
// auto-generated token, because a secret that only appears in a log is not
// a secret. Version wiring arrives with the buildinfo package; until then
// initialize reports "dev".
// a secret. Version/commit come from the link-time buildinfo injection.
mcpReadonly := envBool("YAMA_MCP_READONLY")
bindAddr := ""
if *httpPort != 0 {
bindAddr = "0.0.0.0" // web server listens on :port (all interfaces)
}
mcpSrv := mcp.New(mcp.Config{
Token: strings.TrimSpace(os.Getenv("YAMA_MCP_TOKEN")),
Readonly: mcpReadonly,
TermIdle: time.Duration(envInt("YAMA_MCP_TERM_IDLE", 180)) * time.Second,
MaxConcurrency: envInt("YAMA_MCP_MAX_CONCURRENCY", 16),
ReadMax: int64(envInt("YAMA_MCP_READ_MAX", 2<<20)),
Version: buildinfo.Version,
StartedAt: time.Now(),
Log: log.WithPrefix("MCP"),
Hub: deviceHub,
History: deviceHistory,
AuditPath: auditFile,
Port: *httpPort,
Bind: bindAddr,
})
if mcpSrv.Enabled() {
log.Info("MCP endpoint enabled on /mcp (readonly=%v)", mcpReadonly)
log.Info("MCP endpoint enabled on /mcp (readonly=%v, commit=%s)",
mcpReadonly, buildinfo.Commit)
}
// Start HTTP server for web UI. Hub gives it read-only access to the