@kealthas-dev/opencode-mcp-loki 1.0.13 → 1.0.14

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.
Files changed (2) hide show
  1. package/dist/server.js +20 -34
  2. package/package.json +1 -1
package/dist/server.js CHANGED
@@ -53,6 +53,8 @@ function loadServerConfig() {
53
53
  }
54
54
  }
55
55
  // config.json by default, config-<name>.json when LOKI_CONFIG_ENV is set.
56
+ // Only LOKI_BASE_URL is required - Loki is commonly reachable unauthenticated
57
+ // on an internal LAN, unlike mcp-servers/oracle.
56
58
  function loadLokiConfig() {
57
59
  const envName = process.env.LOKI_CONFIG_ENV;
58
60
  const resolvedPath = join(CONFIG_DIR, envName ? `config-${envName}.json` : "config.json");
@@ -83,23 +85,15 @@ function loadLokiConfig() {
83
85
  }
84
86
  }
85
87
  const serverConfig = loadServerConfig();
86
- // Computing a correct start/end by hand (an exact RFC3339 offset, or -
87
- // worse - a 19-digit nanosecond epoch) is real friction for whatever's
88
- // calling this tool, model or human. This resolves three friendlier
89
- // forms into whatever Loki actually accepts, so most callers never have
90
- // to touch epoch math at all:
91
- // - "now" / "now-<duration>" (duration is <n><unit> pairs, unit one of
92
- // s/m/h/d, e.g. "now-1h", "now-30m", "now-1d") - the same relative-time
93
- // convention Grafana itself uses for Loki/Prometheus time ranges, not
94
- // an invented one.
95
- // - a bare "YYYY-MM-DDTHH:MM:SS" or "YYYY-MM-DD HH:MM:SS" with no
96
- // timezone - assumed to be in LOKI_DEFAULT_TZ_OFFSET and qualified
97
- // before being sent.
98
- // Anything else (already a full RFC3339 offset, or a bare epoch number)
99
- // passes straight through unchanged - both were already correct inputs
100
- // before this existed, and stay correct. An unrecognized shape also
101
- // passes straight through rather than being rejected here - Loki's own
102
- // parser is the final judge and returns its own clean error, same
88
+ // Hand-computing a correct start/end (an RFC3339 offset, or a 19-digit
89
+ // nanosecond epoch) is real friction, so this resolves two friendlier forms
90
+ // into what Loki accepts:
91
+ // - "now"/"now-<duration>" (s/m/h/d units, e.g. "now-1h") - Grafana's own
92
+ // relative-time convention, not an invented one.
93
+ // - a bare "YYYY-MM-DDTHH:MM:SS"/"YYYY-MM-DD HH:MM:SS" with no timezone -
94
+ // assumed to be LOKI_DEFAULT_TZ_OFFSET and qualified before sending.
95
+ // Anything else (already RFC3339, a bare epoch, or unrecognized) passes
96
+ // straight through - Loki's own parser is the final judge, same
103
97
  // full-passthrough philosophy as everywhere else in this server.
104
98
  const RELATIVE_TIME_RE = /^now(?:-((?:\d+[smhd])+))?$/;
105
99
  const DURATION_PART_RE = /(\d+)([smhd])/g;
@@ -121,14 +115,10 @@ function resolveTimeParam(value, tzOffset) {
121
115
  return `${naive[1]}T${naive[2]}${tzOffset}`;
122
116
  return value;
123
117
  }
124
- // Loki's query API (what every tool below hits) has no write side at all -
125
- // unlike Oracle there's no executeQuery()-style connection lifecycle or
126
- // auditQuery() gate to design around here. Every call is a plain,
127
- // stateless GET; this helper just centralizes URL-building, the optional
128
- // auth headers, and turning a non-2xx/network failure into a clean
129
- // {success: false} instead of a thrown error - mirroring the shape
130
- // executeQuery() returns in mcp-servers/oracle/src/server.ts, for the same reason:
131
- // tool results should never surface as a raw MCP protocol error.
118
+ // Loki's API is read-only, so unlike Oracle there's no connection lifecycle
119
+ // or audit gate here - just a stateless GET. Centralizes URL-building, auth
120
+ // headers, and turning a non-2xx/network failure into {success: false}
121
+ // rather than a thrown error, so tool results never surface as a raw MCP error.
132
122
  async function lokiFetch(path, params) {
133
123
  const lokiConfig = loadLokiConfig();
134
124
  const effectivePath = lokiConfig.LOKI_VIA_GRAFANA
@@ -147,10 +137,8 @@ async function lokiFetch(path, params) {
147
137
  headers["X-Scope-OrgID"] = lokiConfig.LOKI_ORG_ID;
148
138
  try {
149
139
  const response = await fetch(url, { headers });
150
- // Read as text first, not response.json() directly - Loki's error
151
- // responses aren't guaranteed to be the same JSON shape as its
152
- // success responses (sometimes plain text), so parsing is only safe
153
- // once response.ok is known.
140
+ // Text first, not response.json() - Loki's error responses aren't
141
+ // guaranteed the same JSON shape as success (sometimes plain text).
154
142
  const text = await response.text();
155
143
  if (!response.ok) {
156
144
  return { success: false, error: `Loki returned ${response.status}: ${text || response.statusText}` };
@@ -260,11 +248,9 @@ function createMcpServer() {
260
248
  });
261
249
  return server;
262
250
  }
263
- // Stateless mode (sessionIdGenerator: undefined) with a fresh Server +
264
- // transport pair per request - same shell as mcp-servers/oracle/src/server.ts, for the
265
- // same reason (the SDK's own reference stateless Streamable HTTP server;
266
- // no session state worth sharing between calls, and sharing one pair would
267
- // just mean concurrent requests fighting over the same transport).
251
+ // Stateless mode: fresh Server+transport pair per request, same shape and
252
+ // reason as oracle/src/server.ts - no session state to share, and reusing
253
+ // one pair would mean requests fighting over it.
268
254
  const httpServer = http.createServer(async (req, res) => {
269
255
  const url = new URL(req.url ?? "/", `http://${req.headers.host ?? "localhost"}`);
270
256
  if (url.pathname !== "/mcp") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kealthas-dev/opencode-mcp-loki",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
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",