@kealthas-dev/opencode-mcp-loki 1.0.9 → 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,13 +12,13 @@ A minimal MCP server exposing three read-only tools — `loki_query_range`, `lok
12
12
 
13
13
  ## Configuration
14
14
 
15
- Config is file-based, not env-var-based — same two-file split as `mcp-servers/oracle/` (see its README's Configuration section for the fullest writeup of the pattern), except unlike `mcp-servers/oracle/`, the Loki config file has a default location too:
15
+ Config is file-based, not env-var-based — same two-file split as `mcp-servers/oracle/` (see its README's Configuration section for the fullest writeup of the pattern). Unlike `mcp-servers/oracle/`'s older scheme, the *location* a config file is read from is never user-supplied here — only a short environment name is, which selects a fixed file. This is deliberate: an arbitrary-path env var invites a caller's shell not expanding `~`, a quoted value suppressing that expansion, or a typo'd relative path resolving against whatever `cwd` happens to be — all silently pointing at the wrong file. A bare name has none of that surface.
16
16
 
17
17
  - **`$HOME/.config/kealthas-dev/opencode-mcp-loki/server.json`** — the port to listen on, at this one fixed path always. Optional: if missing, defaults to `8091`; if present, must be valid JSON or the server refuses to start. Shape (see `server.example.json`):
18
18
  ```json
19
19
  { "LOKI_MCP_PORT": 8091 }
20
20
  ```
21
- - **A Loki config file, normally at `$HOME/.config/kealthas-dev/opencode-mcp-loki/config.json`** — that fixed path is the default (covers the common single-Loki-instance setup with nothing to set), but `LOKI_CONFIG_FILE` overrides it with any other path when set, for multiple environments — e.g. `configs/dev.json`, `configs/prod.json`, `configs/uat.json` alongside it, switched between with `LOKI_CONFIG_FILE=.../configs/prod.json`. The server prints a sample and exits if neither the default file nor an env-var-pointed file exists, or if `LOKI_BASE_URL` is missing from whichever one is read. Shape (see `config.example.json`):
21
+ - **A Loki config file.** With no `LOKI_CONFIG_ENV` set, it's read from `$HOME/.config/kealthas-dev/opencode-mcp-loki/config.json` — covers the common single-Loki-instance setup with nothing to configure. For multiple environments, set `LOKI_CONFIG_ENV` to a plain name (letters/digits/`-`/`_` only) and it reads `$HOME/.config/kealthas-dev/opencode-mcp-loki/configs/<name>.json` instead — e.g. `LOKI_CONFIG_ENV=prod` reads `configs/prod.json`. The server prints a sample and exits if the resolved file doesn't exist, if `LOKI_CONFIG_ENV` isn't a plain name, or if `LOKI_BASE_URL` is missing from whichever file is read. Shape (see `config.example.json`):
22
22
  ```json
23
23
  {
24
24
  "LOKI_BASE_URL": "http://192.168.1.100:3100",
@@ -36,15 +36,17 @@ Published as `@kealthas-dev/opencode-mcp-loki` — on a real deployment, install
36
36
 
37
37
  ```bash
38
38
  npm install -g @kealthas-dev/opencode-mcp-loki
39
- LOKI_CONFIG_FILE=~/.config/kealthas-dev/opencode-mcp-loki/configs/prod.json opencode-mcp-loki
39
+ mkdir -p ~/.config/kealthas-dev/opencode-mcp-loki/configs
40
+ # real config at ~/.config/kealthas-dev/opencode-mcp-loki/configs/prod.json (see config.example.json for the shape)
41
+ LOKI_CONFIG_ENV=prod opencode-mcp-loki
40
42
  ```
41
43
 
42
- For local dev/testing against this repo's own checkout (this directory, not the published package), point `LOKI_CONFIG_FILE` at a real config file (see `config.example.json` for the shape — the sandbox's docker-entrypoint.sh generates one automatically, see Testing below):
44
+ For local dev/testing against this repo's own checkout (this directory, not the published package), same idea — drop a real config file at the default location, or a named one under `configs/` (see `config.example.json` for the shape — the sandbox's docker-entrypoint.sh generates the default one automatically, see Testing below):
43
45
 
44
46
  ```bash
45
47
  npm install
46
48
  npm run build
47
- LOKI_CONFIG_FILE=/path/to/a/real/config.json npm start
49
+ npm start # reads ~/.config/kealthas-dev/opencode-mcp-loki/config.json
48
50
  ```
49
51
 
50
52
  `npm run dev` runs `src/server.ts` directly via `tsx watch` instead, for a compile-on-save loop.
@@ -60,7 +62,7 @@ docker compose -f docker/docker-compose.loki.yml up -d
60
62
  docker/dev.sh run --rm opencode-dev bash
61
63
  ```
62
64
 
63
- `LOKI_CONFIG_FILE` is already set inside that shell — `docker-entrypoint.sh` generates a config file from the sandbox's `LOKI_BASE_URL` compose env var and points `LOKI_CONFIG_FILE` at it. `cd mcp-servers/loki && npm install && npm run build && npm start`, then hit `http://localhost:8091/mcp` from an MCP client or `curl`.
65
+ The default config file is already in place inside that shell — `docker-entrypoint.sh` generates `~/.config/kealthas-dev/opencode-mcp-loki/config.json` from the sandbox's `LOKI_BASE_URL` compose env var. `cd mcp-servers/loki && npm install && npm run build && npm start`, then hit `http://localhost:8091/mcp` from an MCP client or `curl`.
64
66
 
65
67
  `loki.test.ts` (see `tests/README.md`) doesn't need this manual dance — it builds its own config files into a fake `$HOME` per spawned server (same pattern as `mcp-servers/oracle/oracle.test.ts`) and starts/stops its own `dist/server.js` process on its own port as part of the test run, seeding its own test log lines by pushing directly to Loki's push API (not through this MCP server, which is read-only by design).
66
68
 
package/dist/server.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import http from "node:http";
3
3
  import { existsSync, readFileSync } from "node:fs";
4
4
  import { homedir } from "node:os";
5
- import { join, resolve } from "node:path";
5
+ import { join } from "node:path";
6
6
  import { Server } from "@modelcontextprotocol/sdk/server/index.js";
7
7
  import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
8
8
  import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
@@ -45,27 +45,37 @@ function loadServerConfig() {
45
45
  process.exit(1);
46
46
  }
47
47
  }
48
- // Loki connection details are per-environment and read from whatever path
49
- // LOKI_CONFIG_FILE points at - unrestricted filename/location, so the same
50
- // install can be pointed at a different Loki instance just by changing this
51
- // one env var. LOKI_CONFIG_FILE itself is optional: if unset, this falls
52
- // back to config.json next to server.json in CONFIG_DIR, covering the
53
- // common single-environment case without requiring the env var on every
54
- // start - multi-environment setups still override it per deployment. Only
55
- // LOKI_BASE_URL is required - Loki is commonly reachable unauthenticated on
56
- // an internal LAN, unlike mcp-servers/oracle.
48
+ // Loki connection details are per-environment, but the *location* they're
49
+ // read from is never user-supplied - only a short env name is (e.g. "prod"),
50
+ // which selects a fixed file under CONFIG_DIR/configs/. This avoids the
51
+ // class of bug an arbitrary-path env var invites: a caller's shell not
52
+ // expanding "~", a quoted value suppressing that expansion, a typo'd
53
+ // relative path resolving against whatever cwd happens to be - all of
54
+ // which point path.resolve() somewhere unintended, silently. A bare name
55
+ // has none of that surface. No env var set falls back to config.json
56
+ // directly in CONFIG_DIR (not configs/) for the common single-environment
57
+ // case. Only LOKI_BASE_URL is required in the file itself - Loki is
58
+ // commonly reachable unauthenticated on an internal LAN, unlike
59
+ // mcp-servers/oracle.
57
60
  const DEFAULT_LOKI_CONFIG_PATH = join(CONFIG_DIR, "config.json");
61
+ const LOKI_CONFIGS_DIR = join(CONFIG_DIR, "configs");
62
+ const CONFIG_ENV_NAME_RE = /^[a-zA-Z0-9_-]+$/;
58
63
  function loadLokiConfig() {
59
- const envPath = process.env.LOKI_CONFIG_FILE;
60
- const resolvedPath = resolve(envPath ?? DEFAULT_LOKI_CONFIG_PATH);
64
+ const envName = process.env.LOKI_CONFIG_ENV;
65
+ if (envName !== undefined && !CONFIG_ENV_NAME_RE.test(envName)) {
66
+ console.error(`LOKI_CONFIG_ENV must be a plain name (letters, digits, "-", "_"), got: ${JSON.stringify(envName)}`);
67
+ process.exit(1);
68
+ }
69
+ const resolvedPath = envName ? join(LOKI_CONFIGS_DIR, `${envName}.json`) : DEFAULT_LOKI_CONFIG_PATH;
61
70
  if (!existsSync(resolvedPath)) {
62
- if (envPath) {
71
+ if (envName) {
63
72
  console.error(`Loki config file not found: ${resolvedPath}`);
73
+ console.error(`(LOKI_CONFIG_ENV=${envName} looks for "${envName}.json" under ${LOKI_CONFIGS_DIR})`);
64
74
  }
65
75
  else {
66
- console.error(`No LOKI_CONFIG_FILE set and no default config file at: ${resolvedPath}`);
67
- console.error("Either create that file, or point LOKI_CONFIG_FILE at one, e.g.:");
68
- console.error(" LOKI_CONFIG_FILE=~/.config/kealthas-dev/opencode-mcp-loki/configs/prod.json opencode-mcp-loki");
76
+ console.error(`No LOKI_CONFIG_ENV set and no default config file at: ${resolvedPath}`);
77
+ console.error(`Either create that file, or set LOKI_CONFIG_ENV to the name of a file under ${LOKI_CONFIGS_DIR}/, e.g.:`);
78
+ console.error(" LOKI_CONFIG_ENV=prod opencode-mcp-loki");
69
79
  }
70
80
  printSampleConfig("Loki config file", resolvedPath, SAMPLE_LOKI_CONFIG);
71
81
  process.exit(1);
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@kealthas-dev/opencode-mcp-loki",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "type": "module",
5
- "description": "MCP server exposing read-only Loki query/label tools - see README.md for design and the LOKI_CONFIG_FILE-driven config",
5
+ "description": "MCP server exposing read-only Loki query/label tools - see README.md for design and the config.json-driven config",
6
6
  "main": "dist/server.js",
7
7
  "bin": {
8
8
  "opencode-mcp-loki": "dist/server.js"