Feature(Go): MCP endpoint with bearer auth and tools/list
Add a stateless POST /mcp endpoint to the Go server, mounted by the web server and built from an environment-driven Config in cmd. The endpoint gates on YAMA_MCP_TOKEN: without it the route is not registered and /mcp 404s. Requests use a constant-time bearer compare, and transport failures stay transport failures (401 with a WWW-Authenticate challenge, 405 for anything but POST, 413 above 8 MiB, 204 for notifications). Everything after a parsed JSON-RPC request is HTTP 200, including -32600 for batch arrays and -32601 for unknown methods or tools. tools/list returns the nine minimal tools verbatim from an embedded copy of the canonical schemas. tools/mcp_tools/gen_go_tools.py extracts them from mcp/tools.json, preserving order and only the four published fields, and its --check mode detects drift. Readonly mode hides and refuses terminal_exec/terminal_close (-32006); tools that are listed but not implemented yet answer -32000 until their milestone lands. Also sync design §3.2 and the M2/M7/M8 plan text to tools.json, which is the sole schema contract: files not entries, line-based read_file, no since, camelCase capabilities, max_width [64,1920] defaulting to 1024, and outputSchema included in the M8 subset comparison. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
5f124fcb3a
commit
3f1957a9c9
11 files changed
+2022
-60
No files matched your search
+32
-1
@@ -22,6 +22,7 @@ import (
|
||||
"github.com/yuanyuanxiang/SimpleRemoter/server/go/hub"
|
||||
"github.com/yuanyuanxiang/SimpleRemoter/server/go/licensing"
|
||||
"github.com/yuanyuanxiang/SimpleRemoter/server/go/logger"
|
||||
"github.com/yuanyuanxiang/SimpleRemoter/server/go/mcp"
|
||||
"github.com/yuanyuanxiang/SimpleRemoter/server/go/protocol"
|
||||
"github.com/yuanyuanxiang/SimpleRemoter/server/go/server"
|
||||
"github.com/yuanyuanxiang/SimpleRemoter/server/go/web"
|
||||
@@ -880,6 +881,16 @@ func envInt(name string, def int) int {
|
||||
return n
|
||||
}
|
||||
|
||||
// envBool parses a boolean env var; accepts 1/true/yes/on (case-insensitive)
|
||||
// as true and everything else — including unset — as false.
|
||||
func envBool(name string) bool {
|
||||
switch strings.ToLower(strings.TrimSpace(os.Getenv(name))) {
|
||||
case "1", "true", "yes", "on":
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// runIssueToken handles the "issue-token" subcommand. It mints a customer JWT
|
||||
// signed with the operator's RSA private key and prints it to stdout.
|
||||
//
|
||||
@@ -1288,11 +1299,31 @@ func main() {
|
||||
SSO: ssoDetector,
|
||||
}
|
||||
|
||||
// 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".
|
||||
mcpReadonly := envBool("YAMA_MCP_READONLY")
|
||||
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)),
|
||||
StartedAt: time.Now(),
|
||||
Log: log.WithPrefix("MCP"),
|
||||
})
|
||||
if mcpSrv.Enabled() {
|
||||
log.Info("MCP endpoint enabled on /mcp (readonly=%v)", mcpReadonly)
|
||||
}
|
||||
|
||||
// Start HTTP server for web UI. Hub gives it read-only access to the
|
||||
// device registry; the authenticator owns user accounts and session tokens.
|
||||
httpSrv := web.New(*httpPort, log.WithPrefix("Web"), deviceHub, webAuth).
|
||||
WithDeviceHistory(deviceHistory).
|
||||
WithConfig(webCfg)
|
||||
WithConfig(webCfg).
|
||||
WithMCP(mcpSrv)
|
||||
if err := httpSrv.Start(); err != nil {
|
||||
log.Fatal("Failed to start HTTP server: %v", err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user