@juspay/neurolink
Version:
Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio
163 lines (162 loc) • 4.41 kB
TypeScript
/**
* MCP Server Base Class
*
* Abstract base class for creating custom MCP servers with consistent patterns
* for tool registration, execution, and lifecycle management.
*
* Implements MCPServerBase features including:
* - Tool annotation support (readOnlyHint, destructiveHint, idempotentHint)
* - Lifecycle hooks (onInit, onStart, onStop)
* - Event emission for tool operations
* - Conversion to MCPServerInfo format
*
* @module mcp/mcpServerBase
* @since 8.39.0
*/
import { EventEmitter } from "events";
import type { MCPServerBaseConfig, MCPServerCategory, MCPServerInfo, MCPServerTool, MCPToolAnnotations, NeuroLinkExecutionContext, ToolResult } from "../types/index.js";
/**
* MCPServerBase configuration
*/
/**
* Abstract base class for MCP servers
*
* Provides a foundation for creating custom MCP servers with consistent
* patterns for tool registration, execution, and lifecycle management.
*
* @example
* ```typescript
* class MyCustomServer extends MCPServerBase {
* constructor() {
* super({
* id: "my-custom-server",
* name: "My Custom Server",
* description: "Provides custom functionality",
* category: "custom",
* });
*
* // Register tools in constructor or init
* this.registerTool({
* name: "myTool",
* description: "Does something useful",
* annotations: {
* readOnlyHint: true,
* idempotentHint: true,
* },
* execute: async (params, context) => {
* return { success: true, data: "result" };
* },
* });
* }
* }
* ```
*/
export declare abstract class MCPServerBase extends EventEmitter {
protected readonly config: Required<MCPServerBaseConfig>;
protected readonly tools: Map<string, MCPServerTool>;
protected isInitialized: boolean;
protected isRunning: boolean;
constructor(config: MCPServerBaseConfig);
/**
* Initialize the server
* Override in subclasses for async initialization
*/
init(): Promise<void>;
/**
* Hook for subclass initialization
* Override to perform async setup
*/
protected onInit(): Promise<void>;
/**
* Start the server
*/
start(): Promise<void>;
/**
* Hook for subclass start logic
*/
protected onStart(): Promise<void>;
/**
* Stop the server
*/
stop(reason?: string): Promise<void>;
/**
* Hook for subclass stop logic
*/
protected onStop(): Promise<void>;
/**
* Register a tool with the server
*/
registerTool(tool: MCPServerTool): this;
/**
* Register multiple tools at once
*/
registerTools(tools: MCPServerTool[]): this;
/**
* Validate tool configuration
*/
protected validateTool(tool: MCPServerTool): void;
/**
* Execute a tool by name
*/
executeTool(toolName: string, params: unknown, context?: NeuroLinkExecutionContext): Promise<ToolResult>;
/**
* Type guard to check if result is a ToolResult
*/
private isToolResult;
/**
* Get all registered tools
*/
getTools(): MCPServerTool[];
/**
* Get a specific tool by name
*/
getTool(name: string): MCPServerTool | undefined;
/**
* Check if a tool exists
*/
hasTool(name: string): boolean;
/**
* Remove a tool
*/
removeTool(name: string): boolean;
/**
* Get server info in MCPServerInfo format
*/
toServerInfo(): MCPServerInfo;
/**
* Get tools filtered by annotations
*/
getToolsByAnnotation(annotation: keyof MCPToolAnnotations, value: boolean | string | number | string[]): MCPServerTool[];
/**
* Get read-only tools
*/
getReadOnlyTools(): MCPServerTool[];
/**
* Get destructive tools
*/
getDestructiveTools(): MCPServerTool[];
/**
* Get idempotent tools
*/
getIdempotentTools(): MCPServerTool[];
/**
* Get tools that require confirmation
*/
getToolsRequiringConfirmation(): MCPServerTool[];
/**
* Server identification
*/
get id(): string;
get name(): string;
get description(): string;
get version(): string;
get category(): MCPServerCategory;
/**
* Check if server is initialized
*/
get initialized(): boolean;
/**
* Check if server is running
*/
get running(): boolean;
}