@kealthas-dev/opencode-mcp-loki 1.1.0 → 1.1.2
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/dist/server.js +30 -69
- package/package.json +3 -2
package/dist/server.js
CHANGED
|
@@ -3,9 +3,9 @@ import http from "node:http";
|
|
|
3
3
|
import { existsSync, readFileSync } from "node:fs";
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
5
|
import { join } from "node:path";
|
|
6
|
-
import {
|
|
6
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
7
7
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
8
|
-
import {
|
|
8
|
+
import { z } from "zod";
|
|
9
9
|
const DEFAULT_PORT = 8091; // the next free port after mcp-servers/oracle's 8090
|
|
10
10
|
const CONFIG_DIR = join(homedir(), ".config", "kealthas-dev", "opencode-mcp-loki");
|
|
11
11
|
const SERVER_CONFIG_PATH = join(CONFIG_DIR, "server.json");
|
|
@@ -192,73 +192,34 @@ function createMcpServer() {
|
|
|
192
192
|
`no timezone, e.g. "2026-09-15T10:00:00" or "2026-09-15 10:00:00" (assumed to be ${tzOffset}); ` +
|
|
193
193
|
`or an already-qualified absolute value (RFC3339 with an explicit offset, e.g. "2026-09-15T10:00:00+08:00", ` +
|
|
194
194
|
`or a unix epoch in seconds or nanoseconds).`;
|
|
195
|
-
const server = new
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
},
|
|
224
|
-
},
|
|
225
|
-
{
|
|
226
|
-
name: "loki_label_values",
|
|
227
|
-
description: "List the values seen for one label name, optionally restricted to a time range. Use this after loki_labels to find a concrete value to filter on.",
|
|
228
|
-
inputSchema: {
|
|
229
|
-
type: "object",
|
|
230
|
-
properties: {
|
|
231
|
-
label: { type: "string", description: "The label name to list values for, e.g. 'app' or 'namespace'." },
|
|
232
|
-
start: { type: "string", description: TIME_PARAM_DESCRIPTION + " Optional." },
|
|
233
|
-
end: { type: "string", description: TIME_PARAM_DESCRIPTION + " Optional." },
|
|
234
|
-
},
|
|
235
|
-
required: ["label"],
|
|
236
|
-
},
|
|
237
|
-
},
|
|
238
|
-
],
|
|
239
|
-
}));
|
|
240
|
-
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
241
|
-
const { name, arguments: args } = request.params;
|
|
242
|
-
let result;
|
|
243
|
-
switch (name) {
|
|
244
|
-
case "loki_query_range":
|
|
245
|
-
if (!args?.query)
|
|
246
|
-
return { content: [{ type: "text", text: "Missing required argument: query" }], isError: true };
|
|
247
|
-
result = await queryRange(args);
|
|
248
|
-
break;
|
|
249
|
-
case "loki_labels":
|
|
250
|
-
result = await listLabels((args ?? {}));
|
|
251
|
-
break;
|
|
252
|
-
case "loki_label_values":
|
|
253
|
-
if (!args?.label)
|
|
254
|
-
return { content: [{ type: "text", text: "Missing required argument: label" }], isError: true };
|
|
255
|
-
result = await listLabelValues(args);
|
|
256
|
-
break;
|
|
257
|
-
default:
|
|
258
|
-
return { content: [{ type: "text", text: `Unknown tool: ${name}` }], isError: true };
|
|
259
|
-
}
|
|
260
|
-
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
261
|
-
});
|
|
195
|
+
const server = new McpServer({ name: "loki-mcp", version: "1.0.0" });
|
|
196
|
+
const respond = (result) => ({ content: [{ type: "text", text: JSON.stringify(result, null, 2) }] });
|
|
197
|
+
server.registerTool("loki_query_range", {
|
|
198
|
+
description: "Run a LogQL query against the configured Loki instance over a time range and return matching log lines. Full passthrough - any valid LogQL expression, no restriction.",
|
|
199
|
+
inputSchema: {
|
|
200
|
+
query: z.string().describe("LogQL query, e.g. '{app=\"api\"} |= \"error\"'"),
|
|
201
|
+
start: z.string().optional().describe(TIME_PARAM_DESCRIPTION + " Optional - Loki defaults to a recent window."),
|
|
202
|
+
end: z.string().optional().describe(TIME_PARAM_DESCRIPTION + " Optional."),
|
|
203
|
+
limit: z.number().optional().describe("Max number of log lines to return. Optional - Loki defaults to 100."),
|
|
204
|
+
direction: z.enum(["forward", "backward"]).optional().describe("Optional - Loki defaults to backward (newest first)."),
|
|
205
|
+
step: z.string().optional().describe("Query resolution step for metric queries, e.g. '30s'. Optional."),
|
|
206
|
+
},
|
|
207
|
+
}, async (args) => respond(await queryRange(args)));
|
|
208
|
+
server.registerTool("loki_labels", {
|
|
209
|
+
description: "List the label names known to Loki, optionally restricted to a time range. Use this to discover what's queryable before writing a LogQL selector.",
|
|
210
|
+
inputSchema: {
|
|
211
|
+
start: z.string().optional().describe(TIME_PARAM_DESCRIPTION + " Optional."),
|
|
212
|
+
end: z.string().optional().describe(TIME_PARAM_DESCRIPTION + " Optional."),
|
|
213
|
+
},
|
|
214
|
+
}, async (args) => respond(await listLabels(args)));
|
|
215
|
+
server.registerTool("loki_label_values", {
|
|
216
|
+
description: "List the values seen for one label name, optionally restricted to a time range. Use this after loki_labels to find a concrete value to filter on.",
|
|
217
|
+
inputSchema: {
|
|
218
|
+
label: z.string().describe("The label name to list values for, e.g. 'app' or 'namespace'."),
|
|
219
|
+
start: z.string().optional().describe(TIME_PARAM_DESCRIPTION + " Optional."),
|
|
220
|
+
end: z.string().optional().describe(TIME_PARAM_DESCRIPTION + " Optional."),
|
|
221
|
+
},
|
|
222
|
+
}, async (args) => respond(await listLabelValues(args)));
|
|
262
223
|
return server;
|
|
263
224
|
}
|
|
264
225
|
// Stateless mode: fresh Server+transport pair per request, same shape and
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kealthas-dev/opencode-mcp-loki",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
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",
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"test": "tsx --test loki.test.ts"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@modelcontextprotocol/sdk": "^1.0.0"
|
|
28
|
+
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
29
|
+
"zod": "^3.25 || ^4.0"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@types/node": "^22.0.0",
|