Skip to main content
Glama

MongoDB MCP Server

Official
by mongodb-js
elicitation.ts1.95 kB
import type { ElicitRequest } from "@modelcontextprotocol/sdk/types.js"; import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; export class Elicitation { private readonly server: McpServer["server"]; constructor({ server }: { server: McpServer["server"] }) { this.server = server; } /** * Checks if the client supports elicitation capabilities. * @returns True if the client supports elicitation, false otherwise. */ public supportsElicitation(): boolean { const clientCapabilities = this.server.getClientCapabilities(); return clientCapabilities?.elicitation !== undefined; } /** * Requests a boolean confirmation from the user. * @param message - The message to display to the user. * @returns True if the user confirms the action or the client does not support elicitation, false otherwise. */ public async requestConfirmation(message: string): Promise<boolean> { if (!this.supportsElicitation()) { return true; } const result = await this.server.elicitInput({ message, requestedSchema: Elicitation.CONFIRMATION_SCHEMA, }); return result.action === "accept" && result.content?.confirmation === "Yes"; } /** * The schema for the confirmation question. * TODO: In the future would be good to use Zod 4's toJSONSchema() to generate the schema. */ public static CONFIRMATION_SCHEMA: ElicitRequest["params"]["requestedSchema"] = { type: "object", properties: { confirmation: { type: "string", title: "Would you like to confirm?", description: "Would you like to confirm?", enum: ["Yes", "No"], enumNames: ["Yes, I confirm", "No, I do not confirm"], }, }, required: ["confirmation"], }; }

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

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