@guckdev/mcp 0.1.0

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.
@@ -0,0 +1,2 @@
1
+ export { startMcpServer } from "./server.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { startMcpServer } from "./server.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const startMcpServer: () => Promise<void>;
2
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAgHA,eAAO,MAAM,cAAc,QAAa,QAAQ,IAAI,CA4GnD,CAAC"}
package/dist/server.js ADDED
@@ -0,0 +1,183 @@
1
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
2
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
+ import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
4
+ import { loadConfig, readCheckpoint, readSearch, readSessions, readStats, readTail, redactEvent, resolveStoreDir, } from "@guckdev/core";
5
+ const SEARCH_SCHEMA = {
6
+ type: "object",
7
+ additionalProperties: false,
8
+ properties: {
9
+ service: { type: "string" },
10
+ session_id: { type: "string" },
11
+ run_id: { type: "string" },
12
+ types: { type: "array", items: { type: "string" } },
13
+ levels: { type: "array", items: { type: "string" } },
14
+ contains: { type: "string" },
15
+ since: { type: "string" },
16
+ until: { type: "string" },
17
+ limit: { type: "number" },
18
+ backends: { type: "array", items: { type: "string" } },
19
+ config_path: { type: "string" },
20
+ },
21
+ };
22
+ const STATS_SCHEMA = {
23
+ type: "object",
24
+ additionalProperties: false,
25
+ properties: {
26
+ service: { type: "string" },
27
+ session_id: { type: "string" },
28
+ since: { type: "string" },
29
+ until: { type: "string" },
30
+ group_by: { type: "string", enum: ["type", "level", "stage"] },
31
+ limit: { type: "number" },
32
+ backends: { type: "array", items: { type: "string" } },
33
+ config_path: { type: "string" },
34
+ },
35
+ required: ["group_by"],
36
+ };
37
+ const SESSIONS_SCHEMA = {
38
+ type: "object",
39
+ additionalProperties: false,
40
+ properties: {
41
+ service: { type: "string" },
42
+ since: { type: "string" },
43
+ limit: { type: "number" },
44
+ backends: { type: "array", items: { type: "string" } },
45
+ config_path: { type: "string" },
46
+ },
47
+ };
48
+ const TAIL_SCHEMA = {
49
+ type: "object",
50
+ additionalProperties: false,
51
+ properties: {
52
+ service: { type: "string" },
53
+ session_id: { type: "string" },
54
+ run_id: { type: "string" },
55
+ limit: { type: "number" },
56
+ backends: { type: "array", items: { type: "string" } },
57
+ config_path: { type: "string" },
58
+ },
59
+ };
60
+ const buildText = (payload) => {
61
+ return {
62
+ content: [
63
+ {
64
+ type: "text",
65
+ text: JSON.stringify(payload, null, 2),
66
+ },
67
+ ],
68
+ };
69
+ };
70
+ const resolveSince = (input, config, storeDir) => {
71
+ const checkpointMs = readCheckpoint(storeDir);
72
+ if (input) {
73
+ if (input === "checkpoint") {
74
+ if (checkpointMs !== undefined) {
75
+ return new Date(checkpointMs).toISOString();
76
+ }
77
+ return `${config.mcp.default_lookback_ms}ms`;
78
+ }
79
+ return input;
80
+ }
81
+ if (checkpointMs !== undefined) {
82
+ return new Date(checkpointMs).toISOString();
83
+ }
84
+ return `${config.mcp.default_lookback_ms}ms`;
85
+ };
86
+ export const startMcpServer = async () => {
87
+ const server = new Server({
88
+ name: "guck",
89
+ version: "0.1.0",
90
+ }, {
91
+ capabilities: {
92
+ tools: {},
93
+ },
94
+ });
95
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
96
+ return {
97
+ tools: [
98
+ {
99
+ name: "guck.search",
100
+ description: "Search telemetry events with filters.",
101
+ inputSchema: SEARCH_SCHEMA,
102
+ },
103
+ {
104
+ name: "guck.stats",
105
+ description: "Aggregate telemetry counts by type/level/stage.",
106
+ inputSchema: STATS_SCHEMA,
107
+ },
108
+ {
109
+ name: "guck.sessions",
110
+ description: "List recent sessions and error counts.",
111
+ inputSchema: SESSIONS_SCHEMA,
112
+ },
113
+ {
114
+ name: "guck.tail",
115
+ description: "Return the most recent events (non-streaming).",
116
+ inputSchema: TAIL_SCHEMA,
117
+ },
118
+ ],
119
+ };
120
+ });
121
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
122
+ const args = (request.params.arguments ?? {});
123
+ const { config_path: configPath } = args;
124
+ const { config, rootDir } = loadConfig({ configPath });
125
+ if (!config.enabled) {
126
+ return buildText({
127
+ error: "Guck is disabled. Create .guck.json or set GUCK_ENABLED=true/GUCK_CONFIG_PATH.",
128
+ });
129
+ }
130
+ const storeDir = resolveStoreDir(config, rootDir);
131
+ if (request.params.name === "guck.search") {
132
+ const input = (request.params.arguments ?? {});
133
+ const { config_path: _configPath, ...filters } = input;
134
+ const withDefaults = {
135
+ ...filters,
136
+ since: resolveSince(filters.since, config, storeDir),
137
+ };
138
+ const result = await readSearch(config, rootDir, withDefaults);
139
+ const redacted = result.events.map((event) => redactEvent(config, event));
140
+ return buildText({ ...result, events: redacted });
141
+ }
142
+ if (request.params.name === "guck.stats") {
143
+ const input = (request.params.arguments ?? {});
144
+ const { config_path: _configPath, ...filters } = input;
145
+ const withDefaults = {
146
+ ...filters,
147
+ since: resolveSince(filters.since, config, storeDir),
148
+ };
149
+ const result = await readStats(config, rootDir, withDefaults);
150
+ return buildText(result);
151
+ }
152
+ if (request.params.name === "guck.sessions") {
153
+ const input = (request.params.arguments ?? {});
154
+ const { config_path: _configPath, ...filters } = input;
155
+ const withDefaults = {
156
+ ...filters,
157
+ since: resolveSince(filters.since, config, storeDir),
158
+ };
159
+ const result = await readSessions(config, rootDir, withDefaults);
160
+ return buildText(result);
161
+ }
162
+ if (request.params.name === "guck.tail") {
163
+ const input = (request.params.arguments ?? {});
164
+ const { config_path: _configPath, ...filters } = input;
165
+ const limit = input.limit ?? Math.min(config.mcp.max_results, 50);
166
+ const since = resolveSince(undefined, config, storeDir);
167
+ const result = await readTail(config, rootDir, {
168
+ service: filters.service,
169
+ session_id: filters.session_id,
170
+ run_id: filters.run_id,
171
+ limit,
172
+ backends: filters.backends,
173
+ since,
174
+ });
175
+ const redacted = result.events.map((event) => redactEvent(config, event));
176
+ return buildText({ ...result, events: redacted });
177
+ }
178
+ throw new Error(`Unknown tool: ${request.params.name}`);
179
+ });
180
+ const transport = new StdioServerTransport();
181
+ await server.connect(transport);
182
+ };
183
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAML,UAAU,EACV,cAAc,EACd,UAAU,EACV,YAAY,EACZ,SAAS,EACT,QAAQ,EACR,WAAW,EACX,eAAe,GAChB,MAAM,eAAe,CAAC;AACvB,MAAM,aAAa,GAAG;IACpB,IAAI,EAAE,QAAQ;IACd,oBAAoB,EAAE,KAAK;IAC3B,UAAU,EAAE;QACV,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC3B,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC9B,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC1B,KAAK,EAAE,EAAE,IAAI,EAAE,O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AE,EAAE,CAAC,CAAC;YAClE,MAAM,KAAK,GAAG,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;YACxD,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE;gBAC7C,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,UAAU,EAAE,OAAO,CAAC,UAAU;gBAC9B,MAAM,EAAE,OAAO,CAAC,MAAM;gBACtB,KAAK;gBACL,QAAQ,EAAE,OAAO,CAAC,QAAQ;gBAC1B,KAAK;aACN,CAAC,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;YAC1E,OAAO,SAAS,CAAC,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;QACpD,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,iBAAiB,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@guckdev/mcp",
3
+ "version": "0.1.0",
4
+ "description": "MCP server for Guck telemetry",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ }
12
+ },
13
+ "files": [
14
+ "dist",
15
+ "scripts",
16
+ "src",
17
+ "tsconfig.json"
18
+ ],
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "scripts": {
23
+ "build": "node scripts/ensure-deps.mjs && tsc -p tsconfig.json",
24
+ "build:watch": "tsc -p tsconfig.json --watch",
25
+ "prepare": "pnpm run build",
26
+ "test": "pnpm run build"
27
+ },
28
+ "engines": {
29
+ "node": ">=18"
30
+ },
31
+ "dependencies": {
32
+ "@modelcontextprotocol/sdk": "1.26.0",
33
+ "@guckdev/core": "workspace:*"
34
+ },
35
+ "devDependencies": {
36
+ "@types/node": "25.2.2"
37
+ }
38
+ }
@@ -0,0 +1,23 @@
1
+ import { existsSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { spawnSync } from "node:child_process";
4
+
5
+ const dep = { name: "@guckdev/core", entry: "dist/index.js" };
6
+
7
+ const npmExecPath = process.env.npm_execpath;
8
+ const run = (cwd, args) => {
9
+ const cmd = npmExecPath ? process.execPath : "pnpm";
10
+ const cmdArgs = npmExecPath ? [npmExecPath, ...args] : args;
11
+ const result = spawnSync(cmd, cmdArgs, { cwd, stdio: "inherit" });
12
+ if (result.status !== 0) {
13
+ process.exit(result.status ?? 1);
14
+ }
15
+ };
16
+
17
+ const depDir = path.join(process.cwd(), "node_modules", dep.name);
18
+ if (existsSync(depDir)) {
19
+ const entryPath = path.join(depDir, dep.entry);
20
+ if (!existsSync(entryPath)) {
21
+ run(depDir, ["run", "build"]);
22
+ }
23
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export { startMcpServer } from "./server.js";
package/src/server.ts ADDED
@@ -0,0 +1,221 @@
1
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
2
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
+ import {
4
+ CallToolRequestSchema,
5
+ ListToolsRequestSchema,
6
+ } from "@modelcontextprotocol/sdk/types.js";
7
+ import {
8
+ GuckConfig,
9
+ GuckSearchParams,
10
+ GuckSessionsParams,
11
+ GuckStatsParams,
12
+ GuckTailParams,
13
+ loadConfig,
14
+ readCheckpoint,
15
+ readSearch,
16
+ readSessions,
17
+ readStats,
18
+ readTail,
19
+ redactEvent,
20
+ resolveStoreDir,
21
+ } from "@guckdev/core";
22
+ const SEARCH_SCHEMA = {
23
+ type: "object",
24
+ additionalProperties: false,
25
+ properties: {
26
+ service: { type: "string" },
27
+ session_id: { type: "string" },
28
+ run_id: { type: "string" },
29
+ types: { type: "array", items: { type: "string" } },
30
+ levels: { type: "array", items: { type: "string" } },
31
+ contains: { type: "string" },
32
+ since: { type: "string" },
33
+ until: { type: "string" },
34
+ limit: { type: "number" },
35
+ backends: { type: "array", items: { type: "string" } },
36
+ config_path: { type: "string" },
37
+ },
38
+ } as const;
39
+
40
+ const STATS_SCHEMA = {
41
+ type: "object",
42
+ additionalProperties: false,
43
+ properties: {
44
+ service: { type: "string" },
45
+ session_id: { type: "string" },
46
+ since: { type: "string" },
47
+ until: { type: "string" },
48
+ group_by: { type: "string", enum: ["type", "level", "stage"] },
49
+ limit: { type: "number" },
50
+ backends: { type: "array", items: { type: "string" } },
51
+ config_path: { type: "string" },
52
+ },
53
+ required: ["group_by"],
54
+ } as const;
55
+
56
+ const SESSIONS_SCHEMA = {
57
+ type: "object",
58
+ additionalProperties: false,
59
+ properties: {
60
+ service: { type: "string" },
61
+ since: { type: "string" },
62
+ limit: { type: "number" },
63
+ backends: { type: "array", items: { type: "string" } },
64
+ config_path: { type: "string" },
65
+ },
66
+ } as const;
67
+
68
+ const TAIL_SCHEMA = {
69
+ type: "object",
70
+ additionalProperties: false,
71
+ properties: {
72
+ service: { type: "string" },
73
+ session_id: { type: "string" },
74
+ run_id: { type: "string" },
75
+ limit: { type: "number" },
76
+ backends: { type: "array", items: { type: "string" } },
77
+ config_path: { type: "string" },
78
+ },
79
+ } as const;
80
+
81
+ const buildText = (payload: unknown) => {
82
+ return {
83
+ content: [
84
+ {
85
+ type: "text",
86
+ text: JSON.stringify(payload, null, 2),
87
+ },
88
+ ],
89
+ };
90
+ };
91
+
92
+ const resolveSince = (
93
+ input: string | undefined,
94
+ config: GuckConfig,
95
+ storeDir: string,
96
+ ): string => {
97
+ const checkpointMs = readCheckpoint(storeDir);
98
+ if (input) {
99
+ if (input === "checkpoint") {
100
+ if (checkpointMs !== undefined) {
101
+ return new Date(checkpointMs).toISOString();
102
+ }
103
+ return `${config.mcp.default_lookback_ms}ms`;
104
+ }
105
+ return input;
106
+ }
107
+ if (checkpointMs !== undefined) {
108
+ return new Date(checkpointMs).toISOString();
109
+ }
110
+ return `${config.mcp.default_lookback_ms}ms`;
111
+ };
112
+
113
+ export const startMcpServer = async (): Promise<void> => {
114
+ const server = new Server(
115
+ {
116
+ name: "guck",
117
+ version: "0.1.0",
118
+ },
119
+ {
120
+ capabilities: {
121
+ tools: {},
122
+ },
123
+ },
124
+ );
125
+
126
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
127
+ return {
128
+ tools: [
129
+ {
130
+ name: "guck.search",
131
+ description: "Search telemetry events with filters.",
132
+ inputSchema: SEARCH_SCHEMA,
133
+ },
134
+ {
135
+ name: "guck.stats",
136
+ description: "Aggregate telemetry counts by type/level/stage.",
137
+ inputSchema: STATS_SCHEMA,
138
+ },
139
+ {
140
+ name: "guck.sessions",
141
+ description: "List recent sessions and error counts.",
142
+ inputSchema: SESSIONS_SCHEMA,
143
+ },
144
+ {
145
+ name: "guck.tail",
146
+ description: "Return the most recent events (non-streaming).",
147
+ inputSchema: TAIL_SCHEMA,
148
+ },
149
+ ],
150
+ };
151
+ });
152
+
153
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
154
+ const args = (request.params.arguments ?? {}) as { config_path?: string };
155
+ const { config_path: configPath } = args;
156
+ const { config, rootDir } = loadConfig({ configPath });
157
+ if (!config.enabled) {
158
+ return buildText({
159
+ error:
160
+ "Guck is disabled. Create .guck.json or set GUCK_ENABLED=true/GUCK_CONFIG_PATH.",
161
+ });
162
+ }
163
+ const storeDir = resolveStoreDir(config, rootDir);
164
+
165
+ if (request.params.name === "guck.search") {
166
+ const input = (request.params.arguments ?? {}) as GuckSearchParams;
167
+ const { config_path: _configPath, ...filters } = input;
168
+ const withDefaults: GuckSearchParams = {
169
+ ...filters,
170
+ since: resolveSince(filters.since, config, storeDir),
171
+ };
172
+ const result = await readSearch(config, rootDir, withDefaults);
173
+ const redacted = result.events.map((event) => redactEvent(config, event));
174
+ return buildText({ ...result, events: redacted });
175
+ }
176
+
177
+ if (request.params.name === "guck.stats") {
178
+ const input = (request.params.arguments ?? {}) as GuckStatsParams;
179
+ const { config_path: _configPath, ...filters } = input;
180
+ const withDefaults: GuckStatsParams = {
181
+ ...filters,
182
+ since: resolveSince(filters.since, config, storeDir),
183
+ };
184
+ const result = await readStats(config, rootDir, withDefaults);
185
+ return buildText(result);
186
+ }
187
+
188
+ if (request.params.name === "guck.sessions") {
189
+ const input = (request.params.arguments ?? {}) as GuckSessionsParams;
190
+ const { config_path: _configPath, ...filters } = input;
191
+ const withDefaults: GuckSessionsParams = {
192
+ ...filters,
193
+ since: resolveSince(filters.since, config, storeDir),
194
+ };
195
+ const result = await readSessions(config, rootDir, withDefaults);
196
+ return buildText(result);
197
+ }
198
+
199
+ if (request.params.name === "guck.tail") {
200
+ const input = (request.params.arguments ?? {}) as GuckTailParams;
201
+ const { config_path: _configPath, ...filters } = input;
202
+ const limit = input.limit ?? Math.min(config.mcp.max_results, 50);
203
+ const since = resolveSince(undefined, config, storeDir);
204
+ const result = await readTail(config, rootDir, {
205
+ service: filters.service,
206
+ session_id: filters.session_id,
207
+ run_id: filters.run_id,
208
+ limit,
209
+ backends: filters.backends,
210
+ since,
211
+ });
212
+ const redacted = result.events.map((event) => redactEvent(config, event));
213
+ return buildText({ ...result, events: redacted });
214
+ }
215
+
216
+ throw new Error(`Unknown tool: ${request.params.name}`);
217
+ });
218
+
219
+ const transport = new StdioServerTransport();
220
+ await server.connect(transport);
221
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "rootDir": "src",
7
+ "outDir": "dist",
8
+ "declaration": true,
9
+ "declarationMap": true,
10
+ "sourceMap": true,
11
+ "strict": true,
12
+ "noUncheckedIndexedAccess": true,
13
+ "esModuleInterop": true,
14
+ "forceConsistentCasingInFileNames": true,
15
+ "skipLibCheck": true,
16
+ "types": ["node"]
17
+ },
18
+ "include": ["src/**/*.ts"]
19
+ }