foundryvtt-mcp 0.11.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 (139) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +142 -0
  3. package/dist/character/manager.d.ts +92 -0
  4. package/dist/character/manager.d.ts.map +1 -0
  5. package/dist/character/manager.js +208 -0
  6. package/dist/character/manager.js.map +1 -0
  7. package/dist/combat/manager.d.ts +94 -0
  8. package/dist/combat/manager.d.ts.map +1 -0
  9. package/dist/combat/manager.js +373 -0
  10. package/dist/combat/manager.js.map +1 -0
  11. package/dist/config/index.d.ts +114 -0
  12. package/dist/config/index.d.ts.map +1 -0
  13. package/dist/config/index.js +177 -0
  14. package/dist/config/index.js.map +1 -0
  15. package/dist/diagnostics/client.d.ts +193 -0
  16. package/dist/diagnostics/client.d.ts.map +1 -0
  17. package/dist/diagnostics/client.js +314 -0
  18. package/dist/diagnostics/client.js.map +1 -0
  19. package/dist/diagnostics/types.d.ts +414 -0
  20. package/dist/diagnostics/types.d.ts.map +1 -0
  21. package/dist/diagnostics/types.js +94 -0
  22. package/dist/diagnostics/types.js.map +1 -0
  23. package/dist/foundry/auth.d.ts +19 -0
  24. package/dist/foundry/auth.d.ts.map +1 -0
  25. package/dist/foundry/auth.js +135 -0
  26. package/dist/foundry/auth.js.map +1 -0
  27. package/dist/foundry/client.d.ts +95 -0
  28. package/dist/foundry/client.d.ts.map +1 -0
  29. package/dist/foundry/client.js +692 -0
  30. package/dist/foundry/client.js.map +1 -0
  31. package/dist/foundry/types.d.ts +805 -0
  32. package/dist/foundry/types.d.ts.map +1 -0
  33. package/dist/foundry/types.js +13 -0
  34. package/dist/foundry/types.js.map +1 -0
  35. package/dist/index.d.ts +16 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +199 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/resources/index.d.ts +3 -0
  40. package/dist/resources/index.d.ts.map +1 -0
  41. package/dist/resources/index.js +93 -0
  42. package/dist/resources/index.js.map +1 -0
  43. package/dist/tools/base.d.ts +80 -0
  44. package/dist/tools/base.d.ts.map +1 -0
  45. package/dist/tools/base.js +73 -0
  46. package/dist/tools/base.js.map +1 -0
  47. package/dist/tools/definitions.d.ts +414 -0
  48. package/dist/tools/definitions.d.ts.map +1 -0
  49. package/dist/tools/definitions.js +429 -0
  50. package/dist/tools/definitions.js.map +1 -0
  51. package/dist/tools/handlers/actors.d.ts +31 -0
  52. package/dist/tools/handlers/actors.d.ts.map +1 -0
  53. package/dist/tools/handlers/actors.js +76 -0
  54. package/dist/tools/handlers/actors.js.map +1 -0
  55. package/dist/tools/handlers/chat.d.ts +13 -0
  56. package/dist/tools/handlers/chat.d.ts.map +1 -0
  57. package/dist/tools/handlers/chat.js +38 -0
  58. package/dist/tools/handlers/chat.js.map +1 -0
  59. package/dist/tools/handlers/combat.d.ts +11 -0
  60. package/dist/tools/handlers/combat.d.ts.map +1 -0
  61. package/dist/tools/handlers/combat.js +48 -0
  62. package/dist/tools/handlers/combat.js.map +1 -0
  63. package/dist/tools/handlers/diagnostics.d.ts +64 -0
  64. package/dist/tools/handlers/diagnostics.d.ts.map +1 -0
  65. package/dist/tools/handlers/diagnostics.js +182 -0
  66. package/dist/tools/handlers/diagnostics.js.map +1 -0
  67. package/dist/tools/handlers/dice.d.ts +39 -0
  68. package/dist/tools/handlers/dice.d.ts.map +1 -0
  69. package/dist/tools/handlers/dice.js +53 -0
  70. package/dist/tools/handlers/dice.js.map +1 -0
  71. package/dist/tools/handlers/generation.d.ts +44 -0
  72. package/dist/tools/handlers/generation.d.ts.map +1 -0
  73. package/dist/tools/handlers/generation.js +205 -0
  74. package/dist/tools/handlers/generation.js.map +1 -0
  75. package/dist/tools/handlers/items.d.ts +21 -0
  76. package/dist/tools/handlers/items.d.ts.map +1 -0
  77. package/dist/tools/handlers/items.js +50 -0
  78. package/dist/tools/handlers/items.js.map +1 -0
  79. package/dist/tools/handlers/journals.d.ts +22 -0
  80. package/dist/tools/handlers/journals.d.ts.map +1 -0
  81. package/dist/tools/handlers/journals.js +62 -0
  82. package/dist/tools/handlers/journals.js.map +1 -0
  83. package/dist/tools/handlers/resources.d.ts +13 -0
  84. package/dist/tools/handlers/resources.d.ts.map +1 -0
  85. package/dist/tools/handlers/resources.js +188 -0
  86. package/dist/tools/handlers/resources.js.map +1 -0
  87. package/dist/tools/handlers/scenes.d.ts +18 -0
  88. package/dist/tools/handlers/scenes.d.ts.map +1 -0
  89. package/dist/tools/handlers/scenes.js +34 -0
  90. package/dist/tools/handlers/scenes.js.map +1 -0
  91. package/dist/tools/handlers/users.d.ts +11 -0
  92. package/dist/tools/handlers/users.d.ts.map +1 -0
  93. package/dist/tools/handlers/users.js +34 -0
  94. package/dist/tools/handlers/users.js.map +1 -0
  95. package/dist/tools/handlers/utils.d.ts +11 -0
  96. package/dist/tools/handlers/utils.d.ts.map +1 -0
  97. package/dist/tools/handlers/utils.js +24 -0
  98. package/dist/tools/handlers/utils.js.map +1 -0
  99. package/dist/tools/handlers/world.d.ts +26 -0
  100. package/dist/tools/handlers/world.d.ts.map +1 -0
  101. package/dist/tools/handlers/world.js +92 -0
  102. package/dist/tools/handlers/world.js.map +1 -0
  103. package/dist/tools/index.d.ts +19 -0
  104. package/dist/tools/index.d.ts.map +1 -0
  105. package/dist/tools/index.js +22 -0
  106. package/dist/tools/index.js.map +1 -0
  107. package/dist/tools/new-router.d.ts +29 -0
  108. package/dist/tools/new-router.d.ts.map +1 -0
  109. package/dist/tools/new-router.js +97 -0
  110. package/dist/tools/new-router.js.map +1 -0
  111. package/dist/tools/registry.d.ts +51 -0
  112. package/dist/tools/registry.d.ts.map +1 -0
  113. package/dist/tools/registry.js +79 -0
  114. package/dist/tools/registry.js.map +1 -0
  115. package/dist/tools/resources.d.ts +16 -0
  116. package/dist/tools/resources.d.ts.map +1 -0
  117. package/dist/tools/resources.js +63 -0
  118. package/dist/tools/resources.js.map +1 -0
  119. package/dist/tools/router.d.ts +22 -0
  120. package/dist/tools/router.d.ts.map +1 -0
  121. package/dist/tools/router.js +128 -0
  122. package/dist/tools/router.js.map +1 -0
  123. package/dist/utils/cache-instance.d.ts +25 -0
  124. package/dist/utils/cache-instance.d.ts.map +1 -0
  125. package/dist/utils/cache-instance.js +30 -0
  126. package/dist/utils/cache-instance.js.map +1 -0
  127. package/dist/utils/cache.d.ts +80 -0
  128. package/dist/utils/cache.d.ts.map +1 -0
  129. package/dist/utils/cache.js +205 -0
  130. package/dist/utils/cache.js.map +1 -0
  131. package/dist/utils/diagnostics.d.ts +114 -0
  132. package/dist/utils/diagnostics.d.ts.map +1 -0
  133. package/dist/utils/diagnostics.js +330 -0
  134. package/dist/utils/diagnostics.js.map +1 -0
  135. package/dist/utils/logger.d.ts +137 -0
  136. package/dist/utils/logger.d.ts.map +1 -0
  137. package/dist/utils/logger.js +158 -0
  138. package/dist/utils/logger.js.map +1 -0
  139. package/package.json +98 -0
@@ -0,0 +1,414 @@
1
+ /**
2
+ * @fileoverview Type definitions for FoundryVTT diagnostics and logging
3
+ *
4
+ * This module provides TypeScript interfaces for log entries, system health metrics,
5
+ * and diagnostic data structures used by the MCP server for FoundryVTT monitoring.
6
+ *
7
+ * @version 0.1.0
8
+ * @author FoundryVTT MCP Team
9
+ */
10
+ import { z } from 'zod';
11
+ /**
12
+ * Log entry interface representing a single log message with metadata
13
+ *
14
+ * @interface LogEntry
15
+ * @example
16
+ * ```typescript
17
+ * const logEntry: LogEntry = {
18
+ * timestamp: '2024-01-01T12:00:00.000Z',
19
+ * level: 'error',
20
+ * message: 'TypeError: Cannot read property of undefined',
21
+ * stack: 'Error stack trace...',
22
+ * source: 'module'
23
+ * };
24
+ * ```
25
+ */
26
+ export interface LogEntry {
27
+ /** ISO timestamp when the log entry was created */
28
+ timestamp: string;
29
+ /** Log level indicating severity */
30
+ level: 'log' | 'warn' | 'error' | 'info' | 'notification';
31
+ /** The actual log message content */
32
+ message: string;
33
+ /** Optional stack trace for errors */
34
+ stack?: string;
35
+ /** Source component that generated the log */
36
+ source: 'foundry' | 'module' | 'system' | 'api' | 'unknown';
37
+ }
38
+ /**
39
+ * Server information including FoundryVTT and system versions
40
+ *
41
+ * @interface ServerInfo
42
+ */
43
+ export interface ServerInfo {
44
+ /** FoundryVTT version string */
45
+ foundryVersion: string;
46
+ /** Game system version */
47
+ systemVersion: string;
48
+ /** Current world identifier */
49
+ worldId: string;
50
+ /** Server uptime in seconds (if available) */
51
+ uptime?: number;
52
+ }
53
+ /**
54
+ * User session information and statistics
55
+ *
56
+ * @interface UserInfo
57
+ */
58
+ export interface UserInfo {
59
+ /** Total number of users */
60
+ total: number;
61
+ /** Number of currently active users */
62
+ active: number;
63
+ /** Number of GM users */
64
+ gm: number;
65
+ }
66
+ /**
67
+ * Module information and statistics
68
+ *
69
+ * @interface ModuleInfo
70
+ */
71
+ export interface ModuleInfo {
72
+ /** Total number of installed modules */
73
+ total: number;
74
+ /** Number of currently active modules */
75
+ active: number;
76
+ }
77
+ /**
78
+ * Performance metrics for system monitoring
79
+ *
80
+ * @interface PerformanceInfo
81
+ */
82
+ export interface PerformanceInfo {
83
+ /** Node.js memory usage (if available) */
84
+ memory?: NodeJS.MemoryUsage;
85
+ /** Number of connected WebSocket clients */
86
+ connectedClients: number;
87
+ }
88
+ /**
89
+ * Log buffer statistics and metrics
90
+ *
91
+ * @interface LogInfo
92
+ */
93
+ export interface LogInfo {
94
+ /** Current number of entries in the log buffer */
95
+ bufferSize: number;
96
+ /** Number of recent error entries */
97
+ recentErrors: number;
98
+ /** Number of recent warning entries */
99
+ recentWarnings: number;
100
+ /** Error rate as a percentage */
101
+ errorRate: number;
102
+ }
103
+ /**
104
+ * Overall system health status and metrics
105
+ *
106
+ * @interface SystemHealth
107
+ * @example
108
+ * ```typescript
109
+ * const health: SystemHealth = {
110
+ * timestamp: '2024-01-01T12:00:00.000Z',
111
+ * server: { foundryVersion: '11.315', systemVersion: '5e 2.4.1', worldId: 'my-world' },
112
+ * users: { total: 5, active: 3, gm: 1 },
113
+ * modules: { total: 50, active: 35 },
114
+ * performance: { connectedClients: 3 },
115
+ * logs: { bufferSize: 500, recentErrors: 2, recentWarnings: 5, errorRate: 0.1 },
116
+ * status: 'healthy'
117
+ * };
118
+ * ```
119
+ */
120
+ export interface SystemHealth {
121
+ /** Timestamp when health data was collected */
122
+ timestamp: string;
123
+ /** Server information and versions */
124
+ server: ServerInfo;
125
+ /** User session information */
126
+ users: UserInfo;
127
+ /** Module information */
128
+ modules: ModuleInfo;
129
+ /** Performance metrics */
130
+ performance: PerformanceInfo;
131
+ /** Log statistics */
132
+ logs: LogInfo;
133
+ /** Overall health status */
134
+ status: 'healthy' | 'warning' | 'critical';
135
+ }
136
+ /**
137
+ * Error categorization for diagnostics
138
+ *
139
+ * @interface ErrorCategories
140
+ */
141
+ export interface ErrorCategories {
142
+ [category: string]: number;
143
+ }
144
+ /**
145
+ * Diagnostic suggestion for resolving issues
146
+ *
147
+ * @interface DiagnosticSuggestion
148
+ */
149
+ export interface DiagnosticSuggestion {
150
+ /** Error category this suggestion applies to */
151
+ category: string;
152
+ /** Human-readable suggestion text */
153
+ suggestion: string;
154
+ /** Priority level for addressing the issue */
155
+ priority: 'low' | 'medium' | 'high' | 'critical';
156
+ }
157
+ /**
158
+ * Summary of error analysis
159
+ *
160
+ * @interface ErrorSummary
161
+ */
162
+ export interface ErrorSummary {
163
+ /** Total number of errors in the analyzed timeframe */
164
+ totalErrors: number;
165
+ /** Number of unique error messages */
166
+ uniqueErrors: number;
167
+ /** Categorized error counts */
168
+ categories: ErrorCategories;
169
+ }
170
+ /**
171
+ * Complete error diagnosis with analysis and suggestions
172
+ *
173
+ * @interface ErrorDiagnosis
174
+ * @example
175
+ * ```typescript
176
+ * const diagnosis: ErrorDiagnosis = {
177
+ * timestamp: '2024-01-01T12:00:00.000Z',
178
+ * timeframe: '3600 seconds',
179
+ * summary: {
180
+ * totalErrors: 5,
181
+ * uniqueErrors: 3,
182
+ * categories: { 'TypeError': 2, 'Network': 3 }
183
+ * },
184
+ * recentErrors: [...],
185
+ * suggestions: [...],
186
+ * healthScore: 75
187
+ * };
188
+ * ```
189
+ */
190
+ export interface ErrorDiagnosis {
191
+ /** Timestamp of the diagnosis */
192
+ timestamp: string;
193
+ /** Time window analyzed for errors */
194
+ timeframe: string;
195
+ /** Summary of errors found */
196
+ summary: ErrorSummary;
197
+ /** Most recent error entries */
198
+ recentErrors: LogEntry[];
199
+ /** Diagnostic suggestions based on error patterns */
200
+ suggestions: DiagnosticSuggestion[];
201
+ /** Overall health score (0-100) */
202
+ healthScore: number;
203
+ }
204
+ /**
205
+ * Parameters for searching logs
206
+ *
207
+ * @interface LogSearchParams
208
+ */
209
+ export interface LogSearchParams {
210
+ /** Number of log lines to retrieve */
211
+ lines?: number;
212
+ /** Filter by specific log level */
213
+ level?: LogEntry['level'];
214
+ /** Filter logs since this timestamp */
215
+ since?: string;
216
+ /** Filter by log source */
217
+ source?: LogEntry['source'];
218
+ /** Include stack traces in results */
219
+ includeStack?: boolean;
220
+ }
221
+ /**
222
+ * Parameters for log pattern searching
223
+ *
224
+ * @interface LogPatternSearchParams
225
+ */
226
+ export interface LogPatternSearchParams {
227
+ /** Regular expression pattern to search for */
228
+ pattern: string;
229
+ /** Time window in seconds to search within */
230
+ timeframe?: string;
231
+ /** Filter by specific log level */
232
+ level?: LogEntry['level'];
233
+ /** Case-sensitive search */
234
+ caseSensitive?: boolean;
235
+ }
236
+ /**
237
+ * Response structure for log retrieval operations
238
+ *
239
+ * @interface LogResponse
240
+ */
241
+ export interface LogResponse {
242
+ /** Array of log entries */
243
+ logs: LogEntry[];
244
+ /** Total number of log entries returned */
245
+ total: number;
246
+ /** Current size of the log buffer */
247
+ bufferSize?: number;
248
+ /** Maximum size of the log buffer */
249
+ maxBufferSize?: number;
250
+ }
251
+ /**
252
+ * Response structure for log search operations
253
+ *
254
+ * @interface LogSearchResponse
255
+ */
256
+ export interface LogSearchResponse {
257
+ /** Array of matching log entries */
258
+ logs: LogEntry[];
259
+ /** Number of matches found */
260
+ matches: number;
261
+ /** Search pattern used */
262
+ pattern: string;
263
+ /** Timeframe searched */
264
+ searchTimeframe: string;
265
+ }
266
+ export declare const LogEntrySchema: z.ZodObject<{
267
+ timestamp: z.ZodString;
268
+ level: z.ZodEnum<{
269
+ info: "info";
270
+ warn: "warn";
271
+ error: "error";
272
+ log: "log";
273
+ notification: "notification";
274
+ }>;
275
+ message: z.ZodString;
276
+ stack: z.ZodOptional<z.ZodString>;
277
+ source: z.ZodEnum<{
278
+ foundry: "foundry";
279
+ system: "system";
280
+ unknown: "unknown";
281
+ module: "module";
282
+ api: "api";
283
+ }>;
284
+ }, z.core.$strip>;
285
+ export declare const LogResponseSchema: z.ZodObject<{
286
+ logs: z.ZodArray<z.ZodObject<{
287
+ timestamp: z.ZodString;
288
+ level: z.ZodEnum<{
289
+ info: "info";
290
+ warn: "warn";
291
+ error: "error";
292
+ log: "log";
293
+ notification: "notification";
294
+ }>;
295
+ message: z.ZodString;
296
+ stack: z.ZodOptional<z.ZodString>;
297
+ source: z.ZodEnum<{
298
+ foundry: "foundry";
299
+ system: "system";
300
+ unknown: "unknown";
301
+ module: "module";
302
+ api: "api";
303
+ }>;
304
+ }, z.core.$strip>>;
305
+ total: z.ZodNumber;
306
+ bufferSize: z.ZodOptional<z.ZodNumber>;
307
+ maxBufferSize: z.ZodOptional<z.ZodNumber>;
308
+ }, z.core.$strip>;
309
+ export declare const LogSearchResponseSchema: z.ZodObject<{
310
+ logs: z.ZodArray<z.ZodObject<{
311
+ timestamp: z.ZodString;
312
+ level: z.ZodEnum<{
313
+ info: "info";
314
+ warn: "warn";
315
+ error: "error";
316
+ log: "log";
317
+ notification: "notification";
318
+ }>;
319
+ message: z.ZodString;
320
+ stack: z.ZodOptional<z.ZodString>;
321
+ source: z.ZodEnum<{
322
+ foundry: "foundry";
323
+ system: "system";
324
+ unknown: "unknown";
325
+ module: "module";
326
+ api: "api";
327
+ }>;
328
+ }, z.core.$strip>>;
329
+ matches: z.ZodNumber;
330
+ pattern: z.ZodString;
331
+ searchTimeframe: z.ZodString;
332
+ }, z.core.$strip>;
333
+ export declare const SystemHealthSchema: z.ZodObject<{
334
+ timestamp: z.ZodString;
335
+ server: z.ZodObject<{
336
+ foundryVersion: z.ZodString;
337
+ systemVersion: z.ZodString;
338
+ worldId: z.ZodString;
339
+ uptime: z.ZodOptional<z.ZodNumber>;
340
+ }, z.core.$strip>;
341
+ users: z.ZodObject<{
342
+ total: z.ZodNumber;
343
+ active: z.ZodNumber;
344
+ gm: z.ZodNumber;
345
+ }, z.core.$strip>;
346
+ modules: z.ZodObject<{
347
+ total: z.ZodNumber;
348
+ active: z.ZodNumber;
349
+ }, z.core.$strip>;
350
+ performance: z.ZodObject<{
351
+ memory: z.ZodOptional<z.ZodObject<{
352
+ rss: z.ZodNumber;
353
+ heapTotal: z.ZodNumber;
354
+ heapUsed: z.ZodNumber;
355
+ external: z.ZodNumber;
356
+ arrayBuffers: z.ZodNumber;
357
+ }, z.core.$strip>>;
358
+ connectedClients: z.ZodNumber;
359
+ }, z.core.$strip>;
360
+ logs: z.ZodObject<{
361
+ bufferSize: z.ZodNumber;
362
+ recentErrors: z.ZodNumber;
363
+ recentWarnings: z.ZodNumber;
364
+ errorRate: z.ZodNumber;
365
+ }, z.core.$strip>;
366
+ status: z.ZodEnum<{
367
+ healthy: "healthy";
368
+ warning: "warning";
369
+ critical: "critical";
370
+ }>;
371
+ }, z.core.$strip>;
372
+ export declare const ErrorDiagnosisSchema: z.ZodObject<{
373
+ timestamp: z.ZodString;
374
+ timeframe: z.ZodString;
375
+ summary: z.ZodObject<{
376
+ totalErrors: z.ZodNumber;
377
+ uniqueErrors: z.ZodNumber;
378
+ categories: z.ZodRecord<z.ZodString, z.ZodNumber>;
379
+ }, z.core.$strip>;
380
+ recentErrors: z.ZodArray<z.ZodObject<{
381
+ timestamp: z.ZodString;
382
+ level: z.ZodEnum<{
383
+ info: "info";
384
+ warn: "warn";
385
+ error: "error";
386
+ log: "log";
387
+ notification: "notification";
388
+ }>;
389
+ message: z.ZodString;
390
+ stack: z.ZodOptional<z.ZodString>;
391
+ source: z.ZodEnum<{
392
+ foundry: "foundry";
393
+ system: "system";
394
+ unknown: "unknown";
395
+ module: "module";
396
+ api: "api";
397
+ }>;
398
+ }, z.core.$strip>>;
399
+ suggestions: z.ZodArray<z.ZodObject<{
400
+ category: z.ZodString;
401
+ suggestion: z.ZodString;
402
+ priority: z.ZodEnum<{
403
+ critical: "critical";
404
+ low: "low";
405
+ medium: "medium";
406
+ high: "high";
407
+ }>;
408
+ }, z.core.$strip>>;
409
+ healthScore: z.ZodNumber;
410
+ }, z.core.$strip>;
411
+ export declare const ApiStatusResponseSchema: z.ZodObject<{
412
+ status: z.ZodString;
413
+ }, z.core.$strip>;
414
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/diagnostics/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,QAAQ;IACvB,mDAAmD;IACnD,SAAS,EAAE,MAAM,CAAC;IAClB,oCAAoC;IACpC,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,cAAc,CAAC;IAC1D,qCAAqC;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,sCAAsC;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,MAAM,EAAE,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,KAAK,GAAG,SAAS,CAAC;CAC7D;AAED;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,gCAAgC;IAChC,cAAc,EAAE,MAAM,CAAC;IACvB,0BAA0B;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,+BAA+B;IAC/B,OAAO,EAAE,M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E,MAAM,CAAC;IACnB,mCAAmC;IACnC,KAAK,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC1B,4BAA4B;IAC5B,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,2BAA2B;IAC3B,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjB,2CAA2C;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,qCAAqC;IACrC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qCAAqC;IACrC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,oCAAoC;IACpC,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjB,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,0BAA0B;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,yBAAyB;IACzB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;iBAMzB,CAAC;AAEH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;iBAK5B,CAAC;AAEH,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;iBAKlC,CAAC;AAwCH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAQ7B,CAAC;AAgBH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAO/B,CAAC;AAEH,eAAO,MAAM,uBAAuB;;iBAElC,CAAC"}
@@ -0,0 +1,94 @@
1
+ /**
2
+ * @fileoverview Type definitions for FoundryVTT diagnostics and logging
3
+ *
4
+ * This module provides TypeScript interfaces for log entries, system health metrics,
5
+ * and diagnostic data structures used by the MCP server for FoundryVTT monitoring.
6
+ *
7
+ * @version 0.1.0
8
+ * @author FoundryVTT MCP Team
9
+ */
10
+ import { z } from 'zod';
11
+ export const LogEntrySchema = z.object({
12
+ timestamp: z.string(),
13
+ level: z.enum(['log', 'warn', 'error', 'info', 'notification']),
14
+ message: z.string(),
15
+ stack: z.string().optional(),
16
+ source: z.enum(['foundry', 'module', 'system', 'api', 'unknown']),
17
+ });
18
+ export const LogResponseSchema = z.object({
19
+ logs: z.array(LogEntrySchema),
20
+ total: z.number(),
21
+ bufferSize: z.number().optional(),
22
+ maxBufferSize: z.number().optional(),
23
+ });
24
+ export const LogSearchResponseSchema = z.object({
25
+ logs: z.array(LogEntrySchema),
26
+ matches: z.number(),
27
+ pattern: z.string(),
28
+ searchTimeframe: z.string(),
29
+ });
30
+ const ServerInfoSchema = z.object({
31
+ foundryVersion: z.string(),
32
+ systemVersion: z.string(),
33
+ worldId: z.string(),
34
+ uptime: z.number().optional(),
35
+ });
36
+ const UserInfoSchema = z.object({
37
+ total: z.number(),
38
+ active: z.number(),
39
+ gm: z.number(),
40
+ });
41
+ const ModuleInfoSchema = z.object({
42
+ total: z.number(),
43
+ active: z.number(),
44
+ });
45
+ const PerformanceInfoSchema = z.object({
46
+ memory: z
47
+ .object({
48
+ rss: z.number(),
49
+ heapTotal: z.number(),
50
+ heapUsed: z.number(),
51
+ external: z.number(),
52
+ arrayBuffers: z.number(),
53
+ })
54
+ .optional(),
55
+ connectedClients: z.number(),
56
+ });
57
+ const LogInfoSchema = z.object({
58
+ bufferSize: z.number(),
59
+ recentErrors: z.number(),
60
+ recentWarnings: z.number(),
61
+ errorRate: z.number(),
62
+ });
63
+ export const SystemHealthSchema = z.object({
64
+ timestamp: z.string(),
65
+ server: ServerInfoSchema,
66
+ users: UserInfoSchema,
67
+ modules: ModuleInfoSchema,
68
+ performance: PerformanceInfoSchema,
69
+ logs: LogInfoSchema,
70
+ status: z.enum(['healthy', 'warning', 'critical']),
71
+ });
72
+ const ErrorCategoriesSchema = z.record(z.string(), z.number());
73
+ const DiagnosticSuggestionSchema = z.object({
74
+ category: z.string(),
75
+ suggestion: z.string(),
76
+ priority: z.enum(['low', 'medium', 'high', 'critical']),
77
+ });
78
+ const ErrorSummarySchema = z.object({
79
+ totalErrors: z.number(),
80
+ uniqueErrors: z.number(),
81
+ categories: ErrorCategoriesSchema,
82
+ });
83
+ export const ErrorDiagnosisSchema = z.object({
84
+ timestamp: z.string(),
85
+ timeframe: z.string(),
86
+ summary: ErrorSummarySchema,
87
+ recentErrors: z.array(LogEntrySchema),
88
+ suggestions: z.array(DiagnosticSuggestionSchema),
89
+ healthScore: z.number(),
90
+ });
91
+ export const ApiStatusResponseSchema = z.object({
92
+ status: z.string(),
93
+ });
94
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/diagnostics/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAgRxB,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IACrC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC;IAC/D,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC5B,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;CAClE,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC;IAC7B,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE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,EAAE,qBAAqB;CAClC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3C,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,OAAO,EAAE,kBAAkB;IAC3B,YAAY,EAAE,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC;IACrC,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,0BAA0B,CAAC;IAChD,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;CACxB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9C,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;CACnB,CAAC,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * FoundryVTT authentication module
3
+ *
4
+ * Implements the proven 4-step authentication flow for direct WebSocket access:
5
+ * 1. GET /join → session cookie
6
+ * 2. Socket.IO connect + getJoinData → resolve user document _id
7
+ * 3. POST /join as JSON with document _id → authenticated session
8
+ * 4. Socket.IO reconnect with session → full game state access
9
+ */
10
+ /**
11
+ * Authenticates with FoundryVTT using the proven 4-step flow.
12
+ *
13
+ * @returns Session cookie and resolved user document _id
14
+ */
15
+ export declare function authenticateFoundry(baseUrl: string, user: string, password: string): Promise<{
16
+ session: string;
17
+ userId: string;
18
+ }>;
19
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/foundry/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAkGH;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAoD9C"}
@@ -0,0 +1,135 @@
1
+ /**
2
+ * FoundryVTT authentication module
3
+ *
4
+ * Implements the proven 4-step authentication flow for direct WebSocket access:
5
+ * 1. GET /join → session cookie
6
+ * 2. Socket.IO connect + getJoinData → resolve user document _id
7
+ * 3. POST /join as JSON with document _id → authenticated session
8
+ * 4. Socket.IO reconnect with session → full game state access
9
+ */
10
+ import axios from 'axios';
11
+ import { io } from 'socket.io-client';
12
+ import { logger } from '../utils/logger.js';
13
+ /**
14
+ * Extracts the session cookie value from a GET /join response.
15
+ */
16
+ async function getSessionCookie(baseUrl) {
17
+ const res = await axios.get(`${baseUrl}/join`, {
18
+ // Accept 200 (join page) and 302 (redirect after cookie set)
19
+ validateStatus: (status) => status === 200 || status === 302,
20
+ maxRedirects: 0,
21
+ });
22
+ const cookies = res.headers['set-cookie'];
23
+ if (!cookies) {
24
+ throw new Error('No session cookie returned from /join');
25
+ }
26
+ const cookieString = Array.isArray(cookies) ? cookies.join(' ') : cookies;
27
+ const match = cookieString.match(/session=([^;]+)/);
28
+ if (!match?.[1]) {
29
+ throw new Error('Could not extract session cookie from response');
30
+ }
31
+ logger.debug('Session cookie obtained');
32
+ return match[1];
33
+ }
34
+ /**
35
+ * Resolves a user identifier to a FoundryVTT document _id.
36
+ *
37
+ * If the input is already a 16-character alphanumeric string (document _id format),
38
+ * returns it directly. Otherwise, connects via Socket.IO and emits getJoinData
39
+ * to look up the _id by display name.
40
+ */
41
+ async function resolveUserId(baseUrl, user, session) {
42
+ // FoundryVTT document IDs are 16-character alphanumeric strings
43
+ if (/^[a-zA-Z0-9]{16}$/.test(user)) {
44
+ logger.debug('User identifier is already a document _id', { userId: user });
45
+ return user;
46
+ }
47
+ logger.debug('Resolving display name to document _id', { displayName: user });
48
+ return new Promise((resolve, reject) => {
49
+ const socket = io(baseUrl, {
50
+ transports: ['websocket'],
51
+ query: { session },
52
+ });
53
+ const cleanup = () => {
54
+ socket.off('session', onSession);
55
+ socket.off('connect_error', onConnectError);
56
+ };
57
+ const timeout = setTimeout(() => {
58
+ cleanup();
59
+ socket.disconnect();
60
+ reject(new Error('Timeout resolving user ID via getJoinData'));
61
+ }, 10000);
62
+ const onSession = () => {
63
+ socket.emit('getJoinData', (data) => {
64
+ clearTimeout(timeout);
65
+ cleanup();
66
+ socket.disconnect();
67
+ if (!data?.users || !Array.isArray(data.users)) {
68
+ return reject(new Error('getJoinData returned no users'));
69
+ }
70
+ const found = data.users.find((u) => u.name.toLowerCase() === user.toLowerCase());
71
+ if (!found) {
72
+ const available = data.users.map((u) => u.name).join(', ');
73
+ logger.debug('User not found in FoundryVTT user list', { available });
74
+ return reject(new Error(`User "${user}" not found`));
75
+ }
76
+ logger.debug('Resolved user document _id', { displayName: user, _id: found._id });
77
+ resolve(found._id);
78
+ });
79
+ };
80
+ const onConnectError = (err) => {
81
+ clearTimeout(timeout);
82
+ cleanup();
83
+ socket.disconnect();
84
+ reject(new Error(`Socket.IO connection failed during user resolution: ${err.message}`));
85
+ };
86
+ socket.on('session', onSession);
87
+ socket.on('connect_error', onConnectError);
88
+ });
89
+ }
90
+ /**
91
+ * Authenticates with FoundryVTT using the proven 4-step flow.
92
+ *
93
+ * @returns Session cookie and resolved user document _id
94
+ */
95
+ export async function authenticateFoundry(baseUrl, user, password) {
96
+ // Warn when credentials are sent over plaintext HTTP to a non-localhost host
97
+ try {
98
+ const parsed = new URL(baseUrl);
99
+ if (parsed.protocol === 'http:' &&
100
+ parsed.hostname !== 'localhost' &&
101
+ parsed.hostname !== '127.0.0.1' &&
102
+ !parsed.hostname.startsWith('::1')) {
103
+ logger.warn('WARNING: Connecting to a non-localhost host over plain HTTP. ' +
104
+ 'Your password will be transmitted in plaintext. ' +
105
+ 'Use HTTPS for non-local FoundryVTT instances.', { host: parsed.hostname });
106
+ }
107
+ }
108
+ catch {
109
+ // URL already validated by config; ignore parse errors here
110
+ }
111
+ // Step 1: Get session cookie
112
+ const session = await getSessionCookie(baseUrl);
113
+ // Step 2: Resolve user to document _id
114
+ const userId = await resolveUserId(baseUrl, user, session);
115
+ // Step 3: POST /join as JSON with document _id
116
+ const joinRes = await axios.post(`${baseUrl}/join`, {
117
+ action: 'join',
118
+ userid: userId,
119
+ password,
120
+ }, {
121
+ headers: {
122
+ 'Content-Type': 'application/json',
123
+ Cookie: `session=${session}`,
124
+ },
125
+ // Accept 200 (success JSON) and 302 (redirect to /game on success)
126
+ validateStatus: (status) => status === 200 || status === 302,
127
+ });
128
+ if (joinRes.data?.status !== 'success' && joinRes.data?.redirect !== '/game') {
129
+ const msg = joinRes.data?.message || joinRes.data?.error || 'Unknown error';
130
+ throw new Error(`FoundryVTT authentication failed: ${msg}`);
131
+ }
132
+ logger.info('FoundryVTT authentication successful', { userId });
133
+ return { session, userId };
134
+ }
135
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/foundry/auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C;;GAEG;AACH,KAAK,UAAU,gBAAgB,CAAC,OAAe;IAC7C,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,GAAG,OAAO,OAAO,EAAE;QAC7C,6DAA6D;QAC7D,cAAc,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG;QAC5D,YAAY,EAAE,CAAC;KAChB,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC1C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAC3D,CAAC;IAED,MAAM,YAAY,GAAG,KAAK,CAAC,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