Repository navigation
fix: preserve inputSchema $defs/definitions when converting preloaded MCP tools #1030
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
chiragjn
merged 4 commits into
truefoundry:main
from
akushonkamen:fix/945-mcp-inputschema-defs
Oct 22, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b865157
fix(mcp): keep inputSchema $defs/definitions when converting preloade…
akushonkamen 24d0e80
test(mcp): pin model-vendor compatibility of the converted tool schemas
akushonkamen dad738f
chore(changeset): add patch changeset for trueforge-core MCP $defs fix
akushonkamen d2b4326
Reduce the amount of tests
chiragjn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@truefoundry/trueforge-core': patch | ||
| --- | ||
|
|
||
| Keep local `$defs`/`definitions` containers when converting preloaded MCP tool input schemas, so `$ref` pointers resolve instead of being dropped. |
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
83 changes: 83 additions & 0 deletions
83
packages/trueforge-core/tests/core/mcp/convertMCPServersSchema.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import type { ChatCompletionTool } from 'openai/resources/chat/completions'; | ||
| import type { AgentToolSchema, IToolSet, ListToolsResponse } from '../../../src/core/mcp/IMCPServer'; | ||
| import { convertMCPServersToTools } from '../../../src/core/mcp/convertMCPServers'; | ||
| import '../harnessMocks'; | ||
| import { makeMockIMCPServer } from '../harnessMocks'; | ||
|
|
||
| /** FastMCP hoists nested models to top-level `$defs` with `#/$defs/<Model>` refs. */ | ||
| const FASTMCP_STYLE_INPUT_SCHEMA = { | ||
| type: 'object' as const, | ||
| properties: { | ||
| name: { type: 'string' }, | ||
| address: { $ref: '#/$defs/Address' }, | ||
| }, | ||
| required: ['name', 'address'], | ||
| $defs: { | ||
| Address: { | ||
| type: 'object', | ||
| properties: { street: { type: 'string' }, city: { type: 'string' } }, | ||
| required: ['street', 'city'], | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| /** Draft-04 spelling still emitted by older generators. */ | ||
| const DRAFT04_DEFINITIONS_INPUT_SCHEMA = { | ||
| type: 'object' as const, | ||
| properties: { | ||
| address: { $ref: '#/definitions/Address' }, | ||
| }, | ||
| required: ['address'], | ||
| definitions: { | ||
| Address: { | ||
| type: 'object', | ||
| properties: { city: { type: 'string' } }, | ||
| required: ['city'], | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| function makeServer(name: string, tools: AgentToolSchema[]): IToolSet { | ||
| const base = makeMockIMCPServer({ name, preload: true, tools }); | ||
| return { | ||
| ...base, | ||
| listTools: jest.fn((): Promise<ListToolsResponse> => | ||
| Promise.resolve({ | ||
| result: { tools }, | ||
| wasInitialized: undefined, | ||
| }), | ||
| ), | ||
| }; | ||
| } | ||
|
|
||
| function functionParameters(tool: ChatCompletionTool | undefined): Record<string, unknown> | undefined { | ||
| if (tool === undefined || tool.type !== 'function') { | ||
| throw new Error('Expected a function tool'); | ||
| } | ||
| return tool.function.parameters; | ||
| } | ||
|
|
||
| async function convertParameters(inputSchema: AgentToolSchema['inputSchema']) { | ||
| const tools: AgentToolSchema[] = [{ name: 'probe', description: 'probe', inputSchema, preload: true }]; | ||
| const { convertedTools } = await convertMCPServersToTools({ | ||
| tfyManagedServers: [], | ||
| userServers: [makeServer('server', tools)], | ||
| }); | ||
| expect(convertedTools.tools).toHaveLength(1); | ||
| return functionParameters(convertedTools.tools[0]); | ||
| } | ||
|
|
||
| describe('convertMCPServersToTools JSON Schema containers', () => { | ||
| it.each([ | ||
| ['$defs', FASTMCP_STYLE_INPUT_SCHEMA, FASTMCP_STYLE_INPUT_SCHEMA.$defs], | ||
| ['definitions', DRAFT04_DEFINITIONS_INPUT_SCHEMA, DRAFT04_DEFINITIONS_INPUT_SCHEMA.definitions], | ||
| ] as const)('preserves top-level %s so local $refs stay resolvable', async (container, inputSchema, expected) => { | ||
| const parameters = await convertParameters(inputSchema); | ||
| expect(parameters?.[container]).toEqual(expected); | ||
| }); | ||
|
|
||
| it('does not introduce $defs or definitions for schemas without them', async () => { | ||
| const parameters = await convertParameters({ type: 'object', properties: {} }); | ||
| expect(parameters).toEqual({ type: 'object', properties: {}, required: [] }); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.