feat: add jsonSchemaAdapter for plain JSON Schema support — closes #54#244
Open
lucamorettibuilds wants to merge 5 commits intopunkpeye:mainfrom
Open
feat: add jsonSchemaAdapter for plain JSON Schema support — closes #54#244lucamorettibuilds wants to merge 5 commits intopunkpeye:mainfrom
lucamorettibuilds wants to merge 5 commits intopunkpeye:mainfrom
Conversation
Closes punkpeye#54 Adds a function that wraps plain JSON Schema objects with a StandardSchemaV1-compatible interface, enabling users to define tool parameters using raw JSON Schema without a third-party validation library like Zod. **How it works:** - Wraps a JSON Schema object to satisfy StandardSchemaV1 - Uses AJV for runtime validation (lazy-loaded, optional peer dep) - Exposes a fast-path so FastMCP can skip the toJsonSchema() conversion and use the raw schema directly - Supports ajv-formats optionally for format validation **Changes:** - `src/jsonSchemaAdapter.ts` — the adapter function - `src/jsonSchemaAdapter.test.ts` — comprehensive tests - `src/FastMCP.ts` — re-export + fast-path detection in inputSchema resolution **Usage:** ```ts import { FastMCP, jsonSchemaAdapter } from 'fastmcp'; server.addTool({ name: 'greet', description: 'Greet a user', parameters: jsonSchemaAdapter({ type: 'object', properties: { name: { type: 'string' } }, required: ['name'], }), execute: async ({ name }) => `Hello, ${name}!`, }); ```
Author
|
Hey @punkpeye — CI is blocked on first-time contributor approval ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #54
Adds a
jsonSchemaAdapter()utility that wraps plain JSON Schema objects with a Standard Schema v1 interface. This lets users define tool parameters using raw JSON Schema — no Zod, Yup, or other validation library required.How it works
jsonSchemaAdapter(schema)returns aStandardSchemaV1-compatible object__jsonSchemaso FastMCP can skip thetoJsonSchema()conversion and use the raw schema directly — zero overheadajv-formatsis optionally detected for format validation (e.g.email,uri)Usage
Changes
src/jsonSchemaAdapter.tsJsonSchemaObjecttypesrc/jsonSchemaAdapter.test.ts__jsonSchemafast-path, vendor metadata, nested objectssrc/FastMCP.tsinputSchemaresolutionDesign decisions
ajvthemselves. The adapter throws a clear error message if AJV is missing.__jsonSchemafast-path — avoids thetoJsonSchema()roundtrip since we already have valid JSON Schema. FastMCP checks for this property before falling back to the standard conversion.Related