mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 13:23:04 +00:00
fix(mcp): keep restore_book_page free of tuples so ChatGPT accepts the tool list
With the Journey addon on, ChatGPT refused every TREK tool: restore_book_page took a map's path and roads as [lat, lng] tuples, which the SDK writes as the draft-07 array form of items, and JSON Schema 2020-12 refuses that form. The restore now takes a map point as two numbers and parses each page as a spread before it is put back, so lat and lng stay checked and a point out of range is an invalid_op instead of a thrown parse. MCP-SCHEMA-005 holds every tool's input schema free of tuple keywords. Closes #2879
This commit is contained in:
@@ -8,7 +8,9 @@
|
||||
* several MCP clients do not resolve), every id field is the positive integer
|
||||
* of @trek/shared's idSchema, the shared primitive the tools derive their ids
|
||||
* from, and the book restore's schema, which carries whole pages, stays under a ceiling, as do
|
||||
* the page edit and the design revision, which take every page operation.
|
||||
* the page edit and the design revision, which take every page operation. And an input schema
|
||||
* reads the same under draft-07, which the SDK writes, and 2020-12, the MCP default: no tuple,
|
||||
* since ChatGPT checks against 2020-12 and refuses the whole tool list over one tool's tuple.
|
||||
*/
|
||||
import type { ToolOptions } from '../../../src/nest-mcp';
|
||||
import { getEntry, isMcpController, type ClassRef } from '../../../src/nest-mcp/metadata';
|
||||
@@ -39,6 +41,22 @@ function methodNames(ctor: ClassRef): string[] {
|
||||
return [...names];
|
||||
}
|
||||
|
||||
const VALUE_KEYWORDS = new Set(['default', 'const', 'enum', 'examples']);
|
||||
|
||||
/** Where a schema spells a tuple: `items` as an array, `additionalItems` or `prefixItems`. */
|
||||
function tuplesIn(node: unknown, at: string): string[] {
|
||||
if (Array.isArray(node)) return node.flatMap((child, i) => tuplesIn(child, `${at}/${i}`));
|
||||
if (!node || typeof node !== 'object') return [];
|
||||
const schema = node as Record<string, unknown>;
|
||||
const here = Array.isArray(schema.items) || 'additionalItems' in schema || 'prefixItems' in schema ? [at] : [];
|
||||
const below = Object.entries(schema).flatMap(([key, value]) => {
|
||||
if (VALUE_KEYWORDS.has(key) || !value || typeof value !== 'object') return [];
|
||||
if (key !== 'properties') return tuplesIn(value, `${at}/${key}`);
|
||||
return Object.entries(value).flatMap(([name, prop]) => tuplesIn(prop, `${at}/properties/${name}`));
|
||||
});
|
||||
return [...here, ...below];
|
||||
}
|
||||
|
||||
async function toolSchemas(): Promise<Map<string, Record<string, unknown>>> {
|
||||
const out = new Map<string, Record<string, unknown>>();
|
||||
const files = mcpFiles(NEST_ROOT).sort();
|
||||
@@ -106,4 +124,9 @@ describe('MCP tool input schemas', () => {
|
||||
}
|
||||
expect(sizeOf('restore_book_layout')).toBeLessThan(2_000);
|
||||
});
|
||||
|
||||
it('MCP-SCHEMA-005: every input schema is valid JSON Schema 2020-12 too, so no tool holds a tuple', () => {
|
||||
const tuples = [...schemas].flatMap(([key, json]) => tuplesIn(json, '').map((at) => `${key} ${at}`));
|
||||
expect(tuples).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user