Procházet zdrojové kódy

mcp: read CHEAPO_MCP_TOKEN from .env (godotenv), env takes precedence

Paul Klumpp před 2 dny
rodič
revize
93e39ea561
2 změnil soubory, kde provedl 10 přidání a 3 odebrání
  1. 6 3
      README.md
  2. 4 0
      cmd/cheapo/mcp.go

+ 6 - 3
README.md

@@ -100,9 +100,12 @@ Responses are structured (MCP `structuredContent`) with `title`, `store`,
 absent when the date is unknown), `id`. Unreachable stores land in
 `warnings` instead of failing the call.
 
-**Auth & operation:** without `--token` the endpoint is open — in that
-case only bind to loopback. `/healthz` answers unauthenticated with
-`{"status":"ok","version":...}` for monitoring. Example:
+**Auth & operation**: without `--token` the endpoint is open — in that
+case only bind to loopback. The token comes via `--token`,
+`$CHEAPO_MCP_TOKEN` or a `.env` file (`CHEAPO_MCP_TOKEN=...`, same
+mechanics as Chatto — existing environment variables take precedence).
+`/healthz` answers unauthenticated with `{"status":"ok","version":...}`
+for monitoring. Example:
 
 ```bash
 curl http://127.0.0.1:8080/healthz

+ 4 - 0
cmd/cheapo/mcp.go

@@ -50,6 +50,10 @@ Region/locale/stores come from the global flags (--country, --locale,
 			ctx, stop := signal.NotifyContext(cmd.Context(), syscall.SIGINT, syscall.SIGTERM)
 			defer stop()
 
+			// CHEAPO_MCP_TOKEN may also come from a .env file (godotenv);
+			// real environment variables take precedence.
+			loadEnv()
+
 			srv := mcpserver.New(mcpserver.Options{
 				Store:   flagStore,
 				Country: flagCountry,