@graphty/remote-logger 0.0.1 → 1.2.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/README.md +944 -28
- package/bin/remote-log-server.js +3 -0
- package/dist/client/RemoteLogClient.d.ts +116 -0
- package/dist/client/RemoteLogClient.d.ts.map +1 -0
- package/dist/client/RemoteLogClient.js +269 -0
- package/dist/client/RemoteLogClient.js.map +1 -0
- package/dist/client/index.d.ts +7 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +6 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/types.d.ts +60 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +6 -0
- package/dist/client/types.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/index.d.ts +9 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +9 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/mcp-server.d.ts +32 -0
- package/dist/mcp/mcp-server.d.ts.map +1 -0
- package/dist/mcp/mcp-server.js +270 -0
- package/dist/mcp/mcp-server.js.map +1 -0
- package/dist/mcp/tools/index.d.ts +14 -0
- package/dist/mcp/tools/index.d.ts.map +1 -0
- package/dist/mcp/tools/index.js +14 -0
- package/dist/mcp/tools/index.js.map +1 -0
- package/dist/mcp/tools/logs-clear.d.ts +76 -0
- package/dist/mcp/tools/logs-clear.d.ts.map +1 -0
- package/dist/mcp/tools/logs-clear.js +58 -0
- package/dist/mcp/tools/logs-clear.js.map +1 -0
- package/dist/mcp/tools/logs-get-all.d.ts +60 -0
- package/dist/mcp/tools/logs-get-all.d.ts.map +1 -0
- package/dist/mcp/tools/logs-get-all.js +50 -0
- package/dist/mcp/tools/logs-get-all.js.map +1 -0
- package/dist/mcp/tools/logs-get-errors.d.ts +65 -0
- package/dist/mcp/tools/logs-get-errors.d.ts.map +1 -0
- package/dist/mcp/tools/logs-get-errors.js +46 -0
- package/dist/mcp/tools/logs-get-errors.js.map +1 -0
- package/dist/mcp/tools/logs-get-file-path.d.ts +75 -0
- package/dist/mcp/tools/logs-get-file-path.d.ts.map +1 -0
- package/dist/mcp/tools/logs-get-file-path.js +90 -0
- package/dist/mcp/tools/logs-get-file-path.js.map +1 -0
- package/dist/mcp/tools/logs-get-recent.d.ts +89 -0
- package/dist/mcp/tools/logs-get-recent.d.ts.map +1 -0
- package/dist/mcp/tools/logs-get-recent.js +74 -0
- package/dist/mcp/tools/logs-get-recent.js.map +1 -0
- package/dist/mcp/tools/logs-list-sessions.d.ts +64 -0
- package/dist/mcp/tools/logs-list-sessions.d.ts.map +1 -0
- package/dist/mcp/tools/logs-list-sessions.js +48 -0
- package/dist/mcp/tools/logs-list-sessions.js.map +1 -0
- package/dist/mcp/tools/logs-receive.d.ts +150 -0
- package/dist/mcp/tools/logs-receive.d.ts.map +1 -0
- package/dist/mcp/tools/logs-receive.js +68 -0
- package/dist/mcp/tools/logs-receive.js.map +1 -0
- package/dist/mcp/tools/logs-search.d.ts +91 -0
- package/dist/mcp/tools/logs-search.d.ts.map +1 -0
- package/dist/mcp/tools/logs-search.js +68 -0
- package/dist/mcp/tools/logs-search.js.map +1 -0
- package/dist/mcp/tools/logs-status.d.ts +45 -0
- package/dist/mcp/tools/logs-status.d.ts.map +1 -0
- package/dist/mcp/tools/logs-status.js +45 -0
- package/dist/mcp/tools/logs-status.js.map +1 -0
- package/dist/server/dual-server.d.ts +76 -0
- package/dist/server/dual-server.d.ts.map +1 -0
- package/dist/server/dual-server.js +214 -0
- package/dist/server/dual-server.js.map +1 -0
- package/dist/server/index.d.ts +12 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +12 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/jsonl-writer.d.ts +93 -0
- package/dist/server/jsonl-writer.d.ts.map +1 -0
- package/dist/server/jsonl-writer.js +205 -0
- package/dist/server/jsonl-writer.js.map +1 -0
- package/dist/server/log-server.d.ts +126 -0
- package/dist/server/log-server.d.ts.map +1 -0
- package/dist/server/log-server.js +589 -0
- package/dist/server/log-server.js.map +1 -0
- package/dist/server/log-storage.d.ts +301 -0
- package/dist/server/log-storage.d.ts.map +1 -0
- package/dist/server/log-storage.js +408 -0
- package/dist/server/log-storage.js.map +1 -0
- package/dist/server/marker-utils.d.ts +69 -0
- package/dist/server/marker-utils.d.ts.map +1 -0
- package/dist/server/marker-utils.js +118 -0
- package/dist/server/marker-utils.js.map +1 -0
- package/dist/server/self-signed-cert.d.ts +30 -0
- package/dist/server/self-signed-cert.d.ts.map +1 -0
- package/dist/server/self-signed-cert.js +83 -0
- package/dist/server/self-signed-cert.js.map +1 -0
- package/dist/ui/ConsoleCaptureUI.d.ts +118 -0
- package/dist/ui/ConsoleCaptureUI.d.ts.map +1 -0
- package/dist/ui/ConsoleCaptureUI.js +571 -0
- package/dist/ui/ConsoleCaptureUI.js.map +1 -0
- package/dist/ui/index.d.ts +15 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +15 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/vite/index.d.ts +8 -0
- package/dist/vite/index.d.ts.map +1 -0
- package/dist/vite/index.js +8 -0
- package/dist/vite/index.js.map +1 -0
- package/dist/vite/plugin.d.ts +42 -0
- package/dist/vite/plugin.d.ts.map +1 -0
- package/dist/vite/plugin.js +46 -0
- package/dist/vite/plugin.js.map +1 -0
- package/package.json +90 -7
- package/src/client/RemoteLogClient.ts +328 -0
- package/src/client/index.ts +7 -0
- package/src/client/types.ts +62 -0
- package/src/index.ts +28 -0
- package/src/mcp/index.ts +25 -0
- package/src/mcp/mcp-server.ts +364 -0
- package/src/mcp/tools/index.ts +69 -0
- package/src/mcp/tools/logs-clear.ts +86 -0
- package/src/mcp/tools/logs-get-all.ts +78 -0
- package/src/mcp/tools/logs-get-errors.ts +71 -0
- package/src/mcp/tools/logs-get-file-path.ts +121 -0
- package/src/mcp/tools/logs-get-recent.ts +104 -0
- package/src/mcp/tools/logs-list-sessions.ts +71 -0
- package/src/mcp/tools/logs-receive.ts +96 -0
- package/src/mcp/tools/logs-search.ts +95 -0
- package/src/mcp/tools/logs-status.ts +69 -0
- package/src/server/dual-server.ts +308 -0
- package/src/server/index.ts +54 -0
- package/src/server/jsonl-writer.ts +277 -0
- package/src/server/log-server.ts +763 -0
- package/src/server/log-storage.ts +651 -0
- package/src/server/marker-utils.ts +144 -0
- package/src/server/self-signed-cert.ts +93 -0
- package/src/ui/ConsoleCaptureUI.ts +649 -0
- package/src/ui/index.ts +15 -0
- package/src/vite/index.ts +8 -0
- package/src/vite/plugin.ts +59 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* logs_get_file_path MCP tool implementation.
|
|
3
|
+
*
|
|
4
|
+
* Returns the path to the JSONL log file for a project.
|
|
5
|
+
* @module mcp/tools/logs-get-file-path
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as fs from "fs";
|
|
9
|
+
import * as os from "os";
|
|
10
|
+
import * as path from "path";
|
|
11
|
+
import * as z from "zod/v3";
|
|
12
|
+
|
|
13
|
+
import type { LogStorage } from "../../server/log-storage.js";
|
|
14
|
+
import { resolveProjectMarker } from "../../server/marker-utils.js";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Input schema for the logs_get_file_path tool.
|
|
18
|
+
*/
|
|
19
|
+
export const logsGetFilePathInputSchema = z.object({
|
|
20
|
+
/** Project identifier to get the log file for. Derived from workingDirectory if not provided. */
|
|
21
|
+
projectMarker: z.string().optional(),
|
|
22
|
+
/** Directory path to derive project marker from. Ignored if projectMarker is set. */
|
|
23
|
+
workingDirectory: z.string().optional(),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Input type for the logs_get_file_path handler.
|
|
28
|
+
*/
|
|
29
|
+
export type LogsGetFilePathInput = z.infer<typeof logsGetFilePathInputSchema>;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Output type for the logs_get_file_path handler.
|
|
33
|
+
*/
|
|
34
|
+
export interface LogsGetFilePathOutput {
|
|
35
|
+
/** Full path to the JSONL log file */
|
|
36
|
+
path: string;
|
|
37
|
+
/** Whether the file exists */
|
|
38
|
+
exists: boolean;
|
|
39
|
+
/** File size in bytes (0 if file doesn't exist) */
|
|
40
|
+
size: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Get the default JSONL file path for a project marker.
|
|
45
|
+
* This is used when no JsonlWriter is configured.
|
|
46
|
+
* @param projectMarker - The project marker
|
|
47
|
+
* @returns Full path to the JSONL file
|
|
48
|
+
*/
|
|
49
|
+
export function getLogFilePath(projectMarker: string): string {
|
|
50
|
+
return path.join(os.tmpdir(), "remote-logger", projectMarker, "logs.jsonl");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Handler for the logs_get_file_path tool.
|
|
55
|
+
*
|
|
56
|
+
* Returns the path to the JSONL log file for the specified project.
|
|
57
|
+
* The file may not exist if no logs have been written yet.
|
|
58
|
+
* @param storage - The log storage instance
|
|
59
|
+
* @param input - Input parameters
|
|
60
|
+
* @returns File path, existence status, and size
|
|
61
|
+
*/
|
|
62
|
+
export function logsGetFilePathHandler(
|
|
63
|
+
storage: LogStorage,
|
|
64
|
+
input: Partial<LogsGetFilePathInput>,
|
|
65
|
+
): Promise<LogsGetFilePathOutput> {
|
|
66
|
+
// Resolve project marker
|
|
67
|
+
const projectMarker = resolveProjectMarker({
|
|
68
|
+
projectMarker: input.projectMarker,
|
|
69
|
+
workingDirectory: input.workingDirectory,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Get file path from JsonlWriter if available, otherwise use default
|
|
73
|
+
const jsonlWriter = storage.getJsonlWriter();
|
|
74
|
+
const filePath = jsonlWriter
|
|
75
|
+
? jsonlWriter.getFilePath(projectMarker)
|
|
76
|
+
: getLogFilePath(projectMarker);
|
|
77
|
+
|
|
78
|
+
// Check if file exists and get stats
|
|
79
|
+
// Prefer JsonlWriter stats if available for consistency
|
|
80
|
+
if (jsonlWriter) {
|
|
81
|
+
const stats = jsonlWriter.getFileStats(projectMarker);
|
|
82
|
+
if (stats) {
|
|
83
|
+
return Promise.resolve({
|
|
84
|
+
path: filePath,
|
|
85
|
+
exists: stats.exists,
|
|
86
|
+
size: stats.size,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Fall back to direct file system check
|
|
92
|
+
let exists = false;
|
|
93
|
+
let size = 0;
|
|
94
|
+
|
|
95
|
+
try {
|
|
96
|
+
const stats = fs.statSync(filePath);
|
|
97
|
+
exists = true;
|
|
98
|
+
({ size } = stats);
|
|
99
|
+
} catch {
|
|
100
|
+
// File doesn't exist, use defaults
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return Promise.resolve({
|
|
104
|
+
path: filePath,
|
|
105
|
+
exists,
|
|
106
|
+
size,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Tool definition for MCP registration.
|
|
112
|
+
*/
|
|
113
|
+
export const logsGetFilePathTool = {
|
|
114
|
+
name: "logs_get_file_path",
|
|
115
|
+
description:
|
|
116
|
+
"Get the file path to the JSONL log file for a project. " +
|
|
117
|
+
"Use this to access logs via file-based tools like Grep or Read. " +
|
|
118
|
+
"Each project has its own log file. " +
|
|
119
|
+
"The file may not exist if no logs have been written yet for that project.",
|
|
120
|
+
inputSchema: logsGetFilePathInputSchema,
|
|
121
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* logs_get_recent MCP tool implementation.
|
|
3
|
+
*
|
|
4
|
+
* Returns recent logs sorted by time with optional filtering.
|
|
5
|
+
* @module mcp/tools/logs-get-recent
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as z from "zod/v3";
|
|
9
|
+
|
|
10
|
+
import type { LogEntryWithSession, LogFilter,LogStorage } from "../../server/log-storage.js";
|
|
11
|
+
import { resolveProjectMarker } from "../../server/marker-utils.js";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Input schema for the logs_get_recent tool.
|
|
15
|
+
* Note: We use a simple shape without .default() to be compatible with MCP SDK.
|
|
16
|
+
*/
|
|
17
|
+
export const logsGetRecentInputSchema = z.object({
|
|
18
|
+
/** Number of logs to return. Defaults to 50. Range: 1-500. */
|
|
19
|
+
count: z.number().int().min(1).max(500).optional(),
|
|
20
|
+
/** Filter logs to a specific project. Derived from workingDirectory if not provided. */
|
|
21
|
+
projectMarker: z.string().optional(),
|
|
22
|
+
/** Directory path to derive project marker from. Ignored if projectMarker is set. */
|
|
23
|
+
workingDirectory: z.string().optional(),
|
|
24
|
+
/** Filter by log level (e.g., "INFO", "ERROR", "DEBUG"). Case-sensitive. */
|
|
25
|
+
level: z.string().optional(),
|
|
26
|
+
/** Return only logs after this timestamp. Format: ISO 8601 (e.g., "2025-01-08T12:00:00Z"). */
|
|
27
|
+
since: z.string().optional(),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Input type for the logs_get_recent handler.
|
|
32
|
+
*/
|
|
33
|
+
export type LogsGetRecentInput = z.infer<typeof logsGetRecentInputSchema>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Output type for the logs_get_recent handler.
|
|
37
|
+
*/
|
|
38
|
+
export interface LogsGetRecentOutput {
|
|
39
|
+
logs: LogEntryWithSession[];
|
|
40
|
+
count: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Handler for the logs_get_recent tool.
|
|
45
|
+
*
|
|
46
|
+
* Returns recent logs sorted by time (oldest first), with optional filtering
|
|
47
|
+
* by project marker, level, or timestamp.
|
|
48
|
+
* @param storage - The log storage instance
|
|
49
|
+
* @param input - Input parameters
|
|
50
|
+
* @returns Recent logs and count
|
|
51
|
+
*/
|
|
52
|
+
export function logsGetRecentHandler(
|
|
53
|
+
storage: LogStorage,
|
|
54
|
+
input: Partial<LogsGetRecentInput>,
|
|
55
|
+
): Promise<LogsGetRecentOutput> {
|
|
56
|
+
// Apply defaults
|
|
57
|
+
const requestedCount = input.count ?? 50;
|
|
58
|
+
|
|
59
|
+
// Resolve project marker from input
|
|
60
|
+
const projectMarker = resolveProjectMarker({
|
|
61
|
+
projectMarker: input.projectMarker,
|
|
62
|
+
workingDirectory: input.workingDirectory,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// Build filter
|
|
66
|
+
const filter: LogFilter = {};
|
|
67
|
+
|
|
68
|
+
if (projectMarker !== "default") {
|
|
69
|
+
filter.projectMarker = projectMarker;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (input.level) {
|
|
73
|
+
filter.level = input.level;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (input.since) {
|
|
77
|
+
filter.since = input.since;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Ensure count doesn't exceed 500
|
|
81
|
+
const limitedCount = Math.min(requestedCount, 500);
|
|
82
|
+
|
|
83
|
+
// Get recent logs
|
|
84
|
+
const logs = storage.getRecentLogs(limitedCount, filter);
|
|
85
|
+
|
|
86
|
+
return Promise.resolve({
|
|
87
|
+
logs,
|
|
88
|
+
count: logs.length,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Tool definition for MCP registration.
|
|
94
|
+
*/
|
|
95
|
+
export const logsGetRecentTool = {
|
|
96
|
+
name: "logs_get_recent",
|
|
97
|
+
description:
|
|
98
|
+
"Get recent logs from the remote log server, sorted by time (oldest first). " +
|
|
99
|
+
"Use this to see the latest log output from browser applications. " +
|
|
100
|
+
"This is the primary tool for viewing logs. " +
|
|
101
|
+
"For error-only logs, use logs_get_errors instead. " +
|
|
102
|
+
"For searching specific text, use logs_search.",
|
|
103
|
+
inputSchema: logsGetRecentInputSchema,
|
|
104
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* logs_list_sessions MCP tool implementation.
|
|
3
|
+
*
|
|
4
|
+
* Lists all logging sessions with their metadata.
|
|
5
|
+
* @module mcp/tools/logs-list-sessions
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as z from "zod/v3";
|
|
9
|
+
|
|
10
|
+
import type { LogStorage, SessionMetadata } from "../../server/log-storage.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Input schema for the logs_list_sessions tool.
|
|
14
|
+
*/
|
|
15
|
+
export const logsListSessionsInputSchema = z.object({
|
|
16
|
+
/** Filter sessions to a specific project identifier. */
|
|
17
|
+
projectMarker: z.string().optional(),
|
|
18
|
+
/** When true, only return sessions that contain error-level logs. */
|
|
19
|
+
hasErrors: z.boolean().optional(),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Input type for the logs_list_sessions handler.
|
|
24
|
+
*/
|
|
25
|
+
export type LogsListSessionsInput = z.infer<typeof logsListSessionsInputSchema>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Output type for the logs_list_sessions handler.
|
|
29
|
+
*/
|
|
30
|
+
export interface LogsListSessionsOutput {
|
|
31
|
+
sessions: SessionMetadata[];
|
|
32
|
+
count: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Handler for the logs_list_sessions tool.
|
|
37
|
+
*
|
|
38
|
+
* Lists all logging sessions with their metadata including project marker,
|
|
39
|
+
* log counts, error counts, and timestamps.
|
|
40
|
+
* @param storage - The log storage instance
|
|
41
|
+
* @param input - Input parameters
|
|
42
|
+
* @returns List of sessions and count
|
|
43
|
+
*/
|
|
44
|
+
export function logsListSessionsHandler(
|
|
45
|
+
storage: LogStorage,
|
|
46
|
+
input: Partial<LogsListSessionsInput>,
|
|
47
|
+
): Promise<LogsListSessionsOutput> {
|
|
48
|
+
// Get sessions with filter
|
|
49
|
+
const sessions = storage.getSessions({
|
|
50
|
+
projectMarker: input.projectMarker,
|
|
51
|
+
hasErrors: input.hasErrors,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return Promise.resolve({
|
|
55
|
+
sessions,
|
|
56
|
+
count: sessions.length,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Tool definition for MCP registration.
|
|
62
|
+
*/
|
|
63
|
+
export const logsListSessionsTool = {
|
|
64
|
+
name: "logs_list_sessions",
|
|
65
|
+
description:
|
|
66
|
+
"List all logging sessions with their metadata. " +
|
|
67
|
+
"Each session represents a browser tab or application instance. " +
|
|
68
|
+
"Use this to discover active sessions before fetching their logs, " +
|
|
69
|
+
"or to find sessions with errors using the hasErrors filter.",
|
|
70
|
+
inputSchema: logsListSessionsInputSchema,
|
|
71
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* logs_receive MCP tool implementation.
|
|
3
|
+
*
|
|
4
|
+
* Stores logs with session metadata for later retrieval.
|
|
5
|
+
* @module mcp/tools/logs-receive
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as z from "zod/v3";
|
|
9
|
+
|
|
10
|
+
import type { LogStorage } from "../../server/log-storage.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Schema for a single log entry.
|
|
14
|
+
*/
|
|
15
|
+
const logEntrySchema = z.object({
|
|
16
|
+
/** When the log was created. Format: ISO 8601 (e.g., "2025-01-08T12:00:00Z"). */
|
|
17
|
+
time: z.string(),
|
|
18
|
+
/** Severity level (e.g., "INFO", "DEBUG", "WARN", "ERROR"). */
|
|
19
|
+
level: z.string(),
|
|
20
|
+
/** The log message text. */
|
|
21
|
+
message: z.string(),
|
|
22
|
+
/** Additional structured data to attach to the log entry. */
|
|
23
|
+
data: z.record(z.unknown()).optional(),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Input schema for the logs_receive tool.
|
|
28
|
+
*/
|
|
29
|
+
export const logsReceiveInputSchema = z.object({
|
|
30
|
+
/** Unique identifier for this logging session. Links related logs together. */
|
|
31
|
+
sessionId: z.string(),
|
|
32
|
+
/** Array of log entries to store. At least one entry required. */
|
|
33
|
+
logs: z.array(logEntrySchema),
|
|
34
|
+
/** Project identifier for filtering. Derived from sessionId prefix if not provided. */
|
|
35
|
+
projectMarker: z.string().optional(),
|
|
36
|
+
/** Git worktree path for project identification. */
|
|
37
|
+
worktreePath: z.string().optional(),
|
|
38
|
+
/** URL of the page that generated these logs. */
|
|
39
|
+
pageUrl: z.string().optional(),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Input type for the logs_receive handler.
|
|
44
|
+
*/
|
|
45
|
+
export type LogsReceiveInput = z.infer<typeof logsReceiveInputSchema>;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Output type for the logs_receive handler.
|
|
49
|
+
*/
|
|
50
|
+
export interface LogsReceiveOutput {
|
|
51
|
+
/** Whether the operation succeeded */
|
|
52
|
+
success: boolean;
|
|
53
|
+
/** Number of logs stored */
|
|
54
|
+
count: number;
|
|
55
|
+
/** The session ID used */
|
|
56
|
+
sessionId: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Handler for the logs_receive tool.
|
|
61
|
+
*
|
|
62
|
+
* Stores logs with session metadata. The project marker is derived from
|
|
63
|
+
* the session ID prefix if not explicitly provided.
|
|
64
|
+
* @param storage - The log storage instance
|
|
65
|
+
* @param input - Input parameters
|
|
66
|
+
* @returns Success status, count, and session ID
|
|
67
|
+
*/
|
|
68
|
+
export function logsReceiveHandler(
|
|
69
|
+
storage: LogStorage,
|
|
70
|
+
input: LogsReceiveInput,
|
|
71
|
+
): Promise<LogsReceiveOutput> {
|
|
72
|
+
storage.addLogs(input.sessionId, input.logs, {
|
|
73
|
+
projectMarker: input.projectMarker,
|
|
74
|
+
worktreePath: input.worktreePath,
|
|
75
|
+
pageUrl: input.pageUrl,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
return Promise.resolve({
|
|
79
|
+
success: true,
|
|
80
|
+
count: input.logs.length,
|
|
81
|
+
sessionId: input.sessionId,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Tool definition for MCP registration.
|
|
87
|
+
*/
|
|
88
|
+
export const logsReceiveTool = {
|
|
89
|
+
name: "logs_receive",
|
|
90
|
+
description:
|
|
91
|
+
"Store logs from a browser or application session. " +
|
|
92
|
+
"Logs are associated with a session ID and can be filtered by project marker. " +
|
|
93
|
+
"This tool is called by browser clients to send logs to the server. " +
|
|
94
|
+
"You typically don't need to call this directly - use it when manually testing log ingestion.",
|
|
95
|
+
inputSchema: logsReceiveInputSchema,
|
|
96
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* logs_search MCP tool implementation.
|
|
3
|
+
*
|
|
4
|
+
* Searches logs by substring or regex pattern.
|
|
5
|
+
* @module mcp/tools/logs-search
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as z from "zod/v3";
|
|
9
|
+
|
|
10
|
+
import type { LogEntryWithSession, LogStorage } from "../../server/log-storage.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Input schema for the logs_search tool.
|
|
14
|
+
*/
|
|
15
|
+
export const logsSearchInputSchema = z.object({
|
|
16
|
+
/** The text pattern to search for in log messages. */
|
|
17
|
+
query: z.string(),
|
|
18
|
+
/** When true, treat query as a regular expression. Default: false (substring match). */
|
|
19
|
+
regex: z.boolean().optional(),
|
|
20
|
+
/** Filter results to a specific project identifier. Searches all projects if omitted. */
|
|
21
|
+
projectMarker: z.string().optional(),
|
|
22
|
+
/** Filter by log level (e.g., "INFO", "ERROR"). Case-sensitive. */
|
|
23
|
+
level: z.string().optional(),
|
|
24
|
+
/** Maximum number of results to return. Defaults to 100. Range: 1-1000. */
|
|
25
|
+
limit: z.number().int().min(1).max(1000).optional(),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Input type for the logs_search handler.
|
|
30
|
+
*/
|
|
31
|
+
export type LogsSearchInput = z.infer<typeof logsSearchInputSchema>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Output type for the logs_search handler.
|
|
35
|
+
*/
|
|
36
|
+
export interface LogsSearchOutput {
|
|
37
|
+
/** Matching log entries */
|
|
38
|
+
results: LogEntryWithSession[];
|
|
39
|
+
/** Number of results returned */
|
|
40
|
+
count: number;
|
|
41
|
+
/** Error message if regex is invalid */
|
|
42
|
+
error?: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Handler for the logs_search tool.
|
|
47
|
+
*
|
|
48
|
+
* Searches log messages by substring (case-insensitive) or regex pattern.
|
|
49
|
+
* @param storage - The log storage instance
|
|
50
|
+
* @param input - Input parameters
|
|
51
|
+
* @returns Matching logs and count
|
|
52
|
+
*/
|
|
53
|
+
export function logsSearchHandler(
|
|
54
|
+
storage: LogStorage,
|
|
55
|
+
input: LogsSearchInput,
|
|
56
|
+
): Promise<LogsSearchOutput> {
|
|
57
|
+
// Validate regex if provided
|
|
58
|
+
if (input.regex) {
|
|
59
|
+
try {
|
|
60
|
+
new RegExp(input.query);
|
|
61
|
+
} catch {
|
|
62
|
+
return Promise.resolve({
|
|
63
|
+
results: [],
|
|
64
|
+
count: 0,
|
|
65
|
+
error: `Invalid regex pattern: "${input.query}"`,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const results = storage.search({
|
|
71
|
+
query: input.query,
|
|
72
|
+
regex: input.regex,
|
|
73
|
+
projectMarker: input.projectMarker,
|
|
74
|
+
level: input.level,
|
|
75
|
+
limit: input.limit ?? 100,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
return Promise.resolve({
|
|
79
|
+
results,
|
|
80
|
+
count: results.length,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Tool definition for MCP registration.
|
|
86
|
+
*/
|
|
87
|
+
export const logsSearchTool = {
|
|
88
|
+
name: "logs_search",
|
|
89
|
+
description:
|
|
90
|
+
"Search logs by text pattern. " +
|
|
91
|
+
"By default, searches are case-insensitive substrings (e.g., 'error' matches 'TypeError'). " +
|
|
92
|
+
"Use regex: true for regex patterns (e.g., 'user:\\d+' to match 'user:123'). " +
|
|
93
|
+
"More flexible than logs_get_errors when you need to find specific messages.",
|
|
94
|
+
inputSchema: logsSearchInputSchema,
|
|
95
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* logs_status MCP tool implementation.
|
|
3
|
+
*
|
|
4
|
+
* Returns server status including health metrics and HTTP endpoint configuration.
|
|
5
|
+
* @module mcp/tools/logs-status
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as z from "zod/v3";
|
|
9
|
+
|
|
10
|
+
import type { LogStorage, ServerStatus } from "../../server/log-storage.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Input schema for the logs_status tool.
|
|
14
|
+
*/
|
|
15
|
+
export const logsStatusInputSchema = z.object({});
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Input type for the logs_status handler.
|
|
19
|
+
*/
|
|
20
|
+
export type LogsStatusInput = z.infer<typeof logsStatusInputSchema>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Output type for the logs_status handler.
|
|
24
|
+
*/
|
|
25
|
+
export interface LogsStatusOutput extends ServerStatus {
|
|
26
|
+
/** Memory usage information */
|
|
27
|
+
memoryUsage: {
|
|
28
|
+
heapUsed: number;
|
|
29
|
+
heapTotal: number;
|
|
30
|
+
rss: number;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Handler for the logs_status tool.
|
|
36
|
+
*
|
|
37
|
+
* Returns the full status of the log server, including health metrics,
|
|
38
|
+
* HTTP endpoint configuration, and memory usage.
|
|
39
|
+
* @param storage - The log storage instance
|
|
40
|
+
* @returns Server status object
|
|
41
|
+
*/
|
|
42
|
+
export function logsStatusHandler(storage: LogStorage): Promise<LogsStatusOutput> {
|
|
43
|
+
const status = storage.getStatus();
|
|
44
|
+
const memUsage = process.memoryUsage();
|
|
45
|
+
|
|
46
|
+
return Promise.resolve({
|
|
47
|
+
...status,
|
|
48
|
+
memoryUsage: {
|
|
49
|
+
heapUsed: memUsage.heapUsed,
|
|
50
|
+
heapTotal: memUsage.heapTotal,
|
|
51
|
+
rss: memUsage.rss,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Tool definition for MCP registration.
|
|
58
|
+
*/
|
|
59
|
+
export const logsStatusTool = {
|
|
60
|
+
name: "logs_status",
|
|
61
|
+
description:
|
|
62
|
+
"Get the status of the remote log server. " +
|
|
63
|
+
"Returns health metrics (uptime, session count, log count, memory usage), " +
|
|
64
|
+
"HTTP endpoint configuration (port, host, URL for browser clients), " +
|
|
65
|
+
"and retention settings (how long logs are kept before automatic cleanup). " +
|
|
66
|
+
"Use this to verify the server is running, find the endpoint URL for configuring browser clients, " +
|
|
67
|
+
"or check server configuration.",
|
|
68
|
+
inputSchema: logsStatusInputSchema,
|
|
69
|
+
};
|