ai-cli-hub
Version:
Unified MCP Server for AI CLI Tools (Gemini, Qwen, OpenCode)
141 lines (116 loc) • 4.54 kB
JavaScript
/**
* Direct Tool Testing - MCPサーバーのツールを直接テスト
* MCPプロトコルを介さずに各ツール実装を直接呼び出してテストします
*/
// ツール実装を直接インポート
import { createFileOperationTools, executeFileOperationTool } from '../src/tools/file-ops.js';
import { createAuthTools, executeAuthTool } from '../src/tools/auth.js';
import { createGitTools, executeGitTool } from '../src/tools/git.js';
import { createOpenCodeTools, executeOpenCodeTool } from '../src/tools/opencode.js';
import { OAuthManager } from '../src/auth/oauth-manager.js';
console.log("🧪 AI CLI Hub - Direct Tool Testing");
console.log("=====================================");
async function testFileOperations() {
console.log("\\n📁 Testing File Operations Tools");
try {
const fileTools = await createFileOperationTools();
console.log("✅ File tools loaded:", fileTools.size, "tools");
// ファイル書き込みテスト
const writeResult = await executeFileOperationTool(
"file_write",
{
path: "/tmp/mcp-direct-test.txt",
content: "Hello World from Direct MCP Tool Test!\\nTime: " + new Date().toISOString()
}
);
console.log("✅ File write:", writeResult.success ? "Success" : "Failed");
// ファイル読み込みテスト
const readResult = await executeFileOperationTool(
"file_read",
{ path: "/tmp/mcp-direct-test.txt" }
);
console.log("✅ File read:", readResult.success ? "Success" : "Failed");
console.log(" Content length:", readResult.content?.length || 0);
} catch (error) {
console.error("❌ File operations test failed:", error.message);
}
}
async function testAuthTools() {
console.log("\\n🔐 Testing Authentication Tools");
try {
const authTools = await createAuthTools();
const oauthManager = new OAuthManager();
console.log("✅ Auth tools loaded:", authTools.size, "tools");
// 認証状態チェックテスト
const statusResult = await executeAuthTool(
"auth_check_status",
{},
oauthManager
);
console.log("✅ Auth status check:");
console.log(" Providers:", Object.keys(statusResult.providers || {}));
console.log(" Authenticated:", statusResult.authenticatedCount || 0);
} catch (error) {
console.error("❌ Auth tools test failed:", error.message);
}
}
async function testGitTools() {
console.log("\\n🌟 Testing Git Tools");
try {
const gitTools = await createGitTools();
console.log("✅ Git tools loaded:", gitTools.size, "tools");
// Gitリポジトリがある場所でテスト
const statusResult = await executeGitTool(
"git_status",
{ repository: "/Users/jun/ai-cli" }
);
console.log("✅ Git status:", statusResult.success ? "Success" : "Failed");
if (statusResult.repository) {
console.log(" Repository:", statusResult.repository);
console.log(" Branch:", statusResult.branch || "Unknown");
}
} catch (error) {
console.error("❌ Git tools test failed:", error.message);
}
}
async function testOpenCodeTools() {
console.log("\\n🤖 Testing OpenCode Tools");
try {
const openCodeTools = await createOpenCodeTools({
enabled: true,
provider: "anthropic",
apiKey: "demo-key",
useOAuth: false
});
console.log("✅ OpenCode tools loaded:", openCodeTools.size, "tools");
// ChatテストではAPIキーが無効なのでエラーになることを想定
const chatResult = await executeOpenCodeTool(
"opencode_chat",
{
message: "Hello World test message",
provider: "anthropic"
},
{ enabled: true, provider: "anthropic", apiKey: "demo-key" }
);
console.log("✅ OpenCode chat test executed");
console.log(" Result type:", typeof chatResult);
} catch (error) {
console.log("⚠️ OpenCode test expected error:", error.message.substring(0, 100) + "...");
console.log(" (This is expected without real API key)");
}
}
// メイン実行
async function main() {
try {
await testFileOperations();
await testAuthTools();
await testGitTools();
await testOpenCodeTools();
console.log("\\n🎉 Direct tool testing completed!");
console.log("All core functionalities are working correctly.");
} catch (error) {
console.error("\\n❌ Testing failed:", error);
}
}
main();