@west10tech/constructionwire-mcp 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +177 -0
- package/dist/clients/constructionwire-client.d.ts +110 -0
- package/dist/clients/constructionwire-client.d.ts.map +1 -0
- package/dist/clients/constructionwire-client.js +16746 -0
- package/dist/clients/constructionwire-client.js.map +1 -0
- package/dist/config.d.ts +23 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +63 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +165 -0
- package/dist/index.js.map +1 -0
- package/dist/services/log-batcher.d.ts +44 -0
- package/dist/services/log-batcher.d.ts.map +1 -0
- package/dist/services/log-batcher.js +81 -0
- package/dist/services/log-batcher.js.map +1 -0
- package/dist/services/log-shipper.d.ts +104 -0
- package/dist/services/log-shipper.d.ts.map +1 -0
- package/dist/services/log-shipper.js +384 -0
- package/dist/services/log-shipper.js.map +1 -0
- package/dist/services/logger.d.ts +92 -0
- package/dist/services/logger.d.ts.map +1 -0
- package/dist/services/logger.js +224 -0
- package/dist/services/logger.js.map +1 -0
- package/dist/services/progress-reporter.d.ts +64 -0
- package/dist/services/progress-reporter.d.ts.map +1 -0
- package/dist/services/progress-reporter.js +192 -0
- package/dist/services/progress-reporter.js.map +1 -0
- package/dist/services/request-tracker.d.ts +55 -0
- package/dist/services/request-tracker.d.ts.map +1 -0
- package/dist/services/request-tracker.js +184 -0
- package/dist/services/request-tracker.js.map +1 -0
- package/dist/tools/constructionwire-tools.d.ts +23 -0
- package/dist/tools/constructionwire-tools.d.ts.map +1 -0
- package/dist/tools/constructionwire-tools.js +8973 -0
- package/dist/tools/constructionwire-tools.js.map +1 -0
- package/dist/types.d.ts +25 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +57 -0
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface ServerConfig {
|
|
2
|
+
logShipping: {
|
|
3
|
+
enabled: boolean;
|
|
4
|
+
endpoint: string;
|
|
5
|
+
apiKey?: string;
|
|
6
|
+
requireApiKey?: boolean;
|
|
7
|
+
batchSize: number;
|
|
8
|
+
flushInterval: number;
|
|
9
|
+
maxRetries: number;
|
|
10
|
+
logLevel: 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'FATAL';
|
|
11
|
+
};
|
|
12
|
+
constructionwire: {
|
|
13
|
+
cONSTRUCTIONWIREUSERNAME: string;
|
|
14
|
+
cONSTRUCTIONWIREPASSWORD: string;
|
|
15
|
+
api_base_url: any;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export declare function loadConfig(): ServerConfig;
|
|
19
|
+
export declare function validateConfig(config: ServerConfig): {
|
|
20
|
+
isValid: boolean;
|
|
21
|
+
errors: string[];
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAE3B,WAAW,EAAE;QACX,OAAO,EAAE,OAAO,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,aAAa,CAAC,EAAE,OAAO,CAAC;QACxB,SAAS,EAAE,MAAM,CAAC;QAClB,aAAa,EAAE,MAAM,CAAC;QACtB,UAAU,EAAE,MAAM,CAAC;QACnB,QAAQ,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;KACzD,CAAC;IAEF,gBAAgB,EAAE;QAChB,wBAAwB,EAAE,MAAM,CAAC;QACjC,wBAAwB,EAAE,MAAM,CAAC;QACjC,YAAY,EAAE,GAAG,CAAC;KACnB,CAAC;CACH;AAED,wBAAgB,UAAU,IAAI,YAAY,CAoBzC;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,YAAY,GAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CA+C3F"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export function loadConfig() {
|
|
2
|
+
return {
|
|
3
|
+
// Log shipping configuration
|
|
4
|
+
logShipping: {
|
|
5
|
+
enabled: process.env.LOG_SHIPPING_ENABLED === 'true',
|
|
6
|
+
endpoint: process.env.LOG_INGESTION_URL || '',
|
|
7
|
+
...(process.env.LOG_INGESTION_API_KEY && { apiKey: process.env.LOG_INGESTION_API_KEY }),
|
|
8
|
+
requireApiKey: process.env.LOG_SHIPPING_REQUIRE_API_KEY === 'true',
|
|
9
|
+
batchSize: parseInt(process.env.LOG_SHIPPING_BATCH_SIZE || '500', 10),
|
|
10
|
+
flushInterval: parseInt(process.env.LOG_SHIPPING_INTERVAL || '5000', 10),
|
|
11
|
+
maxRetries: parseInt(process.env.LOG_SHIPPING_MAX_RETRIES || '3', 10),
|
|
12
|
+
logLevel: (process.env.LOG_LEVEL || 'ERROR')
|
|
13
|
+
},
|
|
14
|
+
constructionwire: {
|
|
15
|
+
cONSTRUCTIONWIREUSERNAME: process.env.CONSTRUCTIONWIRE_USERNAME || '',
|
|
16
|
+
cONSTRUCTIONWIREPASSWORD: process.env.CONSTRUCTIONWIRE_PASSWORD || '',
|
|
17
|
+
api_base_url: "https://api.constructionwire.com/v1",
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export function validateConfig(config) {
|
|
22
|
+
const errors = [];
|
|
23
|
+
// Validate log shipping configuration
|
|
24
|
+
if (config.logShipping.enabled) {
|
|
25
|
+
if (!config.logShipping.endpoint) {
|
|
26
|
+
errors.push('LOG_INGESTION_URL environment variable is required when log shipping is enabled');
|
|
27
|
+
}
|
|
28
|
+
// API key validation based on requireApiKey flag
|
|
29
|
+
if (config.logShipping.requireApiKey && !config.logShipping.apiKey) {
|
|
30
|
+
errors.push('LOG_INGESTION_API_KEY environment variable is required when LOG_SHIPPING_REQUIRE_API_KEY is true');
|
|
31
|
+
}
|
|
32
|
+
// Warning for missing API key (not an error during transition)
|
|
33
|
+
if (!config.logShipping.apiKey && !config.logShipping.requireApiKey) {
|
|
34
|
+
console.warn('[CONFIG WARNING] LOG_INGESTION_API_KEY not set. Log shipping will work now but will require an API key in the future.');
|
|
35
|
+
console.warn('[CONFIG WARNING] Set LOG_INGESTION_API_KEY to prepare for future requirements.');
|
|
36
|
+
}
|
|
37
|
+
if (config.logShipping.endpoint && !config.logShipping.endpoint.startsWith('https://')) {
|
|
38
|
+
errors.push('LOG_INGESTION_URL must use HTTPS protocol');
|
|
39
|
+
}
|
|
40
|
+
if (config.logShipping.batchSize < 1 || config.logShipping.batchSize > 1000) {
|
|
41
|
+
errors.push('LOG_SHIPPING_BATCH_SIZE must be between 1 and 1000');
|
|
42
|
+
}
|
|
43
|
+
if (config.logShipping.flushInterval < 1000) {
|
|
44
|
+
errors.push('LOG_SHIPPING_INTERVAL must be at least 1000ms');
|
|
45
|
+
}
|
|
46
|
+
if (!['DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL'].includes(config.logShipping.logLevel)) {
|
|
47
|
+
errors.push('LOG_LEVEL must be one of: DEBUG, INFO, WARN, ERROR, FATAL');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// Validate constructionwire configuration
|
|
51
|
+
// ConstructionWire specific validation
|
|
52
|
+
if (!process.env.CONSTRUCTIONWIRE_EMAIL) {
|
|
53
|
+
errors.push('CONSTRUCTIONWIRE_EMAIL environment variable is required for ConstructionWire basic+bearer authentication');
|
|
54
|
+
}
|
|
55
|
+
if (!process.env.CONSTRUCTIONWIRE_PASSWORD) {
|
|
56
|
+
errors.push('CONSTRUCTIONWIRE_PASSWORD environment variable is required for ConstructionWire basic+bearer authentication');
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
isValid: errors.length === 0,
|
|
60
|
+
errors
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAoBA,MAAM,UAAU,UAAU;IACxB,OAAO;QACL,6BAA6B;QAC7B,WAAW,EAAE;YACX,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAoB,KAAK,MAAM;YACpD,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,EAAE;YAC7C,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,CAAC;YACvF,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,4BAA4B,KAAK,MAAM;YAClE,SAAS,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,IAAI,KAAK,EAAE,EAAE,CAAC;YACrE,aAAa,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,MAAM,EAAE,EAAE,CAAC;YACxE,UAAU,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,wBAAwB,IAAI,GAAG,EAAE,EAAE,CAAC;YACrE,QAAQ,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,OAAO,CAAkD;SAC9F;QAED,gBAAgB,EAAE;YAChB,wBAAwB,EAAE,OAAO,CAAC,GAAG,CAAC,yBAAyB,IAAI,EAAE;YACrE,wBAAwB,EAAE,OAAO,CAAC,GAAG,CAAC,yBAAyB,IAAI,EAAE;YACrE,YAAY,EAAE,qCAAqC;SACpD;KACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,MAAoB;IACjD,MAAM,MAAM,GAAa,EAAE,CAAC;IA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EAAE,CAAC;YACvF,MAAM,CAAC,IAAI,CAAC,2DAA2D,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;IAED,0CAA0C;IAC1C,uCAAuC;IACvC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,sBAAsB,EAAE,CAAC;QACxC,MAAM,CAAC,IAAI,CAAC,0GAA0G,CAAC,CAAC;IAC1H,CAAC;IACD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,yBAAyB,EAAE,CAAC;QAC3C,MAAM,CAAC,IAAI,CAAC,6GAA6G,CAAC,CAAC;IAC7H,CAAC;IAED,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;QAC5B,MAAM;KACP,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
3
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
|
+
import { CallToolRequestSchema, ErrorCode, ListToolsRequestSchema, McpError, CancelledNotificationSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
5
|
+
import { config } from 'dotenv';
|
|
6
|
+
import { loadConfig, validateConfig } from './config.js';
|
|
7
|
+
import { LogShipper } from './services/log-shipper.js';
|
|
8
|
+
import { Logger } from './services/logger.js';
|
|
9
|
+
import { RequestTracker } from './services/request-tracker.js';
|
|
10
|
+
import { ProgressReporter } from './services/progress-reporter.js';
|
|
11
|
+
// Load environment variables
|
|
12
|
+
config();
|
|
13
|
+
// Import tools from each template
|
|
14
|
+
import { ConstructionwireTools } from './tools/constructionwire-tools.js';
|
|
15
|
+
import { ConstructionwireClient } from './clients/constructionwire-client.js';
|
|
16
|
+
// Import OAuth clients only if OAuth is enabled globally
|
|
17
|
+
// Import unified OAuth clients for special cases
|
|
18
|
+
class ConstructionwireMcpServer {
|
|
19
|
+
// OAuth clients
|
|
20
|
+
constructor() {
|
|
21
|
+
// Initialize logging first
|
|
22
|
+
this.initializeLogging();
|
|
23
|
+
this.server = new Server({
|
|
24
|
+
name: 'constructionwire-mcp',
|
|
25
|
+
version: '1.0.0',
|
|
26
|
+
}, {
|
|
27
|
+
capabilities: {
|
|
28
|
+
tools: {},
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
// Initialize OAuth clients first
|
|
32
|
+
// Initialize template clients and tools
|
|
33
|
+
// Regular client - pass configuration object
|
|
34
|
+
this.constructionwireClient = new ConstructionwireClient({
|
|
35
|
+
authToken: process.env.CONSTRUCTIONWIRE_USERNAME,
|
|
36
|
+
cONSTRUCTIONWIREUSERNAME: process.env.CONSTRUCTIONWIRE_USERNAME,
|
|
37
|
+
cONSTRUCTIONWIREPASSWORD: process.env.CONSTRUCTIONWIRE_PASSWORD,
|
|
38
|
+
api_base_url: "https://api.constructionwire.com/v1",
|
|
39
|
+
logger: this.logger
|
|
40
|
+
});
|
|
41
|
+
this.constructionwireTools = new ConstructionwireTools(this.constructionwireClient);
|
|
42
|
+
this.setupHandlers();
|
|
43
|
+
this.setupNotificationHandlers();
|
|
44
|
+
}
|
|
45
|
+
initializeLogging() {
|
|
46
|
+
const config = loadConfig();
|
|
47
|
+
const validation = validateConfig(config);
|
|
48
|
+
if (!validation.isValid) {
|
|
49
|
+
console.error('Configuration validation failed:', validation.errors);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
this.logShipper = new LogShipper(config.logShipping);
|
|
53
|
+
this.logger = new Logger({
|
|
54
|
+
logLevel: config.logShipping.logLevel,
|
|
55
|
+
component: 'server',
|
|
56
|
+
enableConsole: true,
|
|
57
|
+
enableShipping: config.logShipping.enabled,
|
|
58
|
+
serverName: 'constructionwire-mcp',
|
|
59
|
+
logShipper: this.logShipper
|
|
60
|
+
});
|
|
61
|
+
this.logger.info('SERVER_INIT', 'MCP server initializing', {
|
|
62
|
+
serverName: 'constructionwire-mcp',
|
|
63
|
+
logShippingEnabled: config.logShipping.enabled,
|
|
64
|
+
logLevel: config.logShipping.logLevel
|
|
65
|
+
});
|
|
66
|
+
// Initialize request tracking and progress reporting
|
|
67
|
+
this.requestTracker = new RequestTracker(this.logger);
|
|
68
|
+
this.progressReporter = new ProgressReporter(this.server, this.logger, this.requestTracker);
|
|
69
|
+
// Set up periodic cleanup
|
|
70
|
+
setInterval(() => {
|
|
71
|
+
this.requestTracker.cleanupStaleRequests();
|
|
72
|
+
this.progressReporter.cleanupCompletedRequests();
|
|
73
|
+
}, 60000);
|
|
74
|
+
}
|
|
75
|
+
setupHandlers() {
|
|
76
|
+
this.server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
77
|
+
const tools = [];
|
|
78
|
+
// Add constructionwire tools
|
|
79
|
+
tools.push(...this.constructionwireTools.getToolDefinitions());
|
|
80
|
+
return { tools };
|
|
81
|
+
});
|
|
82
|
+
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
83
|
+
const { name, arguments: args } = request.params;
|
|
84
|
+
const requestId = request.id;
|
|
85
|
+
const progressToken = request.params._meta?.progressToken;
|
|
86
|
+
// Register request for tracking
|
|
87
|
+
const context = this.requestTracker.registerRequest(requestId, progressToken, name);
|
|
88
|
+
try {
|
|
89
|
+
// Handle constructionwire tools
|
|
90
|
+
if (this.constructionwireTools.canHandle(name)) {
|
|
91
|
+
return await this.constructionwireTools.executeTool(name, args, context, this.progressReporter);
|
|
92
|
+
}
|
|
93
|
+
throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${name}`);
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
// Check if error is due to cancellation
|
|
97
|
+
if (context.abortController.signal.aborted) {
|
|
98
|
+
this.logger.info('REQUEST_ABORTED', 'Request was cancelled', {
|
|
99
|
+
requestId,
|
|
100
|
+
toolName: name,
|
|
101
|
+
reason: context.abortController.signal.reason
|
|
102
|
+
});
|
|
103
|
+
throw new McpError(ErrorCode.InternalError, 'Request was cancelled');
|
|
104
|
+
}
|
|
105
|
+
if (error instanceof McpError) {
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
throw new McpError(ErrorCode.InternalError, `Tool execution failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
// Clean up request tracking
|
|
112
|
+
this.requestTracker.cleanup(requestId);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
setupNotificationHandlers() {
|
|
117
|
+
// Handle cancellation notifications
|
|
118
|
+
this.server.setNotificationHandler(CancelledNotificationSchema, async (notification) => {
|
|
119
|
+
const { requestId, reason } = notification.params;
|
|
120
|
+
this.logger.info('CANCELLATION_RECEIVED', 'Received cancellation notification', {
|
|
121
|
+
requestId,
|
|
122
|
+
reason
|
|
123
|
+
});
|
|
124
|
+
// Cancel the request
|
|
125
|
+
const cancelled = this.requestTracker.cancelRequest(requestId, reason);
|
|
126
|
+
if (!cancelled) {
|
|
127
|
+
this.logger.debug('CANCELLATION_IGNORED', 'Cancellation ignored - request not found or already completed', {
|
|
128
|
+
requestId
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
async run() {
|
|
134
|
+
const transport = new StdioServerTransport();
|
|
135
|
+
await this.server.connect(transport);
|
|
136
|
+
this.logger.info('SERVER_START', 'MCP server started successfully', {
|
|
137
|
+
serverName: 'constructionwire-mcp',
|
|
138
|
+
transport: 'stdio'
|
|
139
|
+
});
|
|
140
|
+
console.error('constructionwire-mcp MCP server running on stdio');
|
|
141
|
+
// Handle graceful shutdown for log shipping
|
|
142
|
+
const shutdown = async () => {
|
|
143
|
+
this.logger.info('SERVER_SHUTDOWN', 'MCP server shutting down', {
|
|
144
|
+
serverName: 'constructionwire-mcp'
|
|
145
|
+
});
|
|
146
|
+
// Shutdown request tracking and progress reporting
|
|
147
|
+
if (this.requestTracker) {
|
|
148
|
+
this.requestTracker.shutdown();
|
|
149
|
+
}
|
|
150
|
+
if (this.progressReporter) {
|
|
151
|
+
this.progressReporter.shutdown();
|
|
152
|
+
}
|
|
153
|
+
// Shutdown logging
|
|
154
|
+
if (this.logShipper) {
|
|
155
|
+
await this.logShipper.shutdown();
|
|
156
|
+
}
|
|
157
|
+
process.exit(0);
|
|
158
|
+
};
|
|
159
|
+
process.on('SIGINT', shutdown);
|
|
160
|
+
process.on('SIGTERM', shutdown);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const server = new ConstructionwireMcpServer();
|
|
164
|
+
server.run().catch(console.error);
|
|
165
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,SAAS,EACT,sBAAsB,EACtB,QAAQ,EACR,2BAA2B,GAC5B,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAEnE,6BAA6B;AAC7B,MAAM,EAAE,CAAC;AAET,kCAAkC;AAClC,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CA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AC;QAElE,4CAA4C;QAC5C,MAAM,QAAQ,GAAG,KAAK,IAAI,EAAE;YAC1B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,EAAE,0BAA0B,EAAE;gBAC9D,UAAU,EAAE,sBAAsB;aACnC,CAAC,CAAC;YAEH,mDAAmD;YACnD,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;gBACxB,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC;YACjC,CAAC;YACD,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;gBAC1B,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAC;YACnC,CAAC;YAED,mBAAmB;YACnB,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;gBACpB,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC;YACnC,CAAC;YAED,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC;QAEF,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC/B,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAClC,CAAC;CACF;AAED,MAAM,MAAM,GAAG,IAAI,yBAAyB,EAAE,CAAC;AAC/C,MAAM,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LogBatcher - Implements the exact batching logic as specified in requirements
|
|
3
|
+
* Batches logs and sends them to the centralized logging endpoint
|
|
4
|
+
*/
|
|
5
|
+
import { LogShipper, LogEntry } from './log-shipper.js';
|
|
6
|
+
export declare class LogBatcher {
|
|
7
|
+
private logs;
|
|
8
|
+
private maxBatchSize;
|
|
9
|
+
private flushInterval;
|
|
10
|
+
private sessionId;
|
|
11
|
+
private logShipper;
|
|
12
|
+
private flushTimer;
|
|
13
|
+
constructor(logShipper: LogShipper, maxBatchSize?: number, flushInterval?: number);
|
|
14
|
+
/**
|
|
15
|
+
* Add a structured log entry to the batch
|
|
16
|
+
*/
|
|
17
|
+
addStructuredLog(logEntry: LogEntry): void;
|
|
18
|
+
/**
|
|
19
|
+
* Flush all batched logs
|
|
20
|
+
*/
|
|
21
|
+
flush(): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Get the session ID for this batcher instance
|
|
24
|
+
*/
|
|
25
|
+
getSessionId(): string;
|
|
26
|
+
/**
|
|
27
|
+
* Generate a unique session ID
|
|
28
|
+
*/
|
|
29
|
+
private generateSessionId;
|
|
30
|
+
/**
|
|
31
|
+
* Get current batch status
|
|
32
|
+
*/
|
|
33
|
+
getBatchStatus(): {
|
|
34
|
+
queueSize: number;
|
|
35
|
+
maxBatchSize: number;
|
|
36
|
+
flushInterval: number;
|
|
37
|
+
sessionId: string;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Shutdown the batcher and flush remaining logs
|
|
41
|
+
*/
|
|
42
|
+
shutdown(): Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=log-batcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-batcher.d.ts","sourceRoot":"","sources":["../../src/services/log-batcher.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAExD,qBAAa,UAAU;IACrB,OAAO,CAAC,IAAI,CAAkB;IAC9B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,UAAU,CAA+B;gBAErC,UAAU,EAAE,UAAU,EAAE,YAAY,GAAE,MAAY,EAAE,aAAa,GAAE,MAAa;IAU5F;;OAEG;IACH,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;IAS1C;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAkB5B;;OAEG;IACH,YAAY,IAAI,MAAM;IAItB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAIzB;;OAEG;IACH,cAAc,IAAI;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE;IASvG;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAShC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LogBatcher - Implements the exact batching logic as specified in requirements
|
|
3
|
+
* Batches logs and sends them to the centralized logging endpoint
|
|
4
|
+
*/
|
|
5
|
+
export class LogBatcher {
|
|
6
|
+
constructor(logShipper, maxBatchSize = 500, flushInterval = 5000) {
|
|
7
|
+
this.logs = [];
|
|
8
|
+
this.flushTimer = null;
|
|
9
|
+
this.logShipper = logShipper;
|
|
10
|
+
this.maxBatchSize = maxBatchSize;
|
|
11
|
+
this.flushInterval = flushInterval;
|
|
12
|
+
this.sessionId = this.generateSessionId();
|
|
13
|
+
// Start the flush timer
|
|
14
|
+
this.flushTimer = setInterval(() => this.flush(), this.flushInterval);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Add a structured log entry to the batch
|
|
18
|
+
*/
|
|
19
|
+
addStructuredLog(logEntry) {
|
|
20
|
+
this.logs.push(logEntry);
|
|
21
|
+
// Flush immediately if batch size reached
|
|
22
|
+
if (this.logs.length >= this.maxBatchSize) {
|
|
23
|
+
this.flush();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Flush all batched logs
|
|
28
|
+
*/
|
|
29
|
+
async flush() {
|
|
30
|
+
if (this.logs.length === 0)
|
|
31
|
+
return;
|
|
32
|
+
const batch = this.logs.splice(0, this.maxBatchSize);
|
|
33
|
+
try {
|
|
34
|
+
// Send each structured log through the LogShipper
|
|
35
|
+
for (const logEntry of batch) {
|
|
36
|
+
this.logShipper.addLog(logEntry);
|
|
37
|
+
}
|
|
38
|
+
// Trigger immediate flush in LogShipper
|
|
39
|
+
await this.logShipper.flush();
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
console.error('Failed to send logs:', error);
|
|
43
|
+
// Could implement retry logic here
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get the session ID for this batcher instance
|
|
48
|
+
*/
|
|
49
|
+
getSessionId() {
|
|
50
|
+
return this.sessionId;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Generate a unique session ID
|
|
54
|
+
*/
|
|
55
|
+
generateSessionId() {
|
|
56
|
+
return `constructionwire-mcp-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get current batch status
|
|
60
|
+
*/
|
|
61
|
+
getBatchStatus() {
|
|
62
|
+
return {
|
|
63
|
+
queueSize: this.logs.length,
|
|
64
|
+
maxBatchSize: this.maxBatchSize,
|
|
65
|
+
flushInterval: this.flushInterval,
|
|
66
|
+
sessionId: this.sessionId
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Shutdown the batcher and flush remaining logs
|
|
71
|
+
*/
|
|
72
|
+
async shutdown() {
|
|
73
|
+
if (this.flushTimer) {
|
|
74
|
+
clearInterval(this.flushTimer);
|
|
75
|
+
this.flushTimer = null;
|
|
76
|
+
}
|
|
77
|
+
// Flush any remaining logs
|
|
78
|
+
await this.flush();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=log-batcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-batcher.js","sourceRoot":"","sources":["../../src/services/log-batcher.ts"],"names":[],"mappings":"AAAA;;;GAG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AK,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC;YAC7C,mCAAmC;QACrC,CAAC;IACH,CAAC;IAED;;OAEG;IACH,YAAY;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;OAEG;IACK,iBAAiB;QACvB,OAAO,wBAAwB,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;IAC5F,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,OAAO;YACL,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM;YAC3B,YAAY,EAAE,IAAI,CAAC,YAAY;YAC/B,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,SAAS,EAAE,IAAI,CAAC,SAAS;SAC1B,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,QAAQ;QACZ,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAC/B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACzB,CAAC;QAED,2BAA2B;QAC3B,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;CACF"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LogShipper - Centralized log shipping service for constructionwire-mcp
|
|
3
|
+
* Sends logs to the centralized logging API endpoint with batching and retry logic
|
|
4
|
+
*/
|
|
5
|
+
export interface LogEntry {
|
|
6
|
+
timestamp: string;
|
|
7
|
+
level: string;
|
|
8
|
+
sessionId: string;
|
|
9
|
+
user: string;
|
|
10
|
+
integration: string;
|
|
11
|
+
component: string;
|
|
12
|
+
action: string;
|
|
13
|
+
message: string;
|
|
14
|
+
serverName: string;
|
|
15
|
+
projectId?: string;
|
|
16
|
+
organizationId?: string;
|
|
17
|
+
metadata?: {
|
|
18
|
+
toolParams?: any;
|
|
19
|
+
responseData?: any;
|
|
20
|
+
errorDetails?: any;
|
|
21
|
+
duration_ms?: number;
|
|
22
|
+
httpStatus?: number;
|
|
23
|
+
responseSize?: number;
|
|
24
|
+
requestId?: string;
|
|
25
|
+
executionId?: string;
|
|
26
|
+
[key: string]: any;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export interface LogBatch {
|
|
30
|
+
logs: LogEntry[];
|
|
31
|
+
}
|
|
32
|
+
export interface LogShipperConfig {
|
|
33
|
+
endpoint: string;
|
|
34
|
+
apiKey?: string;
|
|
35
|
+
requireApiKey?: boolean;
|
|
36
|
+
batchSize: number;
|
|
37
|
+
flushInterval: number;
|
|
38
|
+
maxRetries: number;
|
|
39
|
+
enabled: boolean;
|
|
40
|
+
}
|
|
41
|
+
export declare class LogShipper {
|
|
42
|
+
private config;
|
|
43
|
+
private logQueue;
|
|
44
|
+
private flushTimer;
|
|
45
|
+
private isShuttingDown;
|
|
46
|
+
private lastSuccessfulFlush;
|
|
47
|
+
constructor(config: LogShipperConfig);
|
|
48
|
+
private validateConfig;
|
|
49
|
+
private startFlushTimer;
|
|
50
|
+
/**
|
|
51
|
+
* Add a log entry to the queue
|
|
52
|
+
*/
|
|
53
|
+
addLog(logEntry: LogEntry): void;
|
|
54
|
+
/**
|
|
55
|
+
* Flush all queued logs to the endpoint
|
|
56
|
+
*/
|
|
57
|
+
flush(): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Send logs with retry logic
|
|
60
|
+
*/
|
|
61
|
+
private sendLogsWithRetry;
|
|
62
|
+
/**
|
|
63
|
+
* Map component values to API-accepted enum values
|
|
64
|
+
*/
|
|
65
|
+
private mapComponentToValidEnum;
|
|
66
|
+
/**
|
|
67
|
+
* Map log level to API-accepted enum values (lowercase)
|
|
68
|
+
*/
|
|
69
|
+
private mapLogLevelToValidEnum;
|
|
70
|
+
/**
|
|
71
|
+
* Validate and clean log entries to ensure API compatibility
|
|
72
|
+
*/
|
|
73
|
+
private validateAndCleanLogs;
|
|
74
|
+
/**
|
|
75
|
+
* Clean metadata object to ensure JSON serialization compatibility
|
|
76
|
+
*/
|
|
77
|
+
private cleanMetadata;
|
|
78
|
+
/**
|
|
79
|
+
* Send logs to the API endpoint
|
|
80
|
+
*/
|
|
81
|
+
private sendLogs;
|
|
82
|
+
/**
|
|
83
|
+
* Generate a unique session ID
|
|
84
|
+
*/
|
|
85
|
+
private generateSessionId;
|
|
86
|
+
/**
|
|
87
|
+
* Log locally to stderr (for debugging the log shipper itself)
|
|
88
|
+
*/
|
|
89
|
+
private logLocally;
|
|
90
|
+
/**
|
|
91
|
+
* Get health status of the log shipper
|
|
92
|
+
*/
|
|
93
|
+
getHealthStatus(): {
|
|
94
|
+
healthy: boolean;
|
|
95
|
+
lastFlush?: string;
|
|
96
|
+
queueSize: number;
|
|
97
|
+
config: Partial<LogShipperConfig>;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Graceful shutdown - flush remaining logs
|
|
101
|
+
*/
|
|
102
|
+
shutdown(): Promise<void>;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=log-shipper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-shipper.d.ts","sourceRoot":"","sources":["../../src/services/log-shipper.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,QAAQ;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,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