@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 +8 -6
- package/dist/server.js +26 -16
- package/package.json +2 -2
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)
|
|
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,
|
|
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
|
-
|
|
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),
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
//
|
|
53
|
-
//
|
|
54
|
-
//
|
|
55
|
-
//
|
|
56
|
-
//
|
|
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
|
|
60
|
-
|
|
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 (
|
|
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
|
|
67
|
-
console.error(
|
|
68
|
-
console.error("
|
|
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.
|
|
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
|
|
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"
|