Newer
Older
TelosDB / scripts / test_long_text.cjs

const http = require('http');

const MCP_PORT = 3000;

function sendJsonRpc(method, params) {
    return new Promise((resolve, reject) => {
        const payload = JSON.stringify({
            jsonrpc: "2.0",
            method: "tools/call",
            params: {
                name: method,
                arguments: params
            },
            id: Date.now()
        });

        const req = http.request({
            hostname: '127.0.0.1',
            port: MCP_PORT,
            path: '/messages',
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                'Content-Length': Buffer.byteLength(payload)
            }
        }, (res) => {
            let data = '';
            res.on('data', (chunk) => data += chunk);
            res.on('end', () => {
                if (res.statusCode >= 400) {
                    reject(new Error(`HTTP ${res.statusCode}: ${data}`));
                } else {
                    resolve(JSON.parse(data));
                }
            });
        });

        req.on('error', reject);
        req.write(payload);
        req.end();
    });
}

function parseContent(res) {
    if (res.error) {
        console.error("Test Failed:", res.error);
        process.exit(1);
    }
    return res.result.content[0].text;
}

async function runTest() {
    try {
        console.log("=== Testing Long Text Support ===");
        const baseSentence = "This is a long test sentence that will be repeated many times to test the context window and body limit. ";

        for (const repeatCount of [50, 100, 200]) {
            const longText = baseSentence.repeat(repeatCount);
            console.log(`\n--- Testing with length: ${longText.length} characters ---`);

            // 2. Save Document
            console.log(`2. Saving long document (len=${longText.length})...`);
            try {
                const saveRes = await sendJsonRpc('save_document', {
                    content: longText,
                    document_name: `test/long_text_${longText.length}.txt`
                });
                const saveMsg = parseContent(saveRes);
                console.log("   Result:", saveMsg);

                // 3. Search
                console.log("3. Searching for the document...");
                const searchRes = await sendJsonRpc('find_documents', {
                    content: "long test sentence that will be repeated many times",
                    limit: 1
                });
                const results = JSON.parse(parseContent(searchRes));
                console.log(`   Found ${results.length} results.`);
            } catch (err) {
                console.error(`   Failed for length ${longText.length}:`, err.message);
            }
        }

        console.log("\n=== Test Complete ===");
    } catch (err) {
        console.error("Test Error:", err);
    }
}

runTest();