Skip to content
reaatechREAATECH

@reaatech/structured-function-calling-ai-mcp-server

pending npm

Exposes a `ToolRegistry` as a Model Context Protocol (MCP) server, allowing MCP clients to discover and execute registered functions. It provides an `McpToolServer` class that wraps the `@modelcontextprotocol/sdk` to handle tool registration, schema conversion, and transport management.

@reaatech/structured-function-calling-ai-mcp-server

MCP server exposing registered tools for discovery and invocation by any MCP client.

Installation

terminal
pnpm add @reaatech/structured-function-calling-ai-mcp-server

API

McpToolServer

typescript
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

typescript
function createStdioTransport(): StdioServerTransport;

Returns a real StdioServerTransport from @modelcontextprotocol/sdk. Pass the result to McpToolServer.connect.

convertToMcpTool

typescript
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

typescript
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 client

Direct invocation without MCP:

typescript
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/sdk 1.29.0
  • zod 4.4.3
  • pino 10.3.1