Skip to main content
Glama

MongoDB MCP Server for LLMs

by vivek1612
MIT License
109
  • Apple
tool.ts1.38 kB
import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js"; export interface ToolResponse { content: { type: "text"; text: string; }[]; isError: boolean; _meta?: Record<string, unknown>; } export type ToolParams = { [key: string]: unknown; }; export abstract class BaseTool<T extends ToolParams = ToolParams> { abstract name: string; abstract description: string; abstract inputSchema: { type: "object"; properties: Record<string, unknown>; required?: string[]; }; abstract execute(params: T): Promise<ToolResponse>; protected validateCollection(collection: unknown): string { if (typeof collection !== "string") { throw new McpError( ErrorCode.InvalidRequest, `Collection name must be a string, got ${typeof collection}` ); } return collection; } protected validateObject( value: unknown, name: string ): Record<string, unknown> { if (!value || typeof value !== "object") { throw new McpError(ErrorCode.InvalidRequest, `${name} must be an object`); } return value as Record<string, unknown>; } protected handleError(error: unknown): ToolResponse { return { content: [ { type: "text", text: error instanceof Error ? error.message : String(error), }, ], isError: true, }; } }

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/vivek1612/mongodb-mcp'

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