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:
- Registers the tool via the standard
McpServer.registerToolAPI using a Zodz.record(z.unknown())pass-through schema so that the existing MCPtools/callhandler correctly routes requests and delivers raw args to your handler. - Stores the original JSON Schema and patches the
tools/listresponse handler so clients receive the verbatim JSON Schema over the wire.
Parameters
| Parameter | Type | Description |
|---|---|---|
server | McpServer | The McpServer instance to register the tool on. |
params | RegisterToolFromSchemaParams | Tool 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}` }],
}),
});