mcp-quickbase
Version:
Work with Quickbase via Model Context Protocol
63 lines • 2.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseTool = void 0;
const logger_1 = require("../utils/logger");
const validation_1 = require("../utils/validation");
const logger = (0, logger_1.createLogger)("BaseTool");
/**
* Base class for MCP tools
*/
class BaseTool {
/**
* Constructor
* @param client QuickBase client instance
*/
constructor(client) {
this.client = client;
}
/**
* Validate parameters against schema using Zod
* @param params Parameters to validate
* @returns Validated parameters
*/
validateParams(params) {
return (0, validation_1.validateParams)(params, this.paramSchema, this.name);
}
/**
* Execute the tool
* @param params Tool parameters
* @returns Tool result
*/
async execute(params) {
try {
logger.debug(`Executing tool: ${this.name}`, { params });
// Validate parameters
const validatedParams = this.validateParams(params);
// Execute the tool implementation
const result = await this.run(validatedParams);
logger.debug(`Tool ${this.name} executed successfully`, { result });
return {
success: true,
data: result,
};
}
catch (error) {
const errorMessage = error instanceof Error ? error.message : "Unknown error";
const errorType = error instanceof Error ? error.name : "UnknownError";
logger.error(`Error executing tool ${this.name}`, {
error: errorMessage,
type: errorType,
stack: error instanceof Error ? error.stack : undefined,
});
return {
success: false,
error: {
message: errorMessage,
type: errorType,
},
};
}
}
}
exports.BaseTool = BaseTool;
//# sourceMappingURL=base.js.map