@guckdev/mcp 0.3.1 → 0.5.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.
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +139 -26
- package/dist/server.js.map +1 -1
- package/package.json +2 -2
- package/src/server.ts +152 -25
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAyLA,eAAO,MAAM,cAAc,QAAa,OAAO,CAAC,IAAI,CAkKnD,CAAC"}
|
package/dist/server.js
CHANGED
|
@@ -1,22 +1,77 @@
|
|
|
1
1
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
2
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
3
|
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
-
import { loadConfig, readCheckpoint, readSearch, readSessions, readStats, readTail, redactEvent, resolveStoreDir, } from "@guckdev/core";
|
|
4
|
+
import { formatEventText, loadConfig, projectEventFields, readCheckpoint, readSearch, readSessions, readStats, readTail, redactEvent, resolveStoreDir, } from "@guckdev/core";
|
|
5
5
|
const SEARCH_SCHEMA = {
|
|
6
6
|
type: "object",
|
|
7
|
+
description: "Search telemetry events. All filters are combined with AND; query is a message-only boolean expression applied after other filters.",
|
|
7
8
|
additionalProperties: false,
|
|
8
9
|
properties: {
|
|
9
|
-
service: {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
service: {
|
|
11
|
+
type: "string",
|
|
12
|
+
description: "Exact match on event.service (use to scope to a single service).",
|
|
13
|
+
},
|
|
14
|
+
session_id: {
|
|
15
|
+
type: "string",
|
|
16
|
+
description: "Exact match on event.session_id.",
|
|
17
|
+
},
|
|
18
|
+
run_id: {
|
|
19
|
+
type: "string",
|
|
20
|
+
description: "Exact match on event.run_id.",
|
|
21
|
+
},
|
|
22
|
+
types: {
|
|
23
|
+
type: "array",
|
|
24
|
+
items: { type: "string" },
|
|
25
|
+
description: "Only include events whose event.type is in this list.",
|
|
26
|
+
},
|
|
27
|
+
levels: {
|
|
28
|
+
type: "array",
|
|
29
|
+
items: { type: "string" },
|
|
30
|
+
description: "Only include events whose event.level is in this list (trace, debug, info, warn, error, fatal).",
|
|
31
|
+
},
|
|
32
|
+
contains: {
|
|
33
|
+
type: "string",
|
|
34
|
+
description: "Case-insensitive substring match across event.message, event.type, event.session_id, and event.data JSON.",
|
|
35
|
+
},
|
|
36
|
+
query: {
|
|
37
|
+
type: "string",
|
|
38
|
+
description: "Boolean search applied to event.message only. Supports AND/OR/NOT, parentheses, quotes, and implicit AND (e.g. \"timeout AND retry\"). Case-insensitive.",
|
|
39
|
+
},
|
|
40
|
+
since: {
|
|
41
|
+
type: "string",
|
|
42
|
+
description: "Start time filter. Accepts ISO timestamps or relative durations like 15m/2h/1d. Also supports \"checkpoint\" to resume from the last saved checkpoint.",
|
|
43
|
+
},
|
|
44
|
+
until: {
|
|
45
|
+
type: "string",
|
|
46
|
+
description: "End time filter. Accepts ISO timestamps or relative durations like 15m/2h/1d.",
|
|
47
|
+
},
|
|
48
|
+
limit: {
|
|
49
|
+
type: "number",
|
|
50
|
+
description: "Maximum number of events to return (defaults to config.mcp.max_results).",
|
|
51
|
+
},
|
|
52
|
+
format: {
|
|
53
|
+
type: "string",
|
|
54
|
+
enum: ["json", "text"],
|
|
55
|
+
description: "Output format: json returns events; text returns formatted lines (use template to customize).",
|
|
56
|
+
},
|
|
57
|
+
fields: {
|
|
58
|
+
type: "array",
|
|
59
|
+
items: { type: "string" },
|
|
60
|
+
description: "JSON projection of event fields to return. Allowed fields: id, ts, level, type, service, run_id, session_id, message, data, tags, trace_id, span_id, source.",
|
|
61
|
+
},
|
|
62
|
+
template: {
|
|
63
|
+
type: "string",
|
|
64
|
+
description: "Text format template when format is \"text\". Tokens like {ts}, {level}, {service}, {message} are replaced; unknown tokens become empty. Example: \"{ts}|{service}|{message}\".",
|
|
65
|
+
},
|
|
66
|
+
backends: {
|
|
67
|
+
type: "array",
|
|
68
|
+
items: { type: "string" },
|
|
69
|
+
description: "Restrict search to specific read backends by id or type (local, cloudwatch, k8s).",
|
|
70
|
+
},
|
|
71
|
+
config_path: {
|
|
72
|
+
type: "string",
|
|
73
|
+
description: "Path to .guck.json or a directory containing it; overrides default config resolution.",
|
|
74
|
+
},
|
|
20
75
|
},
|
|
21
76
|
};
|
|
22
77
|
const STATS_SCHEMA = {
|
|
@@ -53,6 +108,10 @@ const TAIL_SCHEMA = {
|
|
|
53
108
|
session_id: { type: "string" },
|
|
54
109
|
run_id: { type: "string" },
|
|
55
110
|
limit: { type: "number" },
|
|
111
|
+
query: { type: "string" },
|
|
112
|
+
format: { type: "string", enum: ["json", "text"] },
|
|
113
|
+
fields: { type: "array", items: { type: "string" } },
|
|
114
|
+
template: { type: "string" },
|
|
56
115
|
backends: { type: "array", items: { type: "string" } },
|
|
57
116
|
config_path: { type: "string" },
|
|
58
117
|
},
|
|
@@ -97,7 +156,7 @@ export const startMcpServer = async () => {
|
|
|
97
156
|
tools: [
|
|
98
157
|
{
|
|
99
158
|
name: "guck.search",
|
|
100
|
-
description: "Search telemetry events with filters.",
|
|
159
|
+
description: "Search telemetry events with filters. Supports boolean message-only query (query), JSON field projection (fields), or text formatting with template (format: text + template).",
|
|
101
160
|
inputSchema: SEARCH_SCHEMA,
|
|
102
161
|
},
|
|
103
162
|
{
|
|
@@ -112,7 +171,7 @@ export const startMcpServer = async () => {
|
|
|
112
171
|
},
|
|
113
172
|
{
|
|
114
173
|
name: "guck.tail",
|
|
115
|
-
description: "Return the most recent events (non-streaming).",
|
|
174
|
+
description: "Return the most recent events (non-streaming). Supports message-only boolean query (query) and output formatting (format: json/text, fields, template).",
|
|
116
175
|
inputSchema: TAIL_SCHEMA,
|
|
117
176
|
},
|
|
118
177
|
],
|
|
@@ -135,9 +194,35 @@ export const startMcpServer = async () => {
|
|
|
135
194
|
...filters,
|
|
136
195
|
since: resolveSince(filters.since, config, storeDir),
|
|
137
196
|
};
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
197
|
+
try {
|
|
198
|
+
const result = await readSearch(config, rootDir, withDefaults);
|
|
199
|
+
const redacted = result.events.map((event) => redactEvent(config, event));
|
|
200
|
+
if (input.format === "text") {
|
|
201
|
+
const lines = redacted.map((event) => formatEventText(event, input.template));
|
|
202
|
+
return buildText({
|
|
203
|
+
format: "text",
|
|
204
|
+
lines,
|
|
205
|
+
truncated: result.truncated,
|
|
206
|
+
errors: result.errors,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
if (input.fields && input.fields.length > 0) {
|
|
210
|
+
const projected = redacted.map((event) => projectEventFields(event, input.fields ?? []));
|
|
211
|
+
return buildText({
|
|
212
|
+
format: "json",
|
|
213
|
+
events: projected,
|
|
214
|
+
truncated: result.truncated,
|
|
215
|
+
errors: result.errors,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
return buildText({ format: "json", ...result, events: redacted });
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
if (error instanceof Error && error.message.startsWith("Invalid query:")) {
|
|
222
|
+
return buildText({ error: error.message, query: input.query });
|
|
223
|
+
}
|
|
224
|
+
throw error;
|
|
225
|
+
}
|
|
141
226
|
}
|
|
142
227
|
if (request.params.name === "guck.stats") {
|
|
143
228
|
const input = (request.params.arguments ?? {});
|
|
@@ -164,16 +249,44 @@ export const startMcpServer = async () => {
|
|
|
164
249
|
const { config_path: _configPath, ...filters } = input;
|
|
165
250
|
const limit = input.limit ?? Math.min(config.mcp.max_results, 50);
|
|
166
251
|
const since = resolveSince(undefined, config, storeDir);
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
252
|
+
let result;
|
|
253
|
+
try {
|
|
254
|
+
result = await readTail(config, rootDir, {
|
|
255
|
+
service: filters.service,
|
|
256
|
+
session_id: filters.session_id,
|
|
257
|
+
run_id: filters.run_id,
|
|
258
|
+
query: filters.query,
|
|
259
|
+
limit,
|
|
260
|
+
backends: filters.backends,
|
|
261
|
+
since,
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
if (error instanceof Error && error.message.startsWith("Invalid query:")) {
|
|
266
|
+
return buildText({ error: error.message, query: input.query });
|
|
267
|
+
}
|
|
268
|
+
throw error;
|
|
269
|
+
}
|
|
175
270
|
const redacted = result.events.map((event) => redactEvent(config, event));
|
|
176
|
-
|
|
271
|
+
if (input.format === "text") {
|
|
272
|
+
const lines = redacted.map((event) => formatEventText(event, input.template));
|
|
273
|
+
return buildText({
|
|
274
|
+
format: "text",
|
|
275
|
+
lines,
|
|
276
|
+
truncated: result.truncated,
|
|
277
|
+
errors: result.errors,
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
if (input.fields && input.fields.length > 0) {
|
|
281
|
+
const projected = redacted.map((event) => projectEventFields(event, input.fields ?? []));
|
|
282
|
+
return buildText({
|
|
283
|
+
format: "json",
|
|
284
|
+
events: projected,
|
|
285
|
+
truncated: result.truncated,
|
|
286
|
+
errors: result.errors,
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
return buildText({ format: "json", ...result, events: redacted });
|
|
177
290
|
}
|
|
178
291
|
throw new Error(`Unknown tool: ${request.params.name}`);
|
|
179
292
|
});
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,M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ACpE,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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guckdev/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "MCP server for Guck telemetry",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@modelcontextprotocol/sdk": "1.26.0",
|
|
37
|
-
"@guckdev/core": "0.
|
|
37
|
+
"@guckdev/core": "0.5.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/node": "25.2.2"
|
package/src/server.ts
CHANGED
|
@@ -10,7 +10,9 @@ import {
|
|
|
10
10
|
GuckSessionsParams,
|
|
11
11
|
GuckStatsParams,
|
|
12
12
|
GuckTailParams,
|
|
13
|
+
formatEventText,
|
|
13
14
|
loadConfig,
|
|
15
|
+
projectEventFields,
|
|
14
16
|
readCheckpoint,
|
|
15
17
|
readSearch,
|
|
16
18
|
readSessions,
|
|
@@ -21,19 +23,86 @@ import {
|
|
|
21
23
|
} from "@guckdev/core";
|
|
22
24
|
const SEARCH_SCHEMA = {
|
|
23
25
|
type: "object",
|
|
26
|
+
description:
|
|
27
|
+
"Search telemetry events. All filters are combined with AND; query is a message-only boolean expression applied after other filters.",
|
|
24
28
|
additionalProperties: false,
|
|
25
29
|
properties: {
|
|
26
|
-
service: {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
service: {
|
|
31
|
+
type: "string",
|
|
32
|
+
description: "Exact match on event.service (use to scope to a single service).",
|
|
33
|
+
},
|
|
34
|
+
session_id: {
|
|
35
|
+
type: "string",
|
|
36
|
+
description: "Exact match on event.session_id.",
|
|
37
|
+
},
|
|
38
|
+
run_id: {
|
|
39
|
+
type: "string",
|
|
40
|
+
description: "Exact match on event.run_id.",
|
|
41
|
+
},
|
|
42
|
+
types: {
|
|
43
|
+
type: "array",
|
|
44
|
+
items: { type: "string" },
|
|
45
|
+
description: "Only include events whose event.type is in this list.",
|
|
46
|
+
},
|
|
47
|
+
levels: {
|
|
48
|
+
type: "array",
|
|
49
|
+
items: { type: "string" },
|
|
50
|
+
description:
|
|
51
|
+
"Only include events whose event.level is in this list (trace, debug, info, warn, error, fatal).",
|
|
52
|
+
},
|
|
53
|
+
contains: {
|
|
54
|
+
type: "string",
|
|
55
|
+
description:
|
|
56
|
+
"Case-insensitive substring match across event.message, event.type, event.session_id, and event.data JSON.",
|
|
57
|
+
},
|
|
58
|
+
query: {
|
|
59
|
+
type: "string",
|
|
60
|
+
description:
|
|
61
|
+
"Boolean search applied to event.message only. Supports AND/OR/NOT, parentheses, quotes, and implicit AND (e.g. \"timeout AND retry\"). Case-insensitive.",
|
|
62
|
+
},
|
|
63
|
+
since: {
|
|
64
|
+
type: "string",
|
|
65
|
+
description:
|
|
66
|
+
"Start time filter. Accepts ISO timestamps or relative durations like 15m/2h/1d. Also supports \"checkpoint\" to resume from the last saved checkpoint.",
|
|
67
|
+
},
|
|
68
|
+
until: {
|
|
69
|
+
type: "string",
|
|
70
|
+
description:
|
|
71
|
+
"End time filter. Accepts ISO timestamps or relative durations like 15m/2h/1d.",
|
|
72
|
+
},
|
|
73
|
+
limit: {
|
|
74
|
+
type: "number",
|
|
75
|
+
description:
|
|
76
|
+
"Maximum number of events to return (defaults to config.mcp.max_results).",
|
|
77
|
+
},
|
|
78
|
+
format: {
|
|
79
|
+
type: "string",
|
|
80
|
+
enum: ["json", "text"],
|
|
81
|
+
description:
|
|
82
|
+
"Output format: json returns events; text returns formatted lines (use template to customize).",
|
|
83
|
+
},
|
|
84
|
+
fields: {
|
|
85
|
+
type: "array",
|
|
86
|
+
items: { type: "string" },
|
|
87
|
+
description:
|
|
88
|
+
"JSON projection of event fields to return. Allowed fields: id, ts, level, type, service, run_id, session_id, message, data, tags, trace_id, span_id, source.",
|
|
89
|
+
},
|
|
90
|
+
template: {
|
|
91
|
+
type: "string",
|
|
92
|
+
description:
|
|
93
|
+
"Text format template when format is \"text\". Tokens like {ts}, {level}, {service}, {message} are replaced; unknown tokens become empty. Example: \"{ts}|{service}|{message}\".",
|
|
94
|
+
},
|
|
95
|
+
backends: {
|
|
96
|
+
type: "array",
|
|
97
|
+
items: { type: "string" },
|
|
98
|
+
description:
|
|
99
|
+
"Restrict search to specific read backends by id or type (local, cloudwatch, k8s).",
|
|
100
|
+
},
|
|
101
|
+
config_path: {
|
|
102
|
+
type: "string",
|
|
103
|
+
description:
|
|
104
|
+
"Path to .guck.json or a directory containing it; overrides default config resolution.",
|
|
105
|
+
},
|
|
37
106
|
},
|
|
38
107
|
} as const;
|
|
39
108
|
|
|
@@ -73,6 +142,10 @@ const TAIL_SCHEMA = {
|
|
|
73
142
|
session_id: { type: "string" },
|
|
74
143
|
run_id: { type: "string" },
|
|
75
144
|
limit: { type: "number" },
|
|
145
|
+
query: { type: "string" },
|
|
146
|
+
format: { type: "string", enum: ["json", "text"] },
|
|
147
|
+
fields: { type: "array", items: { type: "string" } },
|
|
148
|
+
template: { type: "string" },
|
|
76
149
|
backends: { type: "array", items: { type: "string" } },
|
|
77
150
|
config_path: { type: "string" },
|
|
78
151
|
},
|
|
@@ -128,7 +201,8 @@ export const startMcpServer = async (): Promise<void> => {
|
|
|
128
201
|
tools: [
|
|
129
202
|
{
|
|
130
203
|
name: "guck.search",
|
|
131
|
-
description:
|
|
204
|
+
description:
|
|
205
|
+
"Search telemetry events with filters. Supports boolean message-only query (query), JSON field projection (fields), or text formatting with template (format: text + template).",
|
|
132
206
|
inputSchema: SEARCH_SCHEMA,
|
|
133
207
|
},
|
|
134
208
|
{
|
|
@@ -143,7 +217,8 @@ export const startMcpServer = async (): Promise<void> => {
|
|
|
143
217
|
},
|
|
144
218
|
{
|
|
145
219
|
name: "guck.tail",
|
|
146
|
-
description:
|
|
220
|
+
description:
|
|
221
|
+
"Return the most recent events (non-streaming). Supports message-only boolean query (query) and output formatting (format: json/text, fields, template).",
|
|
147
222
|
inputSchema: TAIL_SCHEMA,
|
|
148
223
|
},
|
|
149
224
|
],
|
|
@@ -169,9 +244,34 @@ export const startMcpServer = async (): Promise<void> => {
|
|
|
169
244
|
...filters,
|
|
170
245
|
since: resolveSince(filters.since, config, storeDir),
|
|
171
246
|
};
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
247
|
+
try {
|
|
248
|
+
const result = await readSearch(config, rootDir, withDefaults);
|
|
249
|
+
const redacted = result.events.map((event) => redactEvent(config, event));
|
|
250
|
+
if (input.format === "text") {
|
|
251
|
+
const lines = redacted.map((event) => formatEventText(event, input.template));
|
|
252
|
+
return buildText({
|
|
253
|
+
format: "text",
|
|
254
|
+
lines,
|
|
255
|
+
truncated: result.truncated,
|
|
256
|
+
errors: result.errors,
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
if (input.fields && input.fields.length > 0) {
|
|
260
|
+
const projected = redacted.map((event) => projectEventFields(event, input.fields ?? []));
|
|
261
|
+
return buildText({
|
|
262
|
+
format: "json",
|
|
263
|
+
events: projected,
|
|
264
|
+
truncated: result.truncated,
|
|
265
|
+
errors: result.errors,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
return buildText({ format: "json", ...result, events: redacted });
|
|
269
|
+
} catch (error) {
|
|
270
|
+
if (error instanceof Error && error.message.startsWith("Invalid query:")) {
|
|
271
|
+
return buildText({ error: error.message, query: input.query });
|
|
272
|
+
}
|
|
273
|
+
throw error;
|
|
274
|
+
}
|
|
175
275
|
}
|
|
176
276
|
|
|
177
277
|
if (request.params.name === "guck.stats") {
|
|
@@ -201,16 +301,43 @@ export const startMcpServer = async (): Promise<void> => {
|
|
|
201
301
|
const { config_path: _configPath, ...filters } = input;
|
|
202
302
|
const limit = input.limit ?? Math.min(config.mcp.max_results, 50);
|
|
203
303
|
const since = resolveSince(undefined, config, storeDir);
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
304
|
+
let result;
|
|
305
|
+
try {
|
|
306
|
+
result = await readTail(config, rootDir, {
|
|
307
|
+
service: filters.service,
|
|
308
|
+
session_id: filters.session_id,
|
|
309
|
+
run_id: filters.run_id,
|
|
310
|
+
query: filters.query,
|
|
311
|
+
limit,
|
|
312
|
+
backends: filters.backends,
|
|
313
|
+
since,
|
|
314
|
+
});
|
|
315
|
+
} catch (error) {
|
|
316
|
+
if (error instanceof Error && error.message.startsWith("Invalid query:")) {
|
|
317
|
+
return buildText({ error: error.message, query: input.query });
|
|
318
|
+
}
|
|
319
|
+
throw error;
|
|
320
|
+
}
|
|
212
321
|
const redacted = result.events.map((event) => redactEvent(config, event));
|
|
213
|
-
|
|
322
|
+
if (input.format === "text") {
|
|
323
|
+
const lines = redacted.map((event) => formatEventText(event, input.template));
|
|
324
|
+
return buildText({
|
|
325
|
+
format: "text",
|
|
326
|
+
lines,
|
|
327
|
+
truncated: result.truncated,
|
|
328
|
+
errors: result.errors,
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
if (input.fields && input.fields.length > 0) {
|
|
332
|
+
const projected = redacted.map((event) => projectEventFields(event, input.fields ?? []));
|
|
333
|
+
return buildText({
|
|
334
|
+
format: "json",
|
|
335
|
+
events: projected,
|
|
336
|
+
truncated: result.truncated,
|
|
337
|
+
errors: result.errors,
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
return buildText({ format: "json", ...result, events: redacted });
|
|
214
341
|
}
|
|
215
342
|
|
|
216
343
|
throw new Error(`Unknown tool: ${request.params.name}`);
|