@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.
Files changed (138) hide show
  1. package/README.md +944 -28
  2. package/bin/remote-log-server.js +3 -0
  3. package/dist/client/RemoteLogClient.d.ts +116 -0
  4. package/dist/client/RemoteLogClient.d.ts.map +1 -0
  5. package/dist/client/RemoteLogClient.js +269 -0
  6. package/dist/client/RemoteLogClient.js.map +1 -0
  7. package/dist/client/index.d.ts +7 -0
  8. package/dist/client/index.d.ts.map +1 -0
  9. package/dist/client/index.js +6 -0
  10. package/dist/client/index.js.map +1 -0
  11. package/dist/client/types.d.ts +60 -0
  12. package/dist/client/types.d.ts.map +1 -0
  13. package/dist/client/types.js +6 -0
  14. package/dist/client/types.js.map +1 -0
  15. package/dist/index.d.ts +22 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +23 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/mcp/index.d.ts +9 -0
  20. package/dist/mcp/index.d.ts.map +1 -0
  21. package/dist/mcp/index.js +9 -0
  22. package/dist/mcp/index.js.map +1 -0
  23. package/dist/mcp/mcp-server.d.ts +32 -0
  24. package/dist/mcp/mcp-server.d.ts.map +1 -0
  25. package/dist/mcp/mcp-server.js +270 -0
  26. package/dist/mcp/mcp-server.js.map +1 -0
  27. package/dist/mcp/tools/index.d.ts +14 -0
  28. package/dist/mcp/tools/index.d.ts.map +1 -0
  29. package/dist/mcp/tools/index.js +14 -0
  30. package/dist/mcp/tools/index.js.map +1 -0
  31. package/dist/mcp/tools/logs-clear.d.ts +76 -0
  32. package/dist/mcp/tools/logs-clear.d.ts.map +1 -0
  33. package/dist/mcp/tools/logs-clear.js +58 -0
  34. package/dist/mcp/tools/logs-clear.js.map +1 -0
  35. package/dist/mcp/tools/logs-get-all.d.ts +60 -0
  36. package/dist/mcp/tools/logs-get-all.d.ts.map +1 -0
  37. package/dist/mcp/tools/logs-get-all.js +50 -0
  38. package/dist/mcp/tools/logs-get-all.js.map +1 -0
  39. package/dist/mcp/tools/logs-get-errors.d.ts +65 -0
  40. package/dist/mcp/tools/logs-get-errors.d.ts.map +1 -0
  41. package/dist/mcp/tools/logs-get-errors.js +46 -0
  42. package/dist/mcp/tools/logs-get-errors.js.map +1 -0
  43. package/dist/mcp/tools/logs-get-file-path.d.ts +75 -0
  44. package/dist/mcp/tools/logs-get-file-path.d.ts.map +1 -0
  45. package/dist/mcp/tools/logs-get-file-path.js +90 -0
  46. package/dist/mcp/tools/logs-get-file-path.js.map +1 -0
  47. package/dist/mcp/tools/logs-get-recent.d.ts +89 -0
  48. package/dist/mcp/tools/logs-get-recent.d.ts.map +1 -0
  49. package/dist/mcp/tools/logs-get-recent.js +74 -0
  50. package/dist/mcp/tools/logs-get-recent.js.map +1 -0
  51. package/dist/mcp/tools/logs-list-sessions.d.ts +64 -0
  52. package/dist/mcp/tools/logs-list-sessions.d.ts.map +1 -0
  53. package/dist/mcp/tools/logs-list-sessions.js +48 -0
  54. package/dist/mcp/tools/logs-list-sessions.js.map +1 -0
  55. package/dist/mcp/tools/logs-receive.d.ts +150 -0
  56. package/dist/mcp/tools/logs-receive.d.ts.map +1 -0
  57. package/dist/mcp/tools/logs-receive.js +68 -0
  58. package/dist/mcp/tools/logs-receive.js.map +1 -0
  59. package/dist/mcp/tools/logs-search.d.ts +91 -0
  60. package/dist/mcp/tools/logs-search.d.ts.map +1 -0
  61. package/dist/mcp/tools/logs-search.js +68 -0
  62. package/dist/mcp/tools/logs-search.js.map +1 -0
  63. package/dist/mcp/tools/logs-status.d.ts +45 -0
  64. package/dist/mcp/tools/logs-status.d.ts.map +1 -0
  65. package/dist/mcp/tools/logs-status.js +45 -0
  66. package/dist/mcp/tools/logs-status.js.map +1 -0
  67. package/dist/server/dual-server.d.ts +76 -0
  68. package/dist/server/dual-server.d.ts.map +1 -0
  69. package/dist/server/dual-server.js +214 -0
  70. package/dist/server/dual-server.js.map +1 -0
  71. package/dist/server/index.d.ts +12 -0
  72. package/dist/server/index.d.ts.map +1 -0
  73. package/dist/server/index.js +12 -0
  74. package/dist/server/index.js.map +1 -0
  75. package/dist/server/jsonl-writer.d.ts +93 -0
  76. package/dist/server/jsonl-writer.d.ts.map +1 -0
  77. package/dist/server/jsonl-writer.js +205 -0
  78. package/dist/server/jsonl-writer.js.map +1 -0
  79. package/dist/server/log-server.d.ts +126 -0
  80. package/dist/server/log-server.d.ts.map +1 -0
  81. package/dist/server/log-server.js +589 -0
  82. package/dist/server/log-server.js.map +1 -0
  83. package/dist/server/log-storage.d.ts +301 -0
  84. package/dist/server/log-storage.d.ts.map +1 -0
  85. package/dist/server/log-storage.js +408 -0
  86. package/dist/server/log-storage.js.map +1 -0
  87. package/dist/server/marker-utils.d.ts +69 -0
  88. package/dist/server/marker-utils.d.ts.map +1 -0
  89. package/dist/server/marker-utils.js +118 -0
  90. package/dist/server/marker-utils.js.map +1 -0
  91. package/dist/server/self-signed-cert.d.ts +30 -0
  92. package/dist/server/self-signed-cert.d.ts.map +1 -0
  93. package/dist/server/self-signed-cert.js +83 -0
  94. package/dist/server/self-signed-cert.js.map +1 -0
  95. package/dist/ui/ConsoleCaptureUI.d.ts +118 -0
  96. package/dist/ui/ConsoleCaptureUI.d.ts.map +1 -0
  97. package/dist/ui/ConsoleCaptureUI.js +571 -0
  98. package/dist/ui/ConsoleCaptureUI.js.map +1 -0
  99. package/dist/ui/index.d.ts +15 -0
  100. package/dist/ui/index.d.ts.map +1 -0
  101. package/dist/ui/index.js +15 -0
  102. package/dist/ui/index.js.map +1 -0
  103. package/dist/vite/index.d.ts +8 -0
  104. package/dist/vite/index.d.ts.map +1 -0
  105. package/dist/vite/index.js +8 -0
  106. package/dist/vite/index.js.map +1 -0
  107. package/dist/vite/plugin.d.ts +42 -0
  108. package/dist/vite/plugin.d.ts.map +1 -0
  109. package/dist/vite/plugin.js +46 -0
  110. package/dist/vite/plugin.js.map +1 -0
  111. package/package.json +90 -7
  112. package/src/client/RemoteLogClient.ts +328 -0
  113. package/src/client/index.ts +7 -0
  114. package/src/client/types.ts +62 -0
  115. package/src/index.ts +28 -0
  116. package/src/mcp/index.ts +25 -0
  117. package/src/mcp/mcp-server.ts +364 -0
  118. package/src/mcp/tools/index.ts +69 -0
  119. package/src/mcp/tools/logs-clear.ts +86 -0
  120. package/src/mcp/tools/logs-get-all.ts +78 -0
  121. package/src/mcp/tools/logs-get-errors.ts +71 -0
  122. package/src/mcp/tools/logs-get-file-path.ts +121 -0
  123. package/src/mcp/tools/logs-get-recent.ts +104 -0
  124. package/src/mcp/tools/logs-list-sessions.ts +71 -0
  125. package/src/mcp/tools/logs-receive.ts +96 -0
  126. package/src/mcp/tools/logs-search.ts +95 -0
  127. package/src/mcp/tools/logs-status.ts +69 -0
  128. package/src/server/dual-server.ts +308 -0
  129. package/src/server/index.ts +54 -0
  130. package/src/server/jsonl-writer.ts +277 -0
  131. package/src/server/log-server.ts +763 -0
  132. package/src/server/log-storage.ts +651 -0
  133. package/src/server/marker-utils.ts +144 -0
  134. package/src/server/self-signed-cert.ts +93 -0
  135. package/src/ui/ConsoleCaptureUI.ts +649 -0
  136. package/src/ui/index.ts +15 -0
  137. package/src/vite/index.ts +8 -0
  138. package/src/vite/plugin.ts +59 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logs-receive.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools/logs-receive.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAE5B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAgB9D;;GAEG;AACH,eAAO,MAAM,sBAAsB;IAC/B,+EAA+E;;IAE/E,kEAAkE;;QAhBlE,iFAAiF;;QAEjF,+DAA+D;;QAE/D,4BAA4B;;QAE5B,6DAA6D;;;;;;;;;;;;;IAY7D,uFAAuF;;IAEvF,oDAAoD;;IAEpD,iDAAiD;;;;;;;;;;;;;;;;;;;;;;;;EAEnD,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAEtE;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAC9B,sCAAsC;IACtC,OAAO,EAAE,OAAO,CAAC;IACjB,4BAA4B;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,0BAA0B;IAC1B,SAAS,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAC9B,OAAO,EAAE,UAAU,EACnB,KAAK,EAAE,gBAAgB,GACxB,OAAO,CAAC,iBAAiB,CAAC,CAY5B;AAED;;GAEG;AACH,eAAO,MAAM,eAAe;;;;QA1DxB,+EAA+E;;QAE/E,kEAAkE;;YAhBlE,iFAAiF;;YAEjF,+DAA+D;;YAE/D,4BAA4B;;YAE5B,6DAA6D;;;;;;;;;;;;;QAY7D,uFAAuF;;QAEvF,oDAAoD;;QAEpD,iDAAiD;;;;;;;;;;;;;;;;;;;;;;;;;CA0DpD,CAAC"}
@@ -0,0 +1,68 @@
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
+ import * as z from "zod/v3";
8
+ /**
9
+ * Schema for a single log entry.
10
+ */
11
+ const logEntrySchema = z.object({
12
+ /** When the log was created. Format: ISO 8601 (e.g., "2025-01-08T12:00:00Z"). */
13
+ time: z.string(),
14
+ /** Severity level (e.g., "INFO", "DEBUG", "WARN", "ERROR"). */
15
+ level: z.string(),
16
+ /** The log message text. */
17
+ message: z.string(),
18
+ /** Additional structured data to attach to the log entry. */
19
+ data: z.record(z.unknown()).optional(),
20
+ });
21
+ /**
22
+ * Input schema for the logs_receive tool.
23
+ */
24
+ export const logsReceiveInputSchema = z.object({
25
+ /** Unique identifier for this logging session. Links related logs together. */
26
+ sessionId: z.string(),
27
+ /** Array of log entries to store. At least one entry required. */
28
+ logs: z.array(logEntrySchema),
29
+ /** Project identifier for filtering. Derived from sessionId prefix if not provided. */
30
+ projectMarker: z.string().optional(),
31
+ /** Git worktree path for project identification. */
32
+ worktreePath: z.string().optional(),
33
+ /** URL of the page that generated these logs. */
34
+ pageUrl: z.string().optional(),
35
+ });
36
+ /**
37
+ * Handler for the logs_receive tool.
38
+ *
39
+ * Stores logs with session metadata. The project marker is derived from
40
+ * the session ID prefix if not explicitly provided.
41
+ * @param storage - The log storage instance
42
+ * @param input - Input parameters
43
+ * @returns Success status, count, and session ID
44
+ */
45
+ export function logsReceiveHandler(storage, input) {
46
+ storage.addLogs(input.sessionId, input.logs, {
47
+ projectMarker: input.projectMarker,
48
+ worktreePath: input.worktreePath,
49
+ pageUrl: input.pageUrl,
50
+ });
51
+ return Promise.resolve({
52
+ success: true,
53
+ count: input.logs.length,
54
+ sessionId: input.sessionId,
55
+ });
56
+ }
57
+ /**
58
+ * Tool definition for MCP registration.
59
+ */
60
+ export const logsReceiveTool = {
61
+ name: "logs_receive",
62
+ description: "Store logs from a browser or application session. " +
63
+ "Logs are associated with a session ID and can be filtered by project marker. " +
64
+ "This tool is called by browser clients to send logs to the server. " +
65
+ "You typically don't need to call this directly - use it when manually testing log ingestion.",
66
+ inputSchema: logsReceiveInputSchema,
67
+ };
68
+ //# sourceMappingURL=logs-receive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logs-receive.js","sourceRoot":"","sources":["../../../src/mcp/tools/logs-receive.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAI5B;;GAEG;AACH,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5B,iFAAiF;IACjF,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,+DAA+D;IAC/D,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,4BAA4B;IAC5B,OAAO,EAAE,CAAC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 -0,0 +1,91 @@
1
+ /**
2
+ * logs_search MCP tool implementation.
3
+ *
4
+ * Searches logs by substring or regex pattern.
5
+ * @module mcp/tools/logs-search
6
+ */
7
+ import * as z from "zod/v3";
8
+ import type { LogEntryWithSession, LogStorage } from "../../server/log-storage.js";
9
+ /**
10
+ * Input schema for the logs_search tool.
11
+ */
12
+ export declare const logsSearchInputSchema: z.ZodObject<{
13
+ /** The text pattern to search for in log messages. */
14
+ query: z.ZodString;
15
+ /** When true, treat query as a regular expression. Default: false (substring match). */
16
+ regex: z.ZodOptional<z.ZodBoolean>;
17
+ /** Filter results to a specific project identifier. Searches all projects if omitted. */
18
+ projectMarker: z.ZodOptional<z.ZodString>;
19
+ /** Filter by log level (e.g., "INFO", "ERROR"). Case-sensitive. */
20
+ level: z.ZodOptional<z.ZodString>;
21
+ /** Maximum number of results to return. Defaults to 100. Range: 1-1000. */
22
+ limit: z.ZodOptional<z.ZodNumber>;
23
+ }, "strip", z.ZodTypeAny, {
24
+ query: string;
25
+ level?: string | undefined;
26
+ projectMarker?: string | undefined;
27
+ regex?: boolean | undefined;
28
+ limit?: number | undefined;
29
+ }, {
30
+ query: string;
31
+ level?: string | undefined;
32
+ projectMarker?: string | undefined;
33
+ regex?: boolean | undefined;
34
+ limit?: number | undefined;
35
+ }>;
36
+ /**
37
+ * Input type for the logs_search handler.
38
+ */
39
+ export type LogsSearchInput = z.infer<typeof logsSearchInputSchema>;
40
+ /**
41
+ * Output type for the logs_search handler.
42
+ */
43
+ export interface LogsSearchOutput {
44
+ /** Matching log entries */
45
+ results: LogEntryWithSession[];
46
+ /** Number of results returned */
47
+ count: number;
48
+ /** Error message if regex is invalid */
49
+ error?: string;
50
+ }
51
+ /**
52
+ * Handler for the logs_search tool.
53
+ *
54
+ * Searches log messages by substring (case-insensitive) or regex pattern.
55
+ * @param storage - The log storage instance
56
+ * @param input - Input parameters
57
+ * @returns Matching logs and count
58
+ */
59
+ export declare function logsSearchHandler(storage: LogStorage, input: LogsSearchInput): Promise<LogsSearchOutput>;
60
+ /**
61
+ * Tool definition for MCP registration.
62
+ */
63
+ export declare const logsSearchTool: {
64
+ name: string;
65
+ description: string;
66
+ inputSchema: z.ZodObject<{
67
+ /** The text pattern to search for in log messages. */
68
+ query: z.ZodString;
69
+ /** When true, treat query as a regular expression. Default: false (substring match). */
70
+ regex: z.ZodOptional<z.ZodBoolean>;
71
+ /** Filter results to a specific project identifier. Searches all projects if omitted. */
72
+ projectMarker: z.ZodOptional<z.ZodString>;
73
+ /** Filter by log level (e.g., "INFO", "ERROR"). Case-sensitive. */
74
+ level: z.ZodOptional<z.ZodString>;
75
+ /** Maximum number of results to return. Defaults to 100. Range: 1-1000. */
76
+ limit: z.ZodOptional<z.ZodNumber>;
77
+ }, "strip", z.ZodTypeAny, {
78
+ query: string;
79
+ level?: string | undefined;
80
+ projectMarker?: string | undefined;
81
+ regex?: boolean | undefined;
82
+ limit?: number | undefined;
83
+ }, {
84
+ query: string;
85
+ level?: string | undefined;
86
+ projectMarker?: string | undefined;
87
+ regex?: boolean | undefined;
88
+ limit?: number | undefined;
89
+ }>;
90
+ };
91
+ //# sourceMappingURL=logs-search.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logs-search.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools/logs-search.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAE5B,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEnF;;GAEG;AACH,eAAO,MAAM,qBAAqB;IAC9B,sDAAsD;;IAEtD,wFAAwF;;IAExF,yFAAyF;;IAEzF,mEAAmE;;IAEnE,2EAA2E;;;;;;;;;;;;;;EAE7E,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,2BAA2B;IAC3B,OAAO,EAAE,mBAAmB,EAAE,CAAC;IAC/B,iCAAiC;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,wCAAwC;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC7B,OAAO,EAAE,UAAU,EACnB,KAAK,EAAE,eAAe,GACvB,OAAO,CAAC,gBAAgB,CAAC,CA0B3B;AAED;;GAEG;AACH,eAAO,MAAM,cAAc;;;;QAvEvB,sDAAsD;;QAEtD,wFAAwF;;QAExF,yFAAyF;;QAEzF,mEAAmE;;QAEnE,2EAA2E;;;;;;;;;;;;;;;CAuE9E,CAAC"}
@@ -0,0 +1,68 @@
1
+ /**
2
+ * logs_search MCP tool implementation.
3
+ *
4
+ * Searches logs by substring or regex pattern.
5
+ * @module mcp/tools/logs-search
6
+ */
7
+ import * as z from "zod/v3";
8
+ /**
9
+ * Input schema for the logs_search tool.
10
+ */
11
+ export const logsSearchInputSchema = z.object({
12
+ /** The text pattern to search for in log messages. */
13
+ query: z.string(),
14
+ /** When true, treat query as a regular expression. Default: false (substring match). */
15
+ regex: z.boolean().optional(),
16
+ /** Filter results to a specific project identifier. Searches all projects if omitted. */
17
+ projectMarker: z.string().optional(),
18
+ /** Filter by log level (e.g., "INFO", "ERROR"). Case-sensitive. */
19
+ level: z.string().optional(),
20
+ /** Maximum number of results to return. Defaults to 100. Range: 1-1000. */
21
+ limit: z.number().int().min(1).max(1000).optional(),
22
+ });
23
+ /**
24
+ * Handler for the logs_search tool.
25
+ *
26
+ * Searches log messages by substring (case-insensitive) or regex pattern.
27
+ * @param storage - The log storage instance
28
+ * @param input - Input parameters
29
+ * @returns Matching logs and count
30
+ */
31
+ export function logsSearchHandler(storage, input) {
32
+ // Validate regex if provided
33
+ if (input.regex) {
34
+ try {
35
+ new RegExp(input.query);
36
+ }
37
+ catch {
38
+ return Promise.resolve({
39
+ results: [],
40
+ count: 0,
41
+ error: `Invalid regex pattern: "${input.query}"`,
42
+ });
43
+ }
44
+ }
45
+ const results = storage.search({
46
+ query: input.query,
47
+ regex: input.regex,
48
+ projectMarker: input.projectMarker,
49
+ level: input.level,
50
+ limit: input.limit ?? 100,
51
+ });
52
+ return Promise.resolve({
53
+ results,
54
+ count: results.length,
55
+ });
56
+ }
57
+ /**
58
+ * Tool definition for MCP registration.
59
+ */
60
+ export const logsSearchTool = {
61
+ name: "logs_search",
62
+ description: "Search logs by text pattern. " +
63
+ "By default, searches are case-insensitive substrings (e.g., 'error' matches 'TypeError'). " +
64
+ "Use regex: true for regex patterns (e.g., 'user:\\d+' to match 'user:123'). " +
65
+ "More flexible than logs_get_errors when you need to find specific messages.",
66
+ inputSchema: logsSearchInputSchema,
67
+ };
68
+ //# sourceMappingURL=logs-search.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logs-search.js","sourceRoot":"","sources":["../../../src/mcp/tools/logs-search.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAI5B;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,sDAAsD;IACtD,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,wFAAwF;IACxF,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAC7B,yFAAyF;IACzF,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACpC,mEAAmE;IACnE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC5B,2EAA2E;IAC3E,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE;CACtD,CAAC,CAAC;AAmBH;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAC7B,OAAmB,EACnB,KAAsB;IAEtB,6BAA6B;IAC7B,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QACd,IAAI,CAAC;YACD,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC5B,CAAC;QAAC,MAAM,CAAC;YACL,OAAO,OAAO,CAAC,OAAO,CAAC;gBACnB,OAAO,EAAE,EAAE;gBACX,KAAK,EAAE,CAAC;gBACR,KAAK,EAAE,2BAA2B,KAAK,CAAC,KAAK,GAAG;aACnD,CAAC,CAAC;QACP,CAAC;IACL,CAAC;IAED,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;QAC3B,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,aAAa,EAAE,KAAK,CAAC,aAAa;QAClC,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,KAAK,EAAE,KAAK,CAAC,KAAK,IAAI,GAAG;KAC5B,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,OAAO,CAAC;QACnB,OAAO;QACP,KAAK,EAAE,OAAO,CAAC,MAAM;KACxB,CAAC,CAAC;AACP,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC1B,IAAI,EAAE,aAAa;IACnB,WAAW,EACP,+BAA+B;QAC/B,4FAA4F;QAC5F,8EAA8E;QAC9E,6EAA6E;IACjF,WAAW,EAAE,qBAAqB;CACrC,CAAC"}
@@ -0,0 +1,45 @@
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
+ import * as z from "zod/v3";
8
+ import type { LogStorage, ServerStatus } from "../../server/log-storage.js";
9
+ /**
10
+ * Input schema for the logs_status tool.
11
+ */
12
+ export declare const logsStatusInputSchema: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
13
+ /**
14
+ * Input type for the logs_status handler.
15
+ */
16
+ export type LogsStatusInput = z.infer<typeof logsStatusInputSchema>;
17
+ /**
18
+ * Output type for the logs_status handler.
19
+ */
20
+ export interface LogsStatusOutput extends ServerStatus {
21
+ /** Memory usage information */
22
+ memoryUsage: {
23
+ heapUsed: number;
24
+ heapTotal: number;
25
+ rss: number;
26
+ };
27
+ }
28
+ /**
29
+ * Handler for the logs_status tool.
30
+ *
31
+ * Returns the full status of the log server, including health metrics,
32
+ * HTTP endpoint configuration, and memory usage.
33
+ * @param storage - The log storage instance
34
+ * @returns Server status object
35
+ */
36
+ export declare function logsStatusHandler(storage: LogStorage): Promise<LogsStatusOutput>;
37
+ /**
38
+ * Tool definition for MCP registration.
39
+ */
40
+ export declare const logsStatusTool: {
41
+ name: string;
42
+ description: string;
43
+ inputSchema: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
44
+ };
45
+ //# sourceMappingURL=logs-status.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logs-status.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools/logs-status.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAE5B,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAE5E;;GAEG;AACH,eAAO,MAAM,qBAAqB,gDAAe,CAAC;AAElD;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAAQ,YAAY;IAClD,+BAA+B;IAC/B,WAAW,EAAE;QACT,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;QAClB,GAAG,EAAE,MAAM,CAAC;KACf,CAAC;CACL;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAYhF;AAED;;GAEG;AACH,eAAO,MAAM,cAAc;;;;CAU1B,CAAC"}
@@ -0,0 +1,45 @@
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
+ import * as z from "zod/v3";
8
+ /**
9
+ * Input schema for the logs_status tool.
10
+ */
11
+ export const logsStatusInputSchema = z.object({});
12
+ /**
13
+ * Handler for the logs_status tool.
14
+ *
15
+ * Returns the full status of the log server, including health metrics,
16
+ * HTTP endpoint configuration, and memory usage.
17
+ * @param storage - The log storage instance
18
+ * @returns Server status object
19
+ */
20
+ export function logsStatusHandler(storage) {
21
+ const status = storage.getStatus();
22
+ const memUsage = process.memoryUsage();
23
+ return Promise.resolve({
24
+ ...status,
25
+ memoryUsage: {
26
+ heapUsed: memUsage.heapUsed,
27
+ heapTotal: memUsage.heapTotal,
28
+ rss: memUsage.rss,
29
+ },
30
+ });
31
+ }
32
+ /**
33
+ * Tool definition for MCP registration.
34
+ */
35
+ export const logsStatusTool = {
36
+ name: "logs_status",
37
+ description: "Get the status of the remote log server. " +
38
+ "Returns health metrics (uptime, session count, log count, memory usage), " +
39
+ "HTTP endpoint configuration (port, host, URL for browser clients), " +
40
+ "and retention settings (how long logs are kept before automatic cleanup). " +
41
+ "Use this to verify the server is running, find the endpoint URL for configuring browser clients, " +
42
+ "or check server configuration.",
43
+ inputSchema: logsStatusInputSchema,
44
+ };
45
+ //# sourceMappingURL=logs-status.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logs-status.js","sourceRoot":"","sources":["../../../src/mcp/tools/logs-status.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAI5B;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAmBlD;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAmB;IACjD,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IACnC,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAEvC,OAAO,OAAO,CAAC,OAAO,CAAC;QACnB,GAAG,MAAM;QACT,WAAW,EAAE;YACT,QAAQ,EAAE,QAAQ,CAAC,QAAQ;YAC3B,SAAS,EAAE,QAAQ,CAAC,SAAS;YAC7B,GAAG,EAAE,QAAQ,CAAC,GAAG;SACpB;KACJ,CAAC,CAAC;AACP,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC1B,IAAI,EAAE,aAAa;IACnB,WAAW,EACP,2CAA2C;QAC3C,2EAA2E;QAC3E,qEAAqE;QACrE,4EAA4E;QAC5E,mGAAmG;QACnG,gCAAgC;IACpC,WAAW,EAAE,qBAAqB;CACrC,CAAC"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Dual server orchestration for running HTTP and MCP interfaces simultaneously.
3
+ *
4
+ * This module provides a unified way to start both HTTP and MCP servers
5
+ * that share the same log storage instance.
6
+ * @module server/dual-server
7
+ */
8
+ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
9
+ import type * as http from "http";
10
+ import type * as https from "https";
11
+ import { JsonlWriter } from "./jsonl-writer.js";
12
+ import { LogStorage } from "./log-storage.js";
13
+ /**
14
+ * Find an available port starting from the given base port.
15
+ * Increments port number until an available port is found.
16
+ * @param basePort - Starting port number
17
+ * @param host - Host to bind to
18
+ * @param quiet - Suppress output messages
19
+ * @returns Promise resolving to available port number
20
+ * @throws Error if no available port found within MAX_PORT_SCAN_ATTEMPTS
21
+ */
22
+ export declare function findAvailablePort(basePort: number, host: string, quiet?: boolean): Promise<number>;
23
+ /**
24
+ * Options for creating a dual server.
25
+ */
26
+ export interface DualServerOptions {
27
+ /** Port for HTTP server (default: 9080) */
28
+ httpPort?: number;
29
+ /** Host for HTTP server (default: localhost) */
30
+ httpHost?: string;
31
+ /** Enable MCP server (default: true) */
32
+ mcpEnabled?: boolean;
33
+ /** Enable HTTP server (default: true) */
34
+ httpEnabled?: boolean;
35
+ /** Suppress terminal output (default: false) */
36
+ quiet?: boolean;
37
+ /** Path to SSL certificate file (HTTPS only used if both certPath and keyPath provided) */
38
+ certPath?: string;
39
+ /** Path to SSL private key file (HTTPS only used if both certPath and keyPath provided) */
40
+ keyPath?: string;
41
+ /** Path to file for writing logs (optional) */
42
+ logFile?: string;
43
+ /** External LogStorage instance (optional, will create one if not provided) */
44
+ storage?: LogStorage;
45
+ /** External JSONL writer instance (optional, will create one if not provided) */
46
+ jsonlWriter?: JsonlWriter;
47
+ /** Only serve /log POST and /health GET endpoints (default: false) */
48
+ logReceiveOnly?: boolean;
49
+ }
50
+ /**
51
+ * Result of creating a dual server.
52
+ */
53
+ export interface DualServerResult {
54
+ /** HTTP or HTTPS server instance (if httpEnabled) */
55
+ httpServer?: http.Server | https.Server;
56
+ /** MCP server instance (if mcpEnabled) */
57
+ mcpServer?: McpServer;
58
+ /** Shared log storage instance */
59
+ storage: LogStorage;
60
+ /** JSONL writer instance */
61
+ jsonlWriter?: JsonlWriter;
62
+ /** Actual HTTP port used (may differ from requested if port was in use) */
63
+ httpPort?: number;
64
+ /** Graceful shutdown function */
65
+ shutdown: () => Promise<void>;
66
+ }
67
+ /**
68
+ * Create and start a dual server with HTTP and/or MCP interfaces.
69
+ *
70
+ * By default, both HTTP and MCP are enabled. Use httpEnabled/mcpEnabled
71
+ * to control which interfaces to start.
72
+ * @param options - Server configuration options
73
+ * @returns Promise resolving to the dual server result
74
+ */
75
+ export declare function createDualServer(options?: DualServerOptions): Promise<DualServerResult>;
76
+ //# sourceMappingURL=dual-server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dual-server.d.ts","sourceRoot":"","sources":["../../src/server/dual-server.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO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CAAC;IACpB,4BAA4B;IAC5B,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACjC;AAED;;;;;;;GAOG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAoIjG"}
@@ -0,0 +1,214 @@
1
+ /**
2
+ * Dual server orchestration for running HTTP and MCP interfaces simultaneously.
3
+ *
4
+ * This module provides a unified way to start both HTTP and MCP servers
5
+ * that share the same log storage instance.
6
+ * @module server/dual-server
7
+ */
8
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
9
+ import * as net from "net";
10
+ import * as os from "os";
11
+ import * as path from "path";
12
+ import { createMcpServer } from "../mcp/mcp-server.js";
13
+ import { JsonlWriter } from "./jsonl-writer.js";
14
+ import { createLogServer } from "./log-server.js";
15
+ import { LogStorage } from "./log-storage.js";
16
+ import { certFilesExist } from "./self-signed-cert.js";
17
+ // ANSI color codes for terminal output
18
+ const colors = {
19
+ reset: "\x1b[0m",
20
+ yellow: "\x1b[33m",
21
+ red: "\x1b[31m",
22
+ green: "\x1b[32m",
23
+ cyan: "\x1b[36m",
24
+ };
25
+ /** Maximum number of ports to try when scanning for available port */
26
+ const MAX_PORT_SCAN_ATTEMPTS = 100;
27
+ /** Maximum port number allowed (ports 9000-9099 per project guidelines) */
28
+ const MAX_PORT_NUMBER = 9099;
29
+ /**
30
+ * Check if a port is available for binding.
31
+ * @param port - Port number to check
32
+ * @param host - Host to bind to
33
+ * @returns Promise resolving to true if port is available, false otherwise
34
+ */
35
+ async function isPortAvailable(port, host) {
36
+ return new Promise((resolve) => {
37
+ const server = net.createServer();
38
+ // Enable SO_REUSEADDR to allow faster port reuse after server shutdown
39
+ server.once("error", (err) => {
40
+ if (err.code === "EADDRINUSE") {
41
+ resolve(false);
42
+ }
43
+ else {
44
+ // Other errors (permission, etc.) - port is not usable
45
+ resolve(false);
46
+ }
47
+ });
48
+ server.once("listening", () => {
49
+ server.close(() => {
50
+ resolve(true);
51
+ });
52
+ });
53
+ // Set SO_REUSEADDR before binding
54
+ server.listen({ port, host, exclusive: false });
55
+ });
56
+ }
57
+ /**
58
+ * Find an available port starting from the given base port.
59
+ * Increments port number until an available port is found.
60
+ * @param basePort - Starting port number
61
+ * @param host - Host to bind to
62
+ * @param quiet - Suppress output messages
63
+ * @returns Promise resolving to available port number
64
+ * @throws Error if no available port found within MAX_PORT_SCAN_ATTEMPTS
65
+ */
66
+ export async function findAvailablePort(basePort, host, quiet = false) {
67
+ let port = basePort;
68
+ let attempts = 0;
69
+ while (attempts < MAX_PORT_SCAN_ATTEMPTS) {
70
+ if (port > MAX_PORT_NUMBER) {
71
+ // Wrap around if we exceed max port (shouldn't happen normally)
72
+ break;
73
+ }
74
+ if (await isPortAvailable(port, host)) {
75
+ if (port !== basePort && !quiet) {
76
+ // eslint-disable-next-line no-console
77
+ console.log(`${colors.yellow}Port ${basePort} in use, using port ${port} instead${colors.reset}`);
78
+ }
79
+ return port;
80
+ }
81
+ if (!quiet && attempts === 0) {
82
+ // eslint-disable-next-line no-console
83
+ console.log(`${colors.yellow}Port ${port} is already in use, scanning for available port...${colors.reset}`);
84
+ }
85
+ port++;
86
+ attempts++;
87
+ }
88
+ // No available port found
89
+ const errorMsg = `Could not find available port after ${MAX_PORT_SCAN_ATTEMPTS} attempts starting from ${basePort}. ` +
90
+ `Ports ${basePort}-${port - 1} are all in use. ` +
91
+ `Try killing existing processes: pkill -f "remote-log-server"`;
92
+ if (!quiet) {
93
+ console.error(`${colors.red}${errorMsg}${colors.reset}`);
94
+ }
95
+ throw new Error(errorMsg);
96
+ }
97
+ /**
98
+ * Create and start a dual server with HTTP and/or MCP interfaces.
99
+ *
100
+ * By default, both HTTP and MCP are enabled. Use httpEnabled/mcpEnabled
101
+ * to control which interfaces to start.
102
+ * @param options - Server configuration options
103
+ * @returns Promise resolving to the dual server result
104
+ */
105
+ export async function createDualServer(options = {}) {
106
+ const { httpPort: requestedPort = 9080, httpHost = "localhost", mcpEnabled = true, httpEnabled = true, quiet = false, storage: externalStorage, jsonlWriter: externalJsonlWriter, logReceiveOnly = false, certPath, keyPath, } = options;
107
+ // Create or use provided JSONL writer
108
+ const jsonlBaseDir = path.join(os.tmpdir(), "remote-logger");
109
+ const jsonlWriter = externalJsonlWriter ?? new JsonlWriter(jsonlBaseDir);
110
+ // Create or use provided storage
111
+ const storage = externalStorage ?? new LogStorage({ jsonlWriter });
112
+ let httpServer;
113
+ let mcpServer;
114
+ let actualHttpPort;
115
+ // Start HTTP server if enabled
116
+ if (httpEnabled) {
117
+ // Find an available port starting from the requested port
118
+ actualHttpPort = await findAvailablePort(requestedPort, httpHost, quiet);
119
+ const result = createLogServer({
120
+ port: actualHttpPort,
121
+ host: httpHost,
122
+ storage,
123
+ quiet,
124
+ logReceiveOnly,
125
+ certPath,
126
+ keyPath,
127
+ });
128
+ httpServer = result.server;
129
+ // Wait for HTTP server to be listening
130
+ const serverToStart = httpServer;
131
+ const portToUse = actualHttpPort;
132
+ await new Promise((resolve, reject) => {
133
+ serverToStart.on("error", (err) => {
134
+ // Provide helpful error message for port conflicts
135
+ if (err.code === "EADDRINUSE") {
136
+ const errorMsg = `Port ${portToUse} is already in use. ` +
137
+ `This shouldn't happen after port scanning - there may be a race condition. ` +
138
+ `Try again or kill existing processes: pkill -f "remote-log-server"`;
139
+ if (!quiet) {
140
+ console.error(`${colors.red}${errorMsg}${colors.reset}`);
141
+ }
142
+ reject(new Error(errorMsg));
143
+ }
144
+ else {
145
+ reject(err);
146
+ }
147
+ });
148
+ serverToStart.listen({ port: portToUse, host: httpHost, exclusive: false }, () => {
149
+ serverToStart.removeListener("error", reject);
150
+ if (!quiet) {
151
+ // eslint-disable-next-line no-console
152
+ console.log(`${colors.green}HTTP server listening on ${httpHost}:${portToUse}${colors.reset}`);
153
+ }
154
+ resolve();
155
+ });
156
+ });
157
+ // Set server config in storage so MCP tools can report it
158
+ // Determine protocol based on whether valid cert files were provided
159
+ const useHttps = certPath && keyPath && certFilesExist(certPath, keyPath);
160
+ const protocol = useHttps ? "https" : "http";
161
+ // Determine mode based on configuration
162
+ let mode;
163
+ if (logReceiveOnly && mcpEnabled) {
164
+ mode = "mcp-only";
165
+ }
166
+ else if (!mcpEnabled) {
167
+ mode = "http-only";
168
+ }
169
+ else {
170
+ mode = "dual";
171
+ }
172
+ storage.setServerConfig({
173
+ httpPort: actualHttpPort,
174
+ httpHost,
175
+ protocol,
176
+ httpEndpoint: `${protocol}://${httpHost}:${actualHttpPort}/log`,
177
+ mode,
178
+ });
179
+ }
180
+ // Create and connect MCP server if enabled
181
+ if (mcpEnabled) {
182
+ mcpServer = createMcpServer(storage);
183
+ const transport = new StdioServerTransport();
184
+ await mcpServer.connect(transport);
185
+ }
186
+ // Track if we created the JSONL writer internally
187
+ const ownsJsonlWriter = !externalJsonlWriter;
188
+ // Shutdown function
189
+ const shutdown = async () => {
190
+ // Close HTTP server
191
+ if (httpServer?.listening) {
192
+ await new Promise((resolve) => {
193
+ httpServer.close(() => { resolve(); });
194
+ });
195
+ }
196
+ // Close JSONL writer only if we created it internally
197
+ if (ownsJsonlWriter) {
198
+ await jsonlWriter.close();
199
+ }
200
+ // Stop cleanup timer if storage was created internally
201
+ if (!externalStorage) {
202
+ storage.stopCleanupTimer();
203
+ }
204
+ };
205
+ return {
206
+ httpServer,
207
+ mcpServer,
208
+ storage,
209
+ jsonlWriter,
210
+ httpPort: actualHttpPort,
211
+ shutdown,
212
+ };
213
+ }
214
+ //# sourceMappingURL=dual-server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dual-server.js","sourceRoot":"","sources":["../../src/server/dual-server.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAGjF,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