@@ -86,6 +86,28 @@ export type ServerOptions = ProtocolOptions & {
8686 jsonSchemaValidator ?: jsonSchemaValidator ;
8787} ;
8888
89+ function isJsonObject ( value : unknown ) : value is Record < string , unknown > {
90+ return typeof value === 'object' && value !== null && ! Array . isArray ( value ) ;
91+ }
92+
93+ function findStrippedJsonSchemaPaths ( original : unknown , parsed : unknown , path = '' ) : string [ ] {
94+ if ( Array . isArray ( original ) && Array . isArray ( parsed ) ) {
95+ return original . flatMap ( ( item , index ) => findStrippedJsonSchemaPaths ( item , parsed [ index ] , `${ path } [${ index } ]` ) ) ;
96+ }
97+
98+ if ( ! isJsonObject ( original ) || ! isJsonObject ( parsed ) ) {
99+ return [ ] ;
100+ }
101+
102+ return Object . entries ( original ) . flatMap ( ( [ key , value ] ) => {
103+ const childPath = path ? `${ path } .${ key } ` : key ;
104+ if ( ! Object . prototype . hasOwnProperty . call ( parsed , key ) ) {
105+ return [ childPath ] ;
106+ }
107+ return findStrippedJsonSchemaPaths ( value , parsed [ key ] , childPath ) ;
108+ } ) ;
109+ }
110+
89111/**
90112 * An MCP server on top of a pluggable transport.
91113 *
@@ -625,6 +647,13 @@ export class Server extends Protocol<ServerContext> {
625647 `Elicitation requestedSchema only supports flat primitive properties (string, number, integer, boolean, and string enums): ${ parsedParams . error . message } `
626648 ) ;
627649 }
650+ const strippedSchemaPaths = findStrippedJsonSchemaPaths ( normalizedParams . requestedSchema , parsedParams . data . requestedSchema ) ;
651+ if ( strippedSchemaPaths . length > 0 ) {
652+ throw new ProtocolError (
653+ ProtocolErrorCode . InvalidParams ,
654+ `Elicitation requestedSchema contains unsupported JSON Schema keyword(s) after Standard Schema conversion: ${ strippedSchemaPaths . join ( ', ' ) } `
655+ ) ;
656+ }
628657 return { params : parsedParams . data , standardSchema } ;
629658 }
630659
0 commit comments