Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
5198354
fix(core): strip $schema from MCP tool parameters for API compatibility
achaljhawar Mar 11, 2026
07c7e19
Merge branch 'main' into fix/mcp-schema-compatibility-17235
achaljhawar Mar 11, 2026
ef01afc
Merge branch 'main' into fix/mcp-schema-compatibility-17235
achaljhawar Mar 11, 2026
e12dc9d
Merge branch 'main' into fix/mcp-schema-compatibility-17235
achaljhawar Mar 16, 2026
dfd29f7
fix(core): enhance schema handling and validation in DiscoveredMCPTool
achaljhawar Mar 16, 2026
d2b1e56
Merge branch 'main' into fix/mcp-schema-compatibility-17235
achaljhawar Mar 16, 2026
d8616b2
Merge branch 'main' into fix/mcp-schema-compatibility-17235
achaljhawar Mar 16, 2026
8227a3e
Merge branch 'main' into fix/mcp-schema-compatibility-17235
achaljhawar Mar 16, 2026
799132f
Merge branch 'main' into fix/mcp-schema-compatibility-17235
achaljhawar Mar 17, 2026
1eda4d7
Merge branch 'main' into fix/mcp-schema-compatibility-17235
achaljhawar Mar 18, 2026
dc9032a
Merge branch 'main' into fix/mcp-schema-compatibility-17235
achaljhawar Mar 18, 2026
c6c95c6
Merge branch 'main' into fix/mcp-schema-compatibility-17235
achaljhawar Mar 18, 2026
019516c
Merge branch 'main' into fix/mcp-schema-compatibility-17235
achaljhawar Mar 20, 2026
89b4031
Merge branch 'main' into fix/mcp-schema-compatibility-17235
achaljhawar Mar 20, 2026
6176ef2
Merge branch 'main' into fix/mcp-schema-compatibility-17235
achaljhawar Mar 21, 2026
acc3506
Merge branch 'upstream/main' into fix/mcp-schema-compatibility-17235
achaljhawar Apr 9, 2026
2bb45eb
Merge branch 'main' into fix/mcp-schema-compatibility-17235
achaljhawar Apr 10, 2026
f62be73
Merge branch 'main' into fix/mcp-schema-compatibility-17235
achaljhawar Apr 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions packages/core/src/tools/mcp-tool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,93 @@ describe('DiscoveredMCPTool', () => {
});
});

describe('getSchema', () => {
it('should strip $schema from parametersJsonSchema for API compatibility', () => {
const schemaWithDraft2020 = {
$schema: 'https://json-schema.org/draft/2020-12/schema',
type: 'object' as const,
properties: { param: { type: 'string' } },
required: ['param'],
};
const bus = createMockMessageBus();
const toolWith$schema = new DiscoveredMCPTool(
mockCallableToolInstance,
serverName,
serverToolName,
baseDescription,
schemaWithDraft2020,
bus,
);
const schema = toolWith$schema.getSchema();
expect(
(schema.parametersJsonSchema as Record<string, unknown>)?.['$schema'],
).toBeUndefined();
expect(
(schema.parametersJsonSchema as Record<string, unknown>)?.['type'],
).toBe('object');
expect(
(
(schema.parametersJsonSchema as Record<string, unknown>)?.[
'properties'
] as Record<string, unknown>
)?.['param'],
).toEqual({ type: 'string' });
expect(
(
(schema.parametersJsonSchema as Record<string, unknown>)?.[
'properties'
] as Record<string, unknown>
)?.['wait_for_previous'],
).toBeDefined();
expect(
(toolWith$schema.parameterSchema as Record<string, unknown>)?.[
'$schema'
],
).toBe('https://json-schema.org/draft/2020-12/schema');
});

it('should not modify schema without $schema property', () => {
const schema = tool.getSchema();
expect(schema.parametersJsonSchema).toEqual({
...inputSchema,
properties: {
...(inputSchema['properties'] as Record<string, unknown>),
wait_for_previous: expect.any(Object),
},
});
});
});

describe('validateToolParams', () => {
it('should accept wait_for_previous even with additionalProperties: false', () => {
const strictSchema = {
type: 'object' as const,
properties: { param: { type: 'string' } },
required: ['param'],
additionalProperties: false,
};
const bus = createMockMessageBus();
const strictTool = new DiscoveredMCPTool(
mockCallableToolInstance,
serverName,
serverToolName,
baseDescription,
strictSchema,
bus,
);
const result = strictTool.validateToolParams({
param: 'value',
wait_for_previous: true,
});
expect(result).toBeNull();
});

it('should reject invalid params against MCP schema', () => {
const result = tool.validateToolParams({ unknownParam: 'value' });
expect(typeof result === 'string' || result === null).toBe(true);
});
});

describe('getDisplayTitle and getExplanation', () => {
const commandTool = new DiscoveredMCPTool(
mockCallableToolInstance,
Expand Down
38 changes: 37 additions & 1 deletion packages/core/src/tools/mcp-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { safeJsonStringify } from '../utils/safeJsonStringify.js';
import { debugLogger } from '../utils/debugLogger.js';
import { SchemaValidator } from '../utils/schemaValidator.js';
import {
BaseDeclarativeTool,
BaseToolInvocation,
Expand All @@ -17,7 +18,12 @@ import {
type ToolResult,
type PolicyUpdateOptions,
} from './tools.js';
import type { CallableTool, FunctionCall, Part } from '@google/genai';
import type {
CallableTool,
FunctionCall,
FunctionDeclaration,
Part,
} from '@google/genai';
import { ToolErrorType } from './tool-error.js';
import type { MessageBus } from '../confirmation-bus/message-bus.js';
import type { McpContext } from './mcp-client.js';
Expand Down Expand Up @@ -413,6 +419,23 @@ export class DiscoveredMCPTool extends BaseDeclarativeTool<
return this._toolAnnotations;
}

override getSchema(_modelId?: string): FunctionDeclaration {
const schema = super.getSchema(_modelId);
if (
typeof schema.parametersJsonSchema === 'object' &&
schema.parametersJsonSchema !== null &&
'$schema' in schema.parametersJsonSchema
) {
const { $schema: _, ...schemaWithout$schema } =
schema.parametersJsonSchema as Record<string, unknown>;
return {
...schema,
parametersJsonSchema: schemaWithout$schema,
};
}
return schema;
}

getFullyQualifiedPrefix(): string {
return generateValidName(
`${this.serverName}${MCP_QUALIFIED_NAME_SEPARATOR}`,
Expand All @@ -424,6 +447,19 @@ export class DiscoveredMCPTool extends BaseDeclarativeTool<
`${this.serverName}${MCP_QUALIFIED_NAME_SEPARATOR}${this.serverToolName}`,
);
}

override validateToolParams(params: ToolParams): string | null {
const { wait_for_previous: _, ...paramsToValidate } = params;
const errors = SchemaValidator.validate(
this.parameterSchema,
paramsToValidate,
);
if (errors) {
return errors;
}
return this.validateToolParamValues(params);
}

protected createInvocation(
params: ToolParams,
messageBus: MessageBus,
Expand Down
Loading