@kealthas-dev/opencode-mcp-loki 1.0.10 → 1.0.11
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 +15 -1
- package/dist/server.js +8 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,6 +30,18 @@ Config is file-based, not env-var-based — same two-file split as `mcp-servers/
|
|
|
30
30
|
```
|
|
31
31
|
Only `LOKI_BASE_URL` (no trailing path, e.g. `http://192.168.1.100:3100`) is required — Loki is commonly reachable unauthenticated on an internal LAN, unlike `mcp-servers/oracle/`. `LOKI_USERNAME`/`LOKI_PASSWORD` are HTTP basic auth; `LOKI_ORG_ID` sets `X-Scope-OrgID` for multi-tenant Loki / Grafana Cloud-style setups; `LOKI_DEFAULT_TZ_OFFSET` defaults to `+08:00` if omitted.
|
|
32
32
|
|
|
33
|
+
**When Loki has no directly reachable port of its own** — a common setup where Grafana is the only thing exposed and Loki sits behind it — set `LOKI_VIA_GRAFANA: true` and `LOKI_BASE_URL` becomes Grafana's own URL instead of Loki's. Every request routes through Grafana's datasource-proxy endpoint (`/api/datasources/proxy/<id>/loki/api/v1/...`) rather than hitting a Loki API root directly. `LOKI_USERNAME`/`LOKI_PASSWORD` still work unchanged in this mode — Basic Auth against a real Grafana user account, not Loki itself (Grafana's own default is `admin`/`admin` until changed). `LOKI_GRAFANA_DATASOURCE_ID` is the Loki datasource's ID as assigned inside that Grafana instance (visible in its Data Sources page URL) — optional, defaults to `"1"`, which is what a single-datasource Grafana instance almost always has:
|
|
34
|
+
```json
|
|
35
|
+
{
|
|
36
|
+
"LOKI_BASE_URL": "http://192.168.1.100:3100",
|
|
37
|
+
"LOKI_USERNAME": "admin",
|
|
38
|
+
"LOKI_PASSWORD": "admin",
|
|
39
|
+
"LOKI_VIA_GRAFANA": true,
|
|
40
|
+
"LOKI_GRAFANA_DATASOURCE_ID": "1"
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
A telltale sign you need this mode: querying with `LOKI_VIA_GRAFANA` unset returns an HTML page (often a 404) instead of a JSON error — real Loki's own error responses are always plain text/JSON, never HTML, so an HTML response means the request landed on Grafana's own web UI instead of Loki's API.
|
|
44
|
+
|
|
33
45
|
## Run
|
|
34
46
|
|
|
35
47
|
Published as `@kealthas-dev/opencode-mcp-loki` — on a real deployment, install it globally and run the resulting binary (see SETUP.md step 7):
|
|
@@ -68,4 +80,6 @@ The default config file is already in place inside that shell — `docker-entryp
|
|
|
68
80
|
|
|
69
81
|
## Status
|
|
70
82
|
|
|
71
|
-
**
|
|
83
|
+
**Direct-to-Loki path verified end-to-end and automated.** `loki.test.ts` covers tool listing, `loki_labels`/`loki_label_values` finding pushed test data, `loki_query_range` finding a pushed log line by content, an empty-result query returning cleanly (not an error), and a malformed LogQL query returning a clean error — driven over the real Streamable HTTP transport against the sandbox's `loki` service. Wired into `deploy/opencode.json.example` (`mcp.loki`, `type: "remote"`, `enabled: true`).
|
|
84
|
+
|
|
85
|
+
**`LOKI_VIA_GRAFANA` verified only against a fake stand-in HTTP server** (confirms the request lands on `/api/datasources/proxy/<id>/...` with the right Basic Auth header) — not against a real Grafana instance, and not covered by `loki.test.ts`. See `mcp-servers/TODO.md` for adding a real Grafana fixture to the sandbox.
|
package/dist/server.js
CHANGED
|
@@ -16,6 +16,8 @@ const SAMPLE_LOKI_CONFIG = {
|
|
|
16
16
|
LOKI_PASSWORD: "password (optional)",
|
|
17
17
|
LOKI_ORG_ID: "tenant-id (optional, multi-tenant Loki / Grafana Cloud-style setups)",
|
|
18
18
|
LOKI_DEFAULT_TZ_OFFSET: "+08:00 (optional, defaults to +08:00)",
|
|
19
|
+
LOKI_VIA_GRAFANA: "true (optional - set when Loki is only reachable through Grafana's own datasource proxy, not directly; LOKI_BASE_URL becomes Grafana's URL in that case)",
|
|
20
|
+
LOKI_GRAFANA_DATASOURCE_ID: "1 (optional, only used when LOKI_VIA_GRAFANA is true - defaults to 1)",
|
|
19
21
|
};
|
|
20
22
|
function printSampleConfig(label, path, sample) {
|
|
21
23
|
console.error(`\nExpected ${label} at: ${path}\n`);
|
|
@@ -91,6 +93,8 @@ function loadLokiConfig() {
|
|
|
91
93
|
LOKI_PASSWORD: raw.LOKI_PASSWORD,
|
|
92
94
|
LOKI_ORG_ID: raw.LOKI_ORG_ID,
|
|
93
95
|
LOKI_DEFAULT_TZ_OFFSET: raw.LOKI_DEFAULT_TZ_OFFSET,
|
|
96
|
+
LOKI_VIA_GRAFANA: raw.LOKI_VIA_GRAFANA === true,
|
|
97
|
+
LOKI_GRAFANA_DATASOURCE_ID: raw.LOKI_GRAFANA_DATASOURCE_ID !== undefined ? String(raw.LOKI_GRAFANA_DATASOURCE_ID) : "1",
|
|
94
98
|
};
|
|
95
99
|
}
|
|
96
100
|
catch (err) {
|
|
@@ -149,7 +153,10 @@ function resolveTimeParam(value) {
|
|
|
149
153
|
// executeQuery() returns in mcp-servers/oracle/src/server.ts, for the same reason:
|
|
150
154
|
// tool results should never surface as a raw MCP protocol error.
|
|
151
155
|
async function lokiFetch(path, params) {
|
|
152
|
-
const
|
|
156
|
+
const effectivePath = lokiConfig.LOKI_VIA_GRAFANA
|
|
157
|
+
? `/api/datasources/proxy/${lokiConfig.LOKI_GRAFANA_DATASOURCE_ID}${path}`
|
|
158
|
+
: path;
|
|
159
|
+
const url = new URL(effectivePath, lokiConfig.LOKI_BASE_URL);
|
|
153
160
|
for (const [key, value] of Object.entries(params ?? {})) {
|
|
154
161
|
if (value !== undefined && value !== null)
|
|
155
162
|
url.searchParams.set(key, String(value));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kealthas-dev/opencode-mcp-loki",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.11",
|
|
4
4
|
"type": "module",
|
|
5
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",
|