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.
- package/LICENSE +21 -0
- package/README.md +142 -0
- package/dist/character/manager.d.ts +92 -0
- package/dist/character/manager.d.ts.map +1 -0
- package/dist/character/manager.js +208 -0
- package/dist/character/manager.js.map +1 -0
- package/dist/combat/manager.d.ts +94 -0
- package/dist/combat/manager.d.ts.map +1 -0
- package/dist/combat/manager.js +373 -0
- package/dist/combat/manager.js.map +1 -0
- package/dist/config/index.d.ts +114 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +177 -0
- package/dist/config/index.js.map +1 -0
- package/dist/diagnostics/client.d.ts +193 -0
- package/dist/diagnostics/client.d.ts.map +1 -0
- package/dist/diagnostics/client.js +314 -0
- package/dist/diagnostics/client.js.map +1 -0
- package/dist/diagnostics/types.d.ts +414 -0
- package/dist/diagnostics/types.d.ts.map +1 -0
- package/dist/diagnostics/types.js +94 -0
- package/dist/diagnostics/types.js.map +1 -0
- package/dist/foundry/auth.d.ts +19 -0
- package/dist/foundry/auth.d.ts.map +1 -0
- package/dist/foundry/auth.js +135 -0
- package/dist/foundry/auth.js.map +1 -0
- package/dist/foundry/client.d.ts +95 -0
- package/dist/foundry/client.d.ts.map +1 -0
- package/dist/foundry/client.js +692 -0
- package/dist/foundry/client.js.map +1 -0
- package/dist/foundry/types.d.ts +805 -0
- package/dist/foundry/types.d.ts.map +1 -0
- package/dist/foundry/types.js +13 -0
- package/dist/foundry/types.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +199 -0
- package/dist/index.js.map +1 -0
- package/dist/resources/index.d.ts +3 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +93 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/tools/base.d.ts +80 -0
- package/dist/tools/base.d.ts.map +1 -0
- package/dist/tools/base.js +73 -0
- package/dist/tools/base.js.map +1 -0
- package/dist/tools/definitions.d.ts +414 -0
- package/dist/tools/definitions.d.ts.map +1 -0
- package/dist/tools/definitions.js +429 -0
- package/dist/tools/definitions.js.map +1 -0
- package/dist/tools/handlers/actors.d.ts +31 -0
- package/dist/tools/handlers/actors.d.ts.map +1 -0
- package/dist/tools/handlers/actors.js +76 -0
- package/dist/tools/handlers/actors.js.map +1 -0
- package/dist/tools/handlers/chat.d.ts +13 -0
- package/dist/tools/handlers/chat.d.ts.map +1 -0
- package/dist/tools/handlers/chat.js +38 -0
- package/dist/tools/handlers/chat.js.map +1 -0
- package/dist/tools/handlers/combat.d.ts +11 -0
- package/dist/tools/handlers/combat.d.ts.map +1 -0
- package/dist/tools/handlers/combat.js +48 -0
- package/dist/tools/handlers/combat.js.map +1 -0
- package/dist/tools/handlers/diagnostics.d.ts +64 -0
- package/dist/tools/handlers/diagnostics.d.ts.map +1 -0
- package/dist/tools/handlers/diagnostics.js +182 -0
- package/dist/tools/handlers/diagnostics.js.map +1 -0
- package/dist/tools/handlers/dice.d.ts +39 -0
- package/dist/tools/handlers/dice.d.ts.map +1 -0
- package/dist/tools/handlers/dice.js +53 -0
- package/dist/tools/handlers/dice.js.map +1 -0
- package/dist/tools/handlers/generation.d.ts +44 -0
- package/dist/tools/handlers/generation.d.ts.map +1 -0
- package/dist/tools/handlers/generation.js +205 -0
- package/dist/tools/handlers/generation.js.map +1 -0
- package/dist/tools/handlers/items.d.ts +21 -0
- package/dist/tools/handlers/items.d.ts.map +1 -0
- package/dist/tools/handlers/items.js +50 -0
- package/dist/tools/handlers/items.js.map +1 -0
- package/dist/tools/handlers/journals.d.ts +22 -0
- package/dist/tools/handlers/journals.d.ts.map +1 -0
- package/dist/tools/handlers/journals.js +62 -0
- package/dist/tools/handlers/journals.js.map +1 -0
- package/dist/tools/handlers/resources.d.ts +13 -0
- package/dist/tools/handlers/resources.d.ts.map +1 -0
- package/dist/tools/handlers/resources.js +188 -0
- package/dist/tools/handlers/resources.js.map +1 -0
- package/dist/tools/handlers/scenes.d.ts +18 -0
- package/dist/tools/handlers/scenes.d.ts.map +1 -0
- package/dist/tools/handlers/scenes.js +34 -0
- package/dist/tools/handlers/scenes.js.map +1 -0
- package/dist/tools/handlers/users.d.ts +11 -0
- package/dist/tools/handlers/users.d.ts.map +1 -0
- package/dist/tools/handlers/users.js +34 -0
- package/dist/tools/handlers/users.js.map +1 -0
- package/dist/tools/handlers/utils.d.ts +11 -0
- package/dist/tools/handlers/utils.d.ts.map +1 -0
- package/dist/tools/handlers/utils.js +24 -0
- package/dist/tools/handlers/utils.js.map +1 -0
- package/dist/tools/handlers/world.d.ts +26 -0
- package/dist/tools/handlers/world.d.ts.map +1 -0
- package/dist/tools/handlers/world.js +92 -0
- package/dist/tools/handlers/world.js.map +1 -0
- package/dist/tools/index.d.ts +19 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +22 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/new-router.d.ts +29 -0
- package/dist/tools/new-router.d.ts.map +1 -0
- package/dist/tools/new-router.js +97 -0
- package/dist/tools/new-router.js.map +1 -0
- package/dist/tools/registry.d.ts +51 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +79 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/resources.d.ts +16 -0
- package/dist/tools/resources.d.ts.map +1 -0
- package/dist/tools/resources.js +63 -0
- package/dist/tools/resources.js.map +1 -0
- package/dist/tools/router.d.ts +22 -0
- package/dist/tools/router.d.ts.map +1 -0
- package/dist/tools/router.js +128 -0
- package/dist/tools/router.js.map +1 -0
- package/dist/utils/cache-instance.d.ts +25 -0
- package/dist/utils/cache-instance.d.ts.map +1 -0
- package/dist/utils/cache-instance.js +30 -0
- package/dist/utils/cache-instance.js.map +1 -0
- package/dist/utils/cache.d.ts +80 -0
- package/dist/utils/cache.d.ts.map +1 -0
- package/dist/utils/cache.js +205 -0
- package/dist/utils/cache.js.map +1 -0
- package/dist/utils/diagnostics.d.ts +114 -0
- package/dist/utils/diagnostics.d.ts.map +1 -0
- package/dist/utils/diagnostics.js +330 -0
- package/dist/utils/diagnostics.js.map +1 -0
- package/dist/utils/logger.d.ts +137 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +158 -0
- package/dist/utils/logger.js.map +1 -0
- package/package.json +98 -0
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Diagnostic utilities for enhanced user experience
|
|
3
|
+
*
|
|
4
|
+
* Provides smart error analysis, problem detection, and actionable suggestions
|
|
5
|
+
* to help users troubleshoot and resolve common issues.
|
|
6
|
+
*/
|
|
7
|
+
import { config } from '../config/index.js';
|
|
8
|
+
import { ApiStatusResponseSchema } from '../diagnostics/types.js';
|
|
9
|
+
import { logger } from './logger.js';
|
|
10
|
+
/**
|
|
11
|
+
* Enhanced diagnostic system for FoundryVTT MCP integration
|
|
12
|
+
*/
|
|
13
|
+
export class DiagnosticSystem {
|
|
14
|
+
foundryClient;
|
|
15
|
+
constructor(foundryClient) {
|
|
16
|
+
this.foundryClient = foundryClient;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Diagnose why a specific feature isn't working
|
|
20
|
+
*/
|
|
21
|
+
async diagnoseFeatureProblem(feature) {
|
|
22
|
+
logger.debug(`Diagnosing problem with feature: ${feature}`);
|
|
23
|
+
try {
|
|
24
|
+
// Test basic connectivity
|
|
25
|
+
const isConnected = await this.foundryClient.testConnection();
|
|
26
|
+
if (!isConnected) {
|
|
27
|
+
return this.createConnectivityDiagnostic();
|
|
28
|
+
}
|
|
29
|
+
// Test REST API availability
|
|
30
|
+
const hasRestApi = await this.testRestApiAvailability();
|
|
31
|
+
if (!hasRestApi && this.requiresRestApi(feature)) {
|
|
32
|
+
return this.createRestApiDiagnostic(feature);
|
|
33
|
+
}
|
|
34
|
+
// Test authentication
|
|
35
|
+
const authResult = await this.testAuthentication();
|
|
36
|
+
if (!authResult.valid) {
|
|
37
|
+
return this.createAuthenticationDiagnostic(authResult);
|
|
38
|
+
}
|
|
39
|
+
// Feature-specific diagnostics
|
|
40
|
+
return await this.createFeatureSpecificDiagnostic(feature);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
logger.error('Error during diagnosis:', error);
|
|
44
|
+
return this.createGenericErrorDiagnostic(error);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Perform comprehensive health check
|
|
49
|
+
*/
|
|
50
|
+
async performHealthCheck() {
|
|
51
|
+
logger.info('Performing system health check');
|
|
52
|
+
const report = {
|
|
53
|
+
connectivity: { status: 'offline', emoji: '❌', details: 'Not tested' },
|
|
54
|
+
authentication: { method: 'none', status: 'untested', emoji: '❓' },
|
|
55
|
+
features: {
|
|
56
|
+
diceRolling: false,
|
|
57
|
+
actorSearch: false,
|
|
58
|
+
itemSearch: false,
|
|
59
|
+
sceneData: false,
|
|
60
|
+
diagnostics: false,
|
|
61
|
+
},
|
|
62
|
+
restApiAvailable: false,
|
|
63
|
+
websocketAvailable: false,
|
|
64
|
+
};
|
|
65
|
+
try {
|
|
66
|
+
// Test connectivity
|
|
67
|
+
const isConnected = await this.foundryClient.testConnection();
|
|
68
|
+
if (isConnected) {
|
|
69
|
+
report.connectivity = {
|
|
70
|
+
status: 'connected',
|
|
71
|
+
emoji: '✅',
|
|
72
|
+
details: `Connected to ${config.foundry.url}`,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
report.connectivity = {
|
|
77
|
+
status: 'offline',
|
|
78
|
+
emoji: '❌',
|
|
79
|
+
details: `Cannot reach ${config.foundry.url}`,
|
|
80
|
+
};
|
|
81
|
+
return report; // Early return if not connected
|
|
82
|
+
}
|
|
83
|
+
// Test REST API
|
|
84
|
+
report.restApiAvailable = await this.testRestApiAvailability();
|
|
85
|
+
// Test authentication
|
|
86
|
+
const authResult = await this.testAuthentication();
|
|
87
|
+
report.authentication = {
|
|
88
|
+
method: config.foundry.apiKey ? 'api-key' : 'credentials',
|
|
89
|
+
status: authResult.valid ? 'valid' : 'invalid',
|
|
90
|
+
emoji: authResult.valid ? '✅' : '❌',
|
|
91
|
+
};
|
|
92
|
+
// Test individual features
|
|
93
|
+
report.features.diceRolling = await this.testDiceRolling();
|
|
94
|
+
report.features.actorSearch = await this.testActorSearch();
|
|
95
|
+
report.features.itemSearch = await this.testItemSearch();
|
|
96
|
+
report.features.sceneData = await this.testSceneData();
|
|
97
|
+
report.features.diagnostics = report.restApiAvailable;
|
|
98
|
+
// Update connectivity status based on feature availability
|
|
99
|
+
if (report.restApiAvailable) {
|
|
100
|
+
report.connectivity.status = 'connected';
|
|
101
|
+
}
|
|
102
|
+
else if (report.features.diceRolling) {
|
|
103
|
+
report.connectivity.status = 'limited';
|
|
104
|
+
report.connectivity.emoji = '⚠️';
|
|
105
|
+
report.connectivity.details += ' (Limited functionality - REST API not available)';
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
logger.error('Health check failed:', error);
|
|
110
|
+
report.connectivity = {
|
|
111
|
+
status: 'offline',
|
|
112
|
+
emoji: '❌',
|
|
113
|
+
details: `Health check failed: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
return report;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Format health report for user display
|
|
120
|
+
*/
|
|
121
|
+
formatHealthReport(report) {
|
|
122
|
+
let output = '🏥 **FoundryVTT MCP Health Check**\n\n';
|
|
123
|
+
output += `**Connection**: ${report.connectivity.status.toUpperCase()} ${report.connectivity.emoji}\n`;
|
|
124
|
+
output += ` ${report.connectivity.details}\n\n`;
|
|
125
|
+
output += `**Authentication**: ${report.authentication.method.toUpperCase()} ${report.authentication.emoji}\n`;
|
|
126
|
+
if (report.authentication.status === 'invalid') {
|
|
127
|
+
output += ` ⚠️ Authentication failed - check your credentials\n`;
|
|
128
|
+
}
|
|
129
|
+
output += '\n';
|
|
130
|
+
output += `**Available Features**:\n`;
|
|
131
|
+
output += ` • Dice Rolling: ${report.features.diceRolling ? '✅ Working' : '❌ Failed'}\n`;
|
|
132
|
+
output += ` • Actor Search: ${report.features.actorSearch ? '✅ Full access' : '⚠️ Limited/None'}\n`;
|
|
133
|
+
output += ` • Item Search: ${report.features.itemSearch ? '✅ Full access' : '⚠️ Limited/None'}\n`;
|
|
134
|
+
output += ` • Scene Data: ${report.features.sceneData ? '✅ Real data' : '⚠️ Mock data only'}\n`;
|
|
135
|
+
output += ` • System Diagnostics: ${report.features.diagnostics ? '✅ Available' : '❌ Unavailable'}\n\n`;
|
|
136
|
+
if (!report.restApiAvailable) {
|
|
137
|
+
output += '💡 **Unlock Full Features**:\n';
|
|
138
|
+
output += ' → Install the "Foundry Local REST API" module in FoundryVTT\n';
|
|
139
|
+
output += ' → Enable the module and configure API key\n';
|
|
140
|
+
output += ' → See setup guide: https://github.com/laurigates/foundryvtt-mcp#setup\n\n';
|
|
141
|
+
}
|
|
142
|
+
if (report.connectivity.status === 'offline') {
|
|
143
|
+
output += '🔧 **Troubleshooting Steps**:\n';
|
|
144
|
+
output += ' 1. Ensure FoundryVTT is running and accessible\n';
|
|
145
|
+
output += ' 2. Check FOUNDRY_URL in your .env file\n';
|
|
146
|
+
output += ' 3. Verify network connectivity\n';
|
|
147
|
+
output += ' 4. Test with: `npm run test-connection`\n';
|
|
148
|
+
}
|
|
149
|
+
return output;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Create diagnostic for connectivity issues
|
|
153
|
+
*/
|
|
154
|
+
createConnectivityDiagnostic() {
|
|
155
|
+
return {
|
|
156
|
+
explanation: 'Unable to connect to FoundryVTT server.',
|
|
157
|
+
suggestions: "• **Check if FoundryVTT is running** - Start FoundryVTT and ensure it's accessible\n" +
|
|
158
|
+
`• **Verify server URL** - Check that \`${config.foundry.url}\` is correct\n` +
|
|
159
|
+
'• **Test connectivity** - Run `npm run test-connection` for detailed diagnostics\n' +
|
|
160
|
+
'• **Check firewall** - Ensure no firewall is blocking the connection',
|
|
161
|
+
severity: 'critical',
|
|
162
|
+
canContinue: false,
|
|
163
|
+
documentationUrl: 'https://github.com/laurigates/foundryvtt-mcp/blob/main/TROUBLESHOOTING.md#connectivity-issues',
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Create diagnostic for REST API issues
|
|
168
|
+
*/
|
|
169
|
+
createRestApiDiagnostic(feature) {
|
|
170
|
+
return {
|
|
171
|
+
explanation: `${feature.charAt(0).toUpperCase() + feature.slice(1)} search requires the REST API module for full functionality.`,
|
|
172
|
+
suggestions: '• **Install REST API module** - Get it from the FoundryVTT module browser\n' +
|
|
173
|
+
"• **Enable the module** - Activate it in your world's module settings\n" +
|
|
174
|
+
'• **Configure API key** - Generate and copy the API key from module settings\n' +
|
|
175
|
+
'• **Update .env file** - Set FOUNDRY_API_KEY with your generated key\n' +
|
|
176
|
+
'• **Restart MCP server** - Restart to pick up the new configuration',
|
|
177
|
+
severity: 'warning',
|
|
178
|
+
canContinue: true,
|
|
179
|
+
documentationUrl: 'https://github.com/laurigates/foundryvtt-mcp/blob/main/SETUP_GUIDE.md#rest-api-setup',
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Create diagnostic for authentication issues
|
|
184
|
+
*/
|
|
185
|
+
createAuthenticationDiagnostic(_authResult) {
|
|
186
|
+
const isApiKey = !!config.foundry.apiKey;
|
|
187
|
+
return {
|
|
188
|
+
explanation: `Authentication failed using ${isApiKey ? 'API key' : 'username/password'}.`,
|
|
189
|
+
suggestions: isApiKey
|
|
190
|
+
? "• **Check API key** - Verify the key is correct and hasn't expired\n" +
|
|
191
|
+
'• **Regenerate key** - Generate a new API key in FoundryVTT module settings\n' +
|
|
192
|
+
'• **Module status** - Ensure the REST API module is enabled and running\n' +
|
|
193
|
+
'• **Restart FoundryVTT** - Sometimes a restart resolves authentication issues'
|
|
194
|
+
: '• **Check credentials** - Verify username and password are correct\n' +
|
|
195
|
+
'• **User permissions** - Ensure the user has required permissions\n' +
|
|
196
|
+
'• **Case sensitivity** - Check for typos in username (case-sensitive)\n' +
|
|
197
|
+
'• **User status** - Make sure the user account is active',
|
|
198
|
+
severity: 'error',
|
|
199
|
+
canContinue: false,
|
|
200
|
+
documentationUrl: 'https://github.com/laurigates/foundryvtt-mcp/blob/main/TROUBLESHOOTING.md#authentication-issues',
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Create feature-specific diagnostic
|
|
205
|
+
*/
|
|
206
|
+
async createFeatureSpecificDiagnostic(feature) {
|
|
207
|
+
return {
|
|
208
|
+
explanation: `Connected with full access, but no ${feature} data found.`,
|
|
209
|
+
suggestions: `• **Check data exists** - Verify that ${feature} exist in your FoundryVTT world\n` +
|
|
210
|
+
'• **User permissions** - Ensure you have permission to view this data\n' +
|
|
211
|
+
'• **Module conflicts** - Check if other modules might be interfering\n' +
|
|
212
|
+
`• **Direct test** - Try accessing ${feature} directly in FoundryVTT`,
|
|
213
|
+
severity: 'info',
|
|
214
|
+
canContinue: true,
|
|
215
|
+
documentationUrl: 'https://github.com/laurigates/foundryvtt-mcp/blob/main/TROUBLESHOOTING.md#empty-results',
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Create generic error diagnostic
|
|
220
|
+
*/
|
|
221
|
+
createGenericErrorDiagnostic(_error) {
|
|
222
|
+
return {
|
|
223
|
+
explanation: 'An unexpected error occurred during diagnosis.',
|
|
224
|
+
suggestions: '• **Check logs** - Review server logs for detailed error information\n' +
|
|
225
|
+
'• **Restart services** - Try restarting both FoundryVTT and the MCP server\n' +
|
|
226
|
+
'• **Update software** - Ensure all components are up to date\n' +
|
|
227
|
+
'• **Report issue** - If problem persists, report it on GitHub',
|
|
228
|
+
severity: 'error',
|
|
229
|
+
canContinue: false,
|
|
230
|
+
documentationUrl: 'https://github.com/laurigates/foundryvtt-mcp/issues',
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Test if feature requires REST API
|
|
235
|
+
*/
|
|
236
|
+
requiresRestApi(feature) {
|
|
237
|
+
return ['actors', 'items', 'diagnostics'].includes(feature);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Test REST API availability
|
|
241
|
+
*/
|
|
242
|
+
async testRestApiAvailability() {
|
|
243
|
+
try {
|
|
244
|
+
const response = await this.foundryClient.get('/api/status');
|
|
245
|
+
return (response?.data !== null &&
|
|
246
|
+
response?.data !== undefined &&
|
|
247
|
+
ApiStatusResponseSchema.parse(response.data).status === 'ok');
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
logger.debug('REST API not available:', error);
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Test authentication
|
|
256
|
+
*/
|
|
257
|
+
async testAuthentication() {
|
|
258
|
+
try {
|
|
259
|
+
if (config.foundry.apiKey) {
|
|
260
|
+
// Test API key authentication
|
|
261
|
+
const response = await this.foundryClient.get('/api/world');
|
|
262
|
+
return { valid: !!response };
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
// Test credential authentication (via WebSocket)
|
|
266
|
+
await this.foundryClient.connect();
|
|
267
|
+
return { valid: this.foundryClient.isConnected() };
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
catch (error) {
|
|
271
|
+
return {
|
|
272
|
+
valid: false,
|
|
273
|
+
error: error instanceof Error ? error.message : 'Unknown authentication error',
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Test dice rolling functionality
|
|
279
|
+
*/
|
|
280
|
+
async testDiceRolling() {
|
|
281
|
+
try {
|
|
282
|
+
const result = await this.foundryClient.rollDice('1d20', 'Health check test');
|
|
283
|
+
return typeof result.total === 'number';
|
|
284
|
+
}
|
|
285
|
+
catch (error) {
|
|
286
|
+
logger.debug('Dice rolling test failed:', error);
|
|
287
|
+
return false;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Test actor search functionality
|
|
292
|
+
*/
|
|
293
|
+
async testActorSearch() {
|
|
294
|
+
try {
|
|
295
|
+
const result = await this.foundryClient.searchActors({ limit: 1 });
|
|
296
|
+
return Array.isArray(result.actors);
|
|
297
|
+
}
|
|
298
|
+
catch (error) {
|
|
299
|
+
logger.debug('Actor search test failed:', error);
|
|
300
|
+
return false;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Test item search functionality
|
|
305
|
+
*/
|
|
306
|
+
async testItemSearch() {
|
|
307
|
+
try {
|
|
308
|
+
const result = await this.foundryClient.searchItems({ limit: 1 });
|
|
309
|
+
return Array.isArray(result.items);
|
|
310
|
+
}
|
|
311
|
+
catch (error) {
|
|
312
|
+
logger.debug('Item search test failed:', error);
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Test scene data functionality
|
|
318
|
+
*/
|
|
319
|
+
async testSceneData() {
|
|
320
|
+
try {
|
|
321
|
+
const result = await this.foundryClient.getCurrentScene();
|
|
322
|
+
return !!result && typeof result.name === 'string';
|
|
323
|
+
}
|
|
324
|
+
catch (error) {
|
|
325
|
+
logger.debug('Scene data test failed:', error);
|
|
326
|
+
return false;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
//# sourceMappingURL=diagnostics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostics.js","sourceRoot":"","sources":["../../src/utils/diagnostics.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBA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KAAK,CAAC,CAAC;YAC/C,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Centralized logging utility for FoundryVTT MCP Server
|
|
3
|
+
*
|
|
4
|
+
* This module provides a structured logging system with configurable log levels
|
|
5
|
+
* and consistent formatting across the application. It respects the LOG_LEVEL
|
|
6
|
+
* environment variable for controlling verbosity.
|
|
7
|
+
*
|
|
8
|
+
* @version 0.1.0
|
|
9
|
+
* @author FoundryVTT MCP Team
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Available log levels in order of severity
|
|
13
|
+
*
|
|
14
|
+
* - debug: Detailed information for debugging
|
|
15
|
+
* - info: General information about application flow
|
|
16
|
+
* - warn: Warning messages for potential issues
|
|
17
|
+
* - error: Error messages for failures and exceptions
|
|
18
|
+
*/
|
|
19
|
+
type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
20
|
+
/**
|
|
21
|
+
* Centralized logger class for structured application logging
|
|
22
|
+
*
|
|
23
|
+
* Provides methods for different log levels and automatically filters
|
|
24
|
+
* messages based on the configured minimum log level.
|
|
25
|
+
*
|
|
26
|
+
* @class Logger
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { logger } from './utils/logger.js';
|
|
30
|
+
*
|
|
31
|
+
* logger.info('Server starting...');
|
|
32
|
+
* logger.error('Connection failed:', error);
|
|
33
|
+
* logger.debug('Detailed debug info', { data: someObject });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
declare class Logger {
|
|
37
|
+
private logLevel;
|
|
38
|
+
private levels;
|
|
39
|
+
/**
|
|
40
|
+
* Creates a new Logger instance
|
|
41
|
+
*
|
|
42
|
+
* @param logLevel - Minimum log level to display (default: 'info')
|
|
43
|
+
*/
|
|
44
|
+
constructor(logLevel?: LogLevel);
|
|
45
|
+
/**
|
|
46
|
+
* Determines if a message should be logged based on current log level
|
|
47
|
+
*
|
|
48
|
+
* @private
|
|
49
|
+
* @param level - The log level to check
|
|
50
|
+
* @returns True if the message should be logged, false otherwise
|
|
51
|
+
*/
|
|
52
|
+
private shouldLog;
|
|
53
|
+
/**
|
|
54
|
+
* Formats a log message with timestamp, level, and optional metadata
|
|
55
|
+
*
|
|
56
|
+
* @private
|
|
57
|
+
* @param level - The log level
|
|
58
|
+
* @param message - The main log message
|
|
59
|
+
* @param meta - Optional metadata object
|
|
60
|
+
* @returns Formatted log message string
|
|
61
|
+
*/
|
|
62
|
+
private formatMessage;
|
|
63
|
+
/**
|
|
64
|
+
* Logs a debug message (lowest priority)
|
|
65
|
+
*
|
|
66
|
+
* Used for detailed information that's only needed when debugging issues.
|
|
67
|
+
* Only shown when LOG_LEVEL is set to 'debug'.
|
|
68
|
+
*
|
|
69
|
+
* @param message - The debug message
|
|
70
|
+
* @param meta - Optional metadata object
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* logger.debug('Processing user request', { userId: '123', action: 'search' });
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
debug(message: string, meta?: unknown): void;
|
|
77
|
+
/**
|
|
78
|
+
* Logs an informational message
|
|
79
|
+
*
|
|
80
|
+
* Used for general information about application flow and important events.
|
|
81
|
+
* Shown when LOG_LEVEL is 'debug' or 'info'.
|
|
82
|
+
*
|
|
83
|
+
* @param message - The info message
|
|
84
|
+
* @param meta - Optional metadata object
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* logger.info('Server started successfully', { port: 3000 });
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
info(message: string, meta?: unknown): void;
|
|
91
|
+
/**
|
|
92
|
+
* Logs a warning message
|
|
93
|
+
*
|
|
94
|
+
* Used for potentially problematic situations that don't prevent operation
|
|
95
|
+
* but should be noted. Shown when LOG_LEVEL is 'debug', 'info', or 'warn'.
|
|
96
|
+
*
|
|
97
|
+
* @param message - The warning message
|
|
98
|
+
* @param meta - Optional metadata object
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* logger.warn('Deprecated API endpoint used', { endpoint: '/old-api' });
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
warn(message: string, meta?: unknown): void;
|
|
105
|
+
/**
|
|
106
|
+
* Logs an error message (highest priority)
|
|
107
|
+
*
|
|
108
|
+
* Used for error conditions and exceptions that affect application operation.
|
|
109
|
+
* Always shown regardless of LOG_LEVEL setting.
|
|
110
|
+
*
|
|
111
|
+
* @param message - The error message
|
|
112
|
+
* @param error - Optional error object or metadata
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* logger.error('Database connection failed', error);
|
|
116
|
+
* logger.error('Invalid user input', { input: userData, validation: errors });
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
error(message: string, error?: unknown): void;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Global logger instance
|
|
123
|
+
*
|
|
124
|
+
* Pre-configured logger instance ready for use throughout the application.
|
|
125
|
+
* Respects the LOG_LEVEL environment variable for filtering messages.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* import { logger } from './utils/logger.js';
|
|
130
|
+
*
|
|
131
|
+
* logger.info('Application starting');
|
|
132
|
+
* logger.error('Something went wrong', error);
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
export declare const logger: Logger;
|
|
136
|
+
export {};
|
|
137
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH;;;;;;;GAOG;AACH,KAAK,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAEpD;;;;;;;;;;;;;;;GAeG;AACH,cAAM,MAAM;IACV,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,MAAM,CAKZ;IAEF;;;;OAIG;gBACS,QAAQ,GAAE,QAAiB;IAIvC;;;;;;OAMG;IACH,OAAO,CAAC,SAAS;IAIjB;;;;;;;;OAQG;IACH,OAAO,CAAC,aAAa;IAMrB;;;;;;;;;;;;OAYG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAM5C;;;;;;;;;;;;OAYG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAM3C;;;;;;;;;;;;OAYG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAM3C;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI;CAO9C;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,MAAM,QAA8B,CAAC"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Centralized logging utility for FoundryVTT MCP Server
|
|
3
|
+
*
|
|
4
|
+
* This module provides a structured logging system with configurable log levels
|
|
5
|
+
* and consistent formatting across the application. It respects the LOG_LEVEL
|
|
6
|
+
* environment variable for controlling verbosity.
|
|
7
|
+
*
|
|
8
|
+
* @version 0.1.0
|
|
9
|
+
* @author FoundryVTT MCP Team
|
|
10
|
+
*/
|
|
11
|
+
import { config } from '../config/index.js';
|
|
12
|
+
/**
|
|
13
|
+
* Centralized logger class for structured application logging
|
|
14
|
+
*
|
|
15
|
+
* Provides methods for different log levels and automatically filters
|
|
16
|
+
* messages based on the configured minimum log level.
|
|
17
|
+
*
|
|
18
|
+
* @class Logger
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { logger } from './utils/logger.js';
|
|
22
|
+
*
|
|
23
|
+
* logger.info('Server starting...');
|
|
24
|
+
* logger.error('Connection failed:', error);
|
|
25
|
+
* logger.debug('Detailed debug info', { data: someObject });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
class Logger {
|
|
29
|
+
logLevel;
|
|
30
|
+
levels = {
|
|
31
|
+
debug: 0,
|
|
32
|
+
info: 1,
|
|
33
|
+
warn: 2,
|
|
34
|
+
error: 3,
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Creates a new Logger instance
|
|
38
|
+
*
|
|
39
|
+
* @param logLevel - Minimum log level to display (default: 'info')
|
|
40
|
+
*/
|
|
41
|
+
constructor(logLevel = 'info') {
|
|
42
|
+
this.logLevel = logLevel;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Determines if a message should be logged based on current log level
|
|
46
|
+
*
|
|
47
|
+
* @private
|
|
48
|
+
* @param level - The log level to check
|
|
49
|
+
* @returns True if the message should be logged, false otherwise
|
|
50
|
+
*/
|
|
51
|
+
shouldLog(level) {
|
|
52
|
+
return this.levels[level] >= this.levels[this.logLevel];
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Formats a log message with timestamp, level, and optional metadata
|
|
56
|
+
*
|
|
57
|
+
* @private
|
|
58
|
+
* @param level - The log level
|
|
59
|
+
* @param message - The main log message
|
|
60
|
+
* @param meta - Optional metadata object
|
|
61
|
+
* @returns Formatted log message string
|
|
62
|
+
*/
|
|
63
|
+
formatMessage(level, message, meta) {
|
|
64
|
+
const timestamp = new Date().toISOString();
|
|
65
|
+
const metaStr = meta ? ` ${JSON.stringify(meta)}` : '';
|
|
66
|
+
return `[${timestamp}] ${level.toUpperCase()}: ${message}${metaStr}`;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Logs a debug message (lowest priority)
|
|
70
|
+
*
|
|
71
|
+
* Used for detailed information that's only needed when debugging issues.
|
|
72
|
+
* Only shown when LOG_LEVEL is set to 'debug'.
|
|
73
|
+
*
|
|
74
|
+
* @param message - The debug message
|
|
75
|
+
* @param meta - Optional metadata object
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* logger.debug('Processing user request', { userId: '123', action: 'search' });
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
debug(message, meta) {
|
|
82
|
+
if (this.shouldLog('debug')) {
|
|
83
|
+
console.debug(this.formatMessage('debug', message, meta));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Logs an informational message
|
|
88
|
+
*
|
|
89
|
+
* Used for general information about application flow and important events.
|
|
90
|
+
* Shown when LOG_LEVEL is 'debug' or 'info'.
|
|
91
|
+
*
|
|
92
|
+
* @param message - The info message
|
|
93
|
+
* @param meta - Optional metadata object
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* logger.info('Server started successfully', { port: 3000 });
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
info(message, meta) {
|
|
100
|
+
if (this.shouldLog('info')) {
|
|
101
|
+
console.info(this.formatMessage('info', message, meta));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Logs a warning message
|
|
106
|
+
*
|
|
107
|
+
* Used for potentially problematic situations that don't prevent operation
|
|
108
|
+
* but should be noted. Shown when LOG_LEVEL is 'debug', 'info', or 'warn'.
|
|
109
|
+
*
|
|
110
|
+
* @param message - The warning message
|
|
111
|
+
* @param meta - Optional metadata object
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* logger.warn('Deprecated API endpoint used', { endpoint: '/old-api' });
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
warn(message, meta) {
|
|
118
|
+
if (this.shouldLog('warn')) {
|
|
119
|
+
console.warn(this.formatMessage('warn', message, meta));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Logs an error message (highest priority)
|
|
124
|
+
*
|
|
125
|
+
* Used for error conditions and exceptions that affect application operation.
|
|
126
|
+
* Always shown regardless of LOG_LEVEL setting.
|
|
127
|
+
*
|
|
128
|
+
* @param message - The error message
|
|
129
|
+
* @param error - Optional error object or metadata
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* logger.error('Database connection failed', error);
|
|
133
|
+
* logger.error('Invalid user input', { input: userData, validation: errors });
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
error(message, error) {
|
|
137
|
+
if (this.shouldLog('error')) {
|
|
138
|
+
const errorDetails = error instanceof Error ? { message: error.message, stack: error.stack } : error;
|
|
139
|
+
console.error(this.formatMessage('error', message, errorDetails));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Global logger instance
|
|
145
|
+
*
|
|
146
|
+
* Pre-configured logger instance ready for use throughout the application.
|
|
147
|
+
* Respects the LOG_LEVEL environment variable for filtering messages.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* import { logger } from './utils/logger.js';
|
|
152
|
+
*
|
|
153
|
+
* logger.info('Application starting');
|
|
154
|
+
* logger.error('Something went wrong', error);
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
export const logger = new Logger(config.logLevel);
|
|
158
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAY5C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM;IACF,QAAQ,CAAW;IACnB,MAAM,GAA6B;QACzC,KAAK,EAAE,CAAC;QACR,IAAI,EAAE,CAAC;QACP,IAAI,EAAE,CAAC;QACP,KAA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