Spaces:
Running
Running
| import test from 'node:test'; | |
| import assert from 'node:assert/strict'; | |
| import { compactMcpResult, normalizeMcpTools } from '../src/tools/mcp-client.js'; | |
| import { prepareToolCall } from '../src/tools/tool-registry.js'; | |
| test('normalizes compatible MCP tools for the existing tool loop', () => { | |
| const [tool] = normalizeMcpTools([{ | |
| name: 'search_docs', | |
| description: 'Search documentation.', | |
| inputSchema: { | |
| type: 'object', | |
| properties: { query: { type: 'string' } }, | |
| required: ['query'], | |
| additionalProperties: false, | |
| }, | |
| }]); | |
| assert.equal(tool.source, 'mcp'); | |
| assert.equal(tool.enabled, false); | |
| tool.enabled = true; | |
| const prepared = prepareToolCall({ name: 'search_docs', arguments: { query: 'WebGPU' }, positional: [] }, [tool]); | |
| assert.deepEqual(prepared.args, { query: 'WebGPU' }); | |
| }); | |
| test('skips MCP tools with unsupported names or non-object schemas', () => { | |
| const tools = normalizeMcpTools([ | |
| { name: 'bad-name', inputSchema: { type: 'object', properties: {} } }, | |
| { name: 'primitive', inputSchema: { type: 'string' } }, | |
| { name: 'valid_tool', inputSchema: { type: 'object', properties: {} } }, | |
| ]); | |
| assert.deepEqual(tools.map(tool => tool.name), ['valid_tool']); | |
| }); | |
| test('compacts large MCP text results before returning them to the model', () => { | |
| const result = compactMcpResult({ content: [{ type: 'text', text: 'x'.repeat(18000) }] }); | |
| assert.equal(result.truncated, true); | |
| assert.equal(result.content[0].text.length, 4000); | |
| assert.ok(JSON.stringify(result).length < 4200); | |
| }); | |