/**
* Simple test client to demonstrate MCP server usage
* This simulates how an AI agent would interact with the MCP server
*/
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
import { spawn } from "child_process";
class TestClient {
constructor() {
this.client = null;
}
async connect() {
// Spawn the MCP server
const serverProcess = spawn("node", ["src/index.js"], {
cwd: process.cwd(),
});
const transport = new StdioClientTransport({
command: "node",
args: ["src/index.js"],
});
this.client = new Client(
{
name: "saros-test-client",
version: "1.0.0",
},
{
capabilities: {},
}
);
await this.client.connect(transport);
console.log("โ
Connected to Saros MCP Server\n");
}
async listTools() {
const response = await this.client.listTools();
console.log("๐ Available Tools:");
response.tools.forEach((tool, idx) => {
console.log(`\n${idx + 1}. ${tool.name}`);
console.log(` Description: ${tool.description}`);
});
console.log("\n");
}
async testGetLpPositions(wallet) {
console.log(`๐ Testing: get_lp_positions for ${wallet}`);
try {
const result = await this.client.callTool({
name: "get_lp_positions",
arguments: { wallet },
});
console.log(result.content[0].text);
} catch (error) {
console.error(`โ Error: ${error.message}`);
}
console.log("\n---\n");
}
async testSimulateRebalance(wallet, threshold) {
console.log(`โ๏ธ Testing: simulate_rebalance for ${wallet} (threshold: ${threshold}%)`);
try {
const result = await this.client.callTool({
name: "simulate_rebalance",
arguments: { wallet, threshold },
});
console.log(result.content[0].text);
} catch (error) {
console.error(`โ Error: ${error.message}`);
}
console.log("\n---\n");
}
async testPortfolioAnalytics(wallet) {
console.log(`๐ Testing: portfolio_analytics for ${wallet}`);
try {
const result = await this.client.callTool({
name: "portfolio_analytics",
arguments: { wallet },
});
console.log(result.content[0].text);
} catch (error) {
console.error(`โ Error: ${error.message}`);
}
console.log("\n---\n");
}
async testGetFarmPositions(wallet) {
console.log(`๐พ Testing: get_farm_positions for ${wallet}`);
try {
const result = await this.client.callTool({
name: "get_farm_positions",
arguments: { wallet },
});
console.log(result.content[0].text);
} catch (error) {
console.error(`โ Error: ${error.message}`);
}
console.log("\n---\n");
}
async testSwapQuote(poolAddress, fromMint, toMint, amount) {
console.log(`๐ฑ Testing: swap_quote`);
try {
const result = await this.client.callTool({
name: "swap_quote",
arguments: { poolAddress, fromMint, toMint, amount },
});
console.log(result.content[0].text);
} catch (error) {
console.error(`โ Error: ${error.message}`);
}
console.log("\n---\n");
}
async disconnect() {
await this.client.close();
console.log("๐ Disconnected from server");
}
}
// Run tests
async function main() {
console.log("๐ Saros MCP Server Test Client\n");
console.log("=================================\n");
const client = new TestClient();
try {
await client.connect();
await client.listTools();
// Example wallet (replace with a real Solana wallet for actual testing)
const testWallet = "5UrM9csUEDBeBqMZTuuZyHRNhbRW4vQ1MgKJDrKU1U2v";
// Test all tools
await client.testGetLpPositions(testWallet);
await client.testSimulateRebalance(testWallet, 5);
await client.testPortfolioAnalytics(testWallet);
await client.testGetFarmPositions(testWallet);
// Test swap quote with example pool
const examplePool = "2wUvdZA8ZsY714Y5wUL9fkFmupJGGwzui2N74zqJWgty";
const c98Token = "C98A4nkJXhpVZNAZdHUA95RpTF3T4whtQubL3YobiUX9";
const usdcToken = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
await client.testSwapQuote(examplePool, c98Token, usdcToken, 1);
await client.disconnect();
} catch (error) {
console.error("Fatal error:", error);
process.exit(1);
}
}
main().catch(console.error);