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 options = {
hostname: '127.0.0.1',
port: MCP_PORT,
path: '/messages',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(payload)
}
};
const req = http.request(options, (res) => {
let body = '';
res.on('data', chunk => body += chunk);
res.on('end', () => {
if (res.statusCode >= 200 && res.statusCode < 300) {
try {
const json = JSON.parse(body);
if (json.error) reject(json.error);
else resolve(json.result);
} catch (e) {
reject(new Error(`Invalid JSON: ${body}`));
}
} else {
reject(new Error(`HTTP Error ${res.statusCode}: ${body}`));
}
});
});
req.on('error', reject);
req.write(payload);
req.end();
});
}
function parseContent(result) {
try {
const text = result.content[0].text;
if (text.startsWith('[') || text.startsWith('{')) {
return JSON.parse(text);
}
return text;
} catch (e) {
return [];
}
}
async function main() {
try {
console.log("=== Testing Default Limit ===");
// We assume there are enough items in DB (US Presidents ~47 + added items > 10)
// Search for something broad like "President" or just "a"
console.log("Searching for 'a' without limit...");
const res = await sendJsonRpc('find_documents', {
content: "a"
});
const items = parseContent(res);
console.log(`Returned ${items.length} items.`);
if (items.length === 10) {
console.log("SUCCESS: Default limit appears to be 10.");
} else if (items.length > 10) {
console.error("FAILURE: Returned more than 10 items!");
} else {
console.log("NOTE: Returned fewer than 10 items. Is the DB populated?");
// We can try to add more items if needed, but existing tests added >40 presidents.
}
} catch (error) {
console.error("Test Failed:", error);
}
}
main();