@reaatech/structured-function-calling-ai-mcp-server
MCP server exposing registered tools for discovery and invocation by any MCP client.
Installation
pnpm add @reaatech/structured-function-calling-ai-mcp-serverAPI
McpToolServer
class McpToolServer {
constructor(registry: ToolRegistry, opts: McpServerOptions);
async connect(transport: Transport): Promise<void>;
async close(): Promise<void>;
async listTools(): Promise<McpTool[]>;
async callTool(
name: string,
args: Record<string, unknown>,
): Promise<{ content: Array<{ type: string; text: string }> }>;
}
type McpServerOptions = {
name: string;
version: string;
logger?: pino.Logger;
};Wraps @modelcontextprotocol/sdk’s McpServer. connect registers all tools from the registry and establishes the transport connection. close tears down the connection. listTools returns MCP tool descriptors. callTool executes a tool via an internal ToolExecutor and returns MCP content blocks.
ToolNotFoundError from the registry is caught and returned as an error text block instead of being thrown.
createStdioTransport
function createStdioTransport(): StdioServerTransport;Returns a real StdioServerTransport from @modelcontextprotocol/sdk. Pass the result to McpToolServer.connect.
convertToMcpTool
function convertToMcpTool(def: ToolDefinition): McpTool;
type McpTool = {
name: string;
description?: string;
inputSchema: Record<string, unknown>;
};Converts a ToolDefinition to an MCP Tool descriptor. Converts the Zod schema to JSON Schema via convertToJsonSchema for the inputSchema field.
Usage example
import { z } from 'zod/v3';
import { ToolRegistry } from '@reaatech/structured-function-calling-ai-core';
import { McpToolServer, createStdioTransport } from '@reaatech/structured-function-calling-ai-mcp-server';
import pino from 'pino';
const schema = z.object({ city: z.string() });
const registry = new ToolRegistry();
registry.register({
name: 'get_weather',
description: 'Get weather for a city',
schema,
execute: async (input) => ({ temp: 22, conditions: 'sunny' }),
});
const server = new McpToolServer(registry, {
name: 'my-server',
version: '1.0.0',
logger: pino({ level: 'info' }),
});
const transport = createStdioTransport();
await server.connect(transport);
// Server is now listening on stdio, ready to receive MCP requests from any MCP clientDirect invocation without MCP:
const tools = await server.listTools();
// → [{ name: 'get_weather', description: 'Get weather', inputSchema: { ... } }]
const result = await server.callTool('get_weather', { city: 'NYC' });
// → { content: [{ type: 'text', text: '{"temp":22,"conditions":"sunny"}' }] }Dependencies
@reaatech/structured-function-calling-ai-core(workspace:*)@reaatech/structured-function-calling-ai-engine(workspace:*)@modelcontextprotocol/sdk1.29.0zod4.4.3pino10.3.1
