refactor: optimize configuration and tool implementations

- Standardized error handling across tool implementations
- Improved return type consistency for tool execution results
- Simplified configuration parsing and type definitions
- Enhanced type safety for various configuration schemas
- Cleaned up and normalized tool response structures
- Updated SSE and event subscription tool implementations
This commit is contained in:
jango-blockchained
2025-02-04 00:56:45 +01:00
parent 9a02bdaf11
commit bc1dc8278a
65 changed files with 7094 additions and 7675 deletions

View File

@@ -1,61 +1,67 @@
import { EventEmitter } from 'events';
import { EventEmitter } from "events";
export class LiteMCP extends EventEmitter {
private static instance: LiteMCP;
private constructor() {
super();
// Initialize with default configuration
this.configure({});
}
private static instance: LiteMCP;
private constructor() {
super();
// Initialize with default configuration
this.configure({});
}
public static getInstance(): LiteMCP {
if (!LiteMCP.instance) {
LiteMCP.instance = new LiteMCP();
}
return LiteMCP.instance;
public static getInstance(): LiteMCP {
if (!LiteMCP.instance) {
LiteMCP.instance = new LiteMCP();
}
return LiteMCP.instance;
}
public configure(config: Record<string, any>): void {
// Store configuration
this.config = {
...this.defaultConfig,
...config
};
}
private config: Record<string, any> = {};
private defaultConfig = {
maxRetries: 3,
retryDelay: 1000,
timeout: 5000
public configure(config: Record<string, any>): void {
// Store configuration
this.config = {
...this.defaultConfig,
...config,
};
}
public async execute(command: string, params: Record<string, any> = {}): Promise<any> {
try {
// Emit command execution event
this.emit('command', { command, params });
private config: Record<string, any> = {};
private defaultConfig = {
maxRetries: 3,
retryDelay: 1000,
timeout: 5000,
};
// Execute command logic here
const result = await this.processCommand(command, params);
public async execute(
command: string,
params: Record<string, any> = {},
): Promise<any> {
try {
// Emit command execution event
this.emit("command", { command, params });
// Emit success event
this.emit('success', { command, params, result });
// Execute command logic here
const result = await this.processCommand(command, params);
return result;
} catch (error) {
// Emit error event
this.emit('error', { command, params, error });
throw error;
}
// Emit success event
this.emit("success", { command, params, result });
return result;
} catch (error) {
// Emit error event
this.emit("error", { command, params, error });
throw error;
}
}
private async processCommand(command: string, params: Record<string, any>): Promise<any> {
// Command processing logic
return { command, params, status: 'processed' };
}
private async processCommand(
command: string,
params: Record<string, any>,
): Promise<any> {
// Command processing logic
return { command, params, status: "processed" };
}
public async shutdown(): Promise<void> {
// Cleanup logic
this.removeAllListeners();
}
}
public async shutdown(): Promise<void> {
// Cleanup logic
this.removeAllListeners();
}
}