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:
1 parent
3f1957a9c9
commit
774c0d2545
16 files changed
+1952
-449
No files matched your search
+25
-5
@@ -11,6 +11,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/yuanyuanxiang/SimpleRemoter/server/go/devicehistory"
|
||||
"github.com/yuanyuanxiang/SimpleRemoter/server/go/hub"
|
||||
"github.com/yuanyuanxiang/SimpleRemoter/server/go/logger"
|
||||
)
|
||||
|
||||
@@ -39,6 +41,15 @@ type Config struct {
|
||||
Version string // serverInfo.version
|
||||
StartedAt time.Time // reported by get_server_status
|
||||
Log *logger.Logger
|
||||
|
||||
// Server-side state the local read tools answer from. A nil Hub means the
|
||||
// endpoint was built without a device registry: the host tools then fail
|
||||
// with -32000 instead of reporting an empty (and misleading) list.
|
||||
Hub *hub.Hub
|
||||
History *devicehistory.Store // nil: no offline history to merge
|
||||
AuditPath string // "" = audit file disabled (YAMA_AUDIT_LOG=off)
|
||||
Port int // web/MCP listening port, for get_server_status
|
||||
Bind string // listening address, for get_server_status
|
||||
}
|
||||
|
||||
// toolFunc implements one tools/call. It returns either a result value or a
|
||||
@@ -69,18 +80,21 @@ func New(cfg Config) *Server {
|
||||
if cfg.StartedAt.IsZero() {
|
||||
cfg.StartedAt = time.Now()
|
||||
}
|
||||
if cfg.Version == "" {
|
||||
cfg.Version = "dev"
|
||||
}
|
||||
// Version is left exactly as injected: it may be empty in a build without
|
||||
// git/ldflags. The initialize response substitutes "dev" for such builds;
|
||||
// get_server_status reports the empty string rather than inventing a
|
||||
// version (design §3.2).
|
||||
if cfg.Log == nil {
|
||||
cfg.Log = logger.New(logger.Config{Level: logger.LevelError})
|
||||
}
|
||||
return &Server{
|
||||
s := &Server{
|
||||
cfg: cfg,
|
||||
log: cfg.Log,
|
||||
tools: buildToolSet(toolsJSON),
|
||||
handlers: make(map[string]toolFunc),
|
||||
}
|
||||
s.registerLocalTools()
|
||||
return s
|
||||
}
|
||||
|
||||
// Enabled reports whether /mcp should be registered. An empty token disables
|
||||
@@ -203,10 +217,16 @@ type initializeResult struct {
|
||||
// serverInfo.name ("yama") so clients do not special-case the Go backend.
|
||||
// Differences are stated in instructions, which models read.
|
||||
func (s *Server) initializeResult() initializeResult {
|
||||
// "dev" is a serverInfo-only marker for an unversioned build; the status
|
||||
// tool keeps the raw (empty) value.
|
||||
version := s.cfg.Version
|
||||
if version == "" {
|
||||
version = "dev"
|
||||
}
|
||||
return initializeResult{
|
||||
ProtocolVersion: protocolVersion,
|
||||
Capabilities: serverCapabilities{Tools: toolsCapability{ListChanged: false}},
|
||||
ServerInfo: serverInfo{Name: "yama", Version: s.cfg.Version},
|
||||
ServerInfo: serverInfo{Name: "yama", Version: version},
|
||||
Instructions: serverInstructions,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user