Skip to main content
Glama
baseTool.js1.22 kB
import { ToolSchema } from '@modelcontextprotocol/sdk/types.js'; // Type definition for input schema const ToolInputSchema = ToolSchema.shape.inputSchema; /** * Abstract class to implement MCP tools */ export class BaseTool { // The schema for validating tool arguments schema; // The tool definition for MCP tool; constructor(schema, tool) { this.schema = schema; this.tool = tool; } // Final handler method that performs validation before calling abstract process method async handleRequest(args) { try { // Validate args using schema const validatedArgs = this.schema.parse(args); // Call abstract process method with the validated args return await this.process(validatedArgs); } catch (error) { // Handle validation errors const errorMessage = error instanceof Error ? error.message : 'Unknown validation error'; return { content: [{ type: 'text', text: `Error: ${errorMessage}` }], isError: true, }; } } } // Export the tool input type for reuse in tool implementations export { ToolInputSchema };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ajaystream/hubspot-mcp-custom'

If you have feedback or need assistance with the MCP directory API, please join our Discord server