chore: fix typo in mcp-client (#1555)
Co-authored-by: Scott Densmore <scottdensmore@mac.com>
This commit is contained in:
parent
6c4391dda5
commit
221b066900
|
@ -14,7 +14,7 @@ import {
|
||||||
afterEach,
|
afterEach,
|
||||||
Mocked,
|
Mocked,
|
||||||
} from 'vitest';
|
} from 'vitest';
|
||||||
import { discoverMcpTools, sanatizeParameters } from './mcp-client.js';
|
import { discoverMcpTools, sanitizeParameters } from './mcp-client.js';
|
||||||
import { Schema, Type } from '@google/genai';
|
import { Schema, Type } from '@google/genai';
|
||||||
import { Config, MCPServerConfig } from '../config/config.js';
|
import { Config, MCPServerConfig } from '../config/config.js';
|
||||||
import { DiscoveredMCPTool } from './mcp-tool.js';
|
import { DiscoveredMCPTool } from './mcp-tool.js';
|
||||||
|
@ -538,10 +538,10 @@ describe('discoverMcpTools', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('sanatizeParameters', () => {
|
describe('sanitizeParameters', () => {
|
||||||
it('should do nothing for an undefined schema', () => {
|
it('should do nothing for an undefined schema', () => {
|
||||||
const schema = undefined;
|
const schema = undefined;
|
||||||
sanatizeParameters(schema);
|
sanitizeParameters(schema);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should remove default when anyOf is present', () => {
|
it('should remove default when anyOf is present', () => {
|
||||||
|
@ -549,11 +549,11 @@ describe('sanatizeParameters', () => {
|
||||||
anyOf: [{ type: Type.STRING }, { type: Type.NUMBER }],
|
anyOf: [{ type: Type.STRING }, { type: Type.NUMBER }],
|
||||||
default: 'hello',
|
default: 'hello',
|
||||||
};
|
};
|
||||||
sanatizeParameters(schema);
|
sanitizeParameters(schema);
|
||||||
expect(schema.default).toBeUndefined();
|
expect(schema.default).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should recursively sanatize items in anyOf', () => {
|
it('should recursively sanitize items in anyOf', () => {
|
||||||
const schema: Schema = {
|
const schema: Schema = {
|
||||||
anyOf: [
|
anyOf: [
|
||||||
{
|
{
|
||||||
|
@ -563,22 +563,22 @@ describe('sanatizeParameters', () => {
|
||||||
{ type: Type.NUMBER },
|
{ type: Type.NUMBER },
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
sanatizeParameters(schema);
|
sanitizeParameters(schema);
|
||||||
expect(schema.anyOf![0].default).toBeUndefined();
|
expect(schema.anyOf![0].default).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should recursively sanatize items in items', () => {
|
it('should recursively sanitize items in items', () => {
|
||||||
const schema: Schema = {
|
const schema: Schema = {
|
||||||
items: {
|
items: {
|
||||||
anyOf: [{ type: Type.STRING }],
|
anyOf: [{ type: Type.STRING }],
|
||||||
default: 'world',
|
default: 'world',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
sanatizeParameters(schema);
|
sanitizeParameters(schema);
|
||||||
expect(schema.items!.default).toBeUndefined();
|
expect(schema.items!.default).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should recursively sanatize items in properties', () => {
|
it('should recursively sanitize items in properties', () => {
|
||||||
const schema: Schema = {
|
const schema: Schema = {
|
||||||
properties: {
|
properties: {
|
||||||
prop1: {
|
prop1: {
|
||||||
|
@ -587,7 +587,7 @@ describe('sanatizeParameters', () => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
sanatizeParameters(schema);
|
sanitizeParameters(schema);
|
||||||
expect(schema.properties!.prop1.default).toBeUndefined();
|
expect(schema.properties!.prop1.default).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -614,7 +614,7 @@ describe('sanatizeParameters', () => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
sanatizeParameters(schema);
|
sanitizeParameters(schema);
|
||||||
expect(schema.properties!.prop1.items!.default).toBeUndefined();
|
expect(schema.properties!.prop1.items!.default).toBeUndefined();
|
||||||
const nestedProp =
|
const nestedProp =
|
||||||
schema.properties!.prop2.anyOf![0].properties!.nestedProp;
|
schema.properties!.prop2.anyOf![0].properties!.nestedProp;
|
||||||
|
|
|
@ -304,7 +304,7 @@ async function connectAndDiscover(
|
||||||
toolNameForModel.slice(0, 28) + '___' + toolNameForModel.slice(-32);
|
toolNameForModel.slice(0, 28) + '___' + toolNameForModel.slice(-32);
|
||||||
}
|
}
|
||||||
|
|
||||||
sanatizeParameters(funcDecl.parameters);
|
sanitizeParameters(funcDecl.parameters);
|
||||||
|
|
||||||
// Ensure parameters is a valid JSON schema object, default to empty if not.
|
// Ensure parameters is a valid JSON schema object, default to empty if not.
|
||||||
const parameterSchema: Record<string, unknown> =
|
const parameterSchema: Record<string, unknown> =
|
||||||
|
@ -362,7 +362,7 @@ async function connectAndDiscover(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sanatizeParameters(schema?: Schema) {
|
export function sanitizeParameters(schema?: Schema) {
|
||||||
if (!schema) {
|
if (!schema) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -370,15 +370,15 @@ export function sanatizeParameters(schema?: Schema) {
|
||||||
// Vertex AI gets confused if both anyOf and default are set.
|
// Vertex AI gets confused if both anyOf and default are set.
|
||||||
schema.default = undefined;
|
schema.default = undefined;
|
||||||
for (const item of schema.anyOf) {
|
for (const item of schema.anyOf) {
|
||||||
sanatizeParameters(item);
|
sanitizeParameters(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (schema.items) {
|
if (schema.items) {
|
||||||
sanatizeParameters(schema.items);
|
sanitizeParameters(schema.items);
|
||||||
}
|
}
|
||||||
if (schema.properties) {
|
if (schema.properties) {
|
||||||
for (const item of Object.values(schema.properties)) {
|
for (const item of Object.values(schema.properties)) {
|
||||||
sanatizeParameters(item);
|
sanitizeParameters(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue