@kpritam/gremlin-mcp
Version:
A Gremlin MCP server that allows for fetching status, schema, and querying using Gremlin for any Gremlin-compatible graph database (TypeScript implementation).
59 lines • 2.23 kB
TypeScript
/**
* Utility functions for MCP tool registration and handling.
* Eliminates code duplication and provides consistent error handling.
*/
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import type { GremlinClient } from '../gremlin/client.js';
import { z } from 'zod';
/**
* Configuration for creating a tool handler.
*/
export interface ToolConfig {
name: string;
title: string;
description: string;
inputSchema?: Record<string, z.ZodType> | Record<string, never>;
}
/**
* Handler function type for tools.
*/
export type ToolHandler<T = Record<string, unknown>> = (args: T, client: GremlinClient) => Promise<unknown>;
/**
* Standard response format for tool results.
*/
export interface ToolResponse {
[key: string]: unknown;
content: Array<{
type: 'text';
text: string;
}>;
}
/**
* Creates a standardized text response for tools.
*/
export declare function createTextResponse(data: unknown): ToolResponse;
/**
* Wraps a tool handler with consistent error handling and logging.
*/
export declare function withErrorHandling<T>(toolName: string, handler: ToolHandler<T>): (args: T, client: GremlinClient) => Promise<ToolResponse>;
/**
* Creates and registers a tool with standardized configuration.
*/
export declare function createTool<T extends Record<string, unknown>>(server: McpServer, getGraphClient: () => Promise<GremlinClient>, config: ToolConfig, handler: ToolHandler<T>): void;
/**
* Validates input against a schema and returns parsed result.
*/
export declare function validateInput<T>(schema: z.ZodSchema<T>, input: unknown, toolName: string): T;
/**
* Common error types for tools.
*/
export declare class ToolError extends Error {
readonly toolName: string;
readonly details?: unknown | undefined;
constructor(toolName: string, message: string, details?: unknown | undefined);
}
/**
* Helper for creating simple tools that don't require input validation.
*/
export declare function createSimpleTool(server: McpServer, getGraphClient: () => Promise<GremlinClient>, name: string, title: string, description: string, handler: (client: GremlinClient) => Promise<unknown>): void;
//# sourceMappingURL=tool-helpers.d.ts.map