Skip to main content

Function: registerToolFromSchema()

registerToolFromSchema(server, params): void

Defined in: registerToolFromSchema.ts:139

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.

Thin wrapper over @modelcontextprotocol/server's fromJsonSchema, which converts a JSON Schema into a Standard Schema that registerTool accepts directly, so the schema round-trips verbatim over tools/list. Arguments reach the handler unchecked unless validateArguments is enabled.

Parameters

ParameterTypeDescription
serverMcpServerThe McpServer instance to register the tool on.
paramsRegisterToolFromSchemaParamsTool configuration including name, description, inputSchema, validateArguments, 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}` }],
}),
});