Skip to main content

Function: registerToolFromSchema()

registerToolFromSchema(server, params): void

Defined in: index.ts:456

Registers a tool on an MCP server using a plain JSON Schema object for inputSchema instead of a Zod shape.

This is useful when tool definitions are shared between the MCP server and an AI SDK agent (e.g. Vercel AI SDK's tool() helper), because both consume a plain JSON Schema at runtime. Using this helper eliminates the lossy JSON-Schema→Zod conversion that would otherwise be required.

Internally the helper:

  1. Registers the tool via the standard McpServer.registerTool API using a Zod z.record(z.unknown()) pass-through schema so that the existing MCP tools/call handler correctly routes requests and delivers raw args to your handler.
  2. Stores the original JSON Schema and patches the tools/list response handler so clients receive the verbatim JSON Schema over the wire.

Parameters

ParameterTypeDescription
serverMcpServerThe McpServer instance to register the tool on.
paramsRegisterToolFromSchemaParamsTool configuration including name, description, inputSchema, and handler.

Returns

void

Example

import { registerToolFromSchema, McpServer } from '@ttoss/http-server-mcp';

const server = new McpServer({ name: 'my-server', version: '1.0.0' });

registerToolFromSchema(server, {
name: 'get-project',
description: 'Get a project by ID',
inputSchema: {
type: 'object',
properties: { id: { type: 'string', description: 'Project public ID' } },
required: ['id'],
},
handler: async ({ id }) => ({
content: [{ type: 'text', text: `Project: ${id}` }],
}),
});