#!/usr/bin/env tsx
/**
* Manual testing CLI for searchfox-mcp
* Allows quick interactive testing of individual tools
*/
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
async function testTool(toolName: string, args: Record<string, unknown>) {
console.log(`\nπ§ Testing tool: ${toolName}`);
console.log(`π¦ Arguments: ${JSON.stringify(args, null, 2)}\n`);
const client = new Client(
{
name: "searchfox-manual-test",
version: "1.0.0",
},
{
capabilities: {},
}
);
const transport = new StdioClientTransport({
command: "tsx",
args: ["src/index.ts"],
});
try {
console.log("π Connecting to server...");
await client.connect(transport);
console.log("β
Connected\n");
console.log("β³ Calling tool...");
const startTime = Date.now();
const result = await client.callTool({
name: toolName,
arguments: args,
});
const duration = Date.now() - startTime;
console.log(`β
Tool call completed in ${duration}ms\n`);
if (result.isError) {
console.error("β Error result:");
console.error(JSON.stringify(result.content, null, 2));
} else {
console.log("β
Success result:");
const content = result.content[0];
if (content.type === "text") {
const parsed = JSON.parse(content.text);
console.log(JSON.stringify(parsed, null, 2));
} else {
console.log(content);
}
}
await client.close();
} catch (error) {
console.error("\nπ₯ Error:", error);
process.exit(1);
}
}
// Parse command line arguments
const args = process.argv.slice(2);
if (args.length < 2) {
console.log("Usage: tsx manual-test.ts <tool-name> <args-json>");
console.log("\nExamples:");
console.log(
' tsx manual-test.ts search \'{"query":"nsIFrame","repo":"mozilla-central","limit":5}\''
);
console.log(
' tsx manual-test.ts get_definition \'{"symbol":"nsIFrame","repo":"mozilla-central"}\''
);
console.log(
' tsx manual-test.ts get_call_graph \'{"mode":"calls-from","source_symbol":"nsIFrame::GetContent","repo":"mozilla-central","depth":1}\''
);
console.log(
' tsx manual-test.ts get_field_layout \'{"class_name":"nsIFrame","repo":"mozilla-central"}\''
);
console.log(
' tsx manual-test.ts get_blame \'{"path":"dom/base/nsGlobalWindowOuter.cpp","repo":"mozilla-central","start_line":1,"end_line":10}\''
);
console.log(
' tsx manual-test.ts get_file \'{"repo":"mozilla-central","path":"dom/base/nsGlobalWindowOuter.h","lines":{"start":1,"end":50}}\''
);
console.log(
' tsx manual-test.ts search_paths \'{"pattern":"nsGlobal*.h","repo":"mozilla-central","limit":10}\''
);
console.log(
' tsx manual-test.ts search_symbols \'{"symbol":"MessagePort","type":"symbol","repo":"mozilla-central","limit":10}\''
);
process.exit(1);
}
const toolName = args[0];
let toolArgs: Record<string, unknown>;
try {
toolArgs = JSON.parse(args[1]);
} catch {
console.error("β Invalid JSON for arguments:", args[1]);
process.exit(1);
}
testTool(toolName, toolArgs);