MCP API Reference
This document provides a complete API reference for AG-Kit’s Model Context Protocol (MCP) integration components.Core Classes
AGKitMCPServer
Exposes AG-Kit tools as a standard MCP server.Constructor
config: AGKitMCPServerConfig- Server configuration object
Methods
registerTool()
Register a single AG-Kit tool with the server.
tool: BaseTool- The AG-Kit tool to registertoolConfig?: MCPToolConfig- Optional tool configuration
MCPToolMetadata - Metadata for the registered tool
MCPToolConfig Interface:
registerTools()
Register multiple AG-Kit tools with shared configuration.tools: BaseTool[]- Array of AG-Kit tools to registertoolConfig?: MCPToolConfig- Optional shared configuration
MCPToolMetadata[] - Array of metadata for registered tools
unregisterTool()
Remove a tool from the server.name: string- Name of the tool to remove
boolean - True if tool was removed, false if not found
run()
Start the MCP server with specified transport.transportConfig: MCPTransportConfig- Transport configuration
stop()
Stop the MCP server and cleanup resources.callTool()
Execute a registered tool directly.name: string- Name of the tool to executeargs: Record<string, any>- Tool arguments
Promise<CallToolResult> - MCP-formatted tool result
listTools()
Get list of all registered tools.isServerRunning()
Check if the server is currently running.boolean - True if server is running
getStats()
Get server statistics and information.addEventListener()
Add event listener for server events.listener: MCPEventListener- Event listener function
removeEventListener()
Remove event listener.listener: MCPEventListener- Event listener to remove
boolean - True if listener was removed
MCPClientManager
Manages connections to external MCP servers.Constructor
Methods
addServer()
Add and connect to an MCP server.serverId: string- Unique identifier for the serverconfig: MCPClientConfig- Client configurationconnectionOptions?: MCPConnectionOptions- Optional connection settings
disconnectServer()
Disconnect from a specific server.disconnectAll()
Disconnect from all servers.createClientTools()
Create AG-Kit tool wrappers for all available MCP tools.serverId?: string- Optional server ID to filter tools
MCPClientTool[] - Array of wrapped tools
createClientTool()
Create a specific AG-Kit tool wrapper for an MCP tool.serverId: string- Server ID containing the tooltoolName: string- Name of the MCP toolagKitToolName?: string- Custom name for the AG-Kit tool
MCPClientTool - Wrapped tool instance
callTool()
Call an MCP tool directly.isServerConnected()
Check if a server is connected.getStats()
Get client manager statistics.addEventListener()
Add event listener for client events.removeEventListener()
Remove event listener.MCPClientTool
Wraps an external MCP tool to work within AG-Kit’s tool system.Constructor
mcpClient: Client- MCP client instancemcpToolMetadata: MCPToolMetadata- Tool metadata from MCP serverconfig?: MCPToolConfig- Optional tool configurationadapterConfig?: MCPAdapterConfig- Optional adapter configuration
Methods
invoke()
Execute the MCP tool (inherited from BaseTool).getMCPMetadata()
Get the original MCP tool metadata.isConnected()
Check if the underlying MCP client is connected.updateConfig()
Update tool configuration.updateAdapterConfig()
Update adapter configuration.MCPToolkit
High-level toolkit for managing MCP tools from external servers.Constructor
name?: string- Optional toolkit name (default: “mcp-toolkit”)
Methods
addServer()
Add an MCP server and load its tools.removeServer()
Remove a server and its tools.getConnectedServers()
Get list of connected server IDs.getServerTools()
Get tools from a specific server.refresh()
Refresh all server connections and reload tools.cleanup()
Cleanup all resources and disconnect from servers.getClientManager()
Get the underlying client manager.getStats()
Get toolkit statistics.Utility Functions
zodSchemaToMCPSchema()
Convert a Zod schema to MCP JSON schema format.zodSchema: z.ZodSchema<any>- Zod schema to convert
convertAGKitToolToMCPMetadata()
Convert AG-Kit BaseTool to MCP tool metadata.createAGKitMCPServer()
Utility function to create and configure an MCP server.createMCPToolkit()
Create a new MCP toolkit with pre-configured servers.servers- Server configurations in object mapping (recommended) or array formatname- Optional toolkit name
Memory Transport Registry
MemoryTransportRegistry
Singleton registry for managing in-memory MCP transports.Methods
getInstance()
Get the singleton instance.registerServer()
Register an MCP server with memory transport.unregisterServer()
Unregister a server.getServer()
Get a registered server.createTransportPair()
Create a linked pair of memory transports.getClientTransport()
Get client transport for connections.callTool()
Direct tool call via memory transport.listTools()
List tools via memory transport.Type Definitions
MCPEvent
Union type for all MCP events.MCPEventListener
Event listener function type.MCPClientStatus
Status information for MCP client connections.Transport Configuration Types
Note: Thetype field is optional in all transport configurations. If not specified, the type will be auto-detected based on the configuration properties with the following priority: memory > stdio > streamableHttp > sse.
MCPStdioTransportConfig
MCPSSETransportConfig
MCPStreamableHTTPTransportConfig
MCPInMemoryTransportConfig
MCPCustomTransportConfig
Auto-Detection Priority
Whentype is not specified, the transport type is detected in the following order:
- memory - If
memoryIdis present - stdio - If
commandis present - streamableHttp - If
urlis present (default for URL-based configs) - sse - Requires explicit
type: 'sse'for URL-based configs - custom - If
transportis present