@covalenthq/goldrush-mcp-server
Version:
GoldRush MCP Server for interacting with Covalent GoldRush API
137 lines • 4.92 kB
JavaScript
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
import path from "path";
async function tokenBalancesExample(client) {
console.log("\n=== token_balances Example ===");
const result = await client.callTool({
name: "token_balances",
arguments: {
chainName: "eth-mainnet",
address: "0xfC43f5F9dd45258b3AFf31Bdbe6561D97e8B71de",
quoteCurrency: "USD",
nft: false,
},
});
console.log("Token balances:", result.content);
}
async function historicalBalancesExample(client) {
console.log("\n=== historical_token_balances Example ===");
const result = await client.callTool({
name: "historical_token_balances",
arguments: {
chainName: "eth-mainnet",
address: "0xfC43f5F9dd45258b3AFf31Bdbe6561D97e8B71de",
quoteCurrency: "USD",
date: "2024-01-01",
},
});
console.log("Historical balances:", result.content);
}
async function transactionsExample(client) {
console.log("\n=== transactions_for_address Example ===");
const result = await client.callTool({
name: "transactions_for_address",
arguments: {
chainName: "eth-mainnet",
walletAddress: "0xfC43f5F9dd45258b3AFf31Bdbe6561D97e8B71de",
page: 0,
quoteCurrency: "USD",
noLogs: true,
},
});
console.log("Transactions:", result.content);
}
async function specificTransactionExample(client) {
console.log("\n=== transaction Example ===");
const result = await client.callTool({
name: "transaction",
arguments: {
chainName: "eth-mainnet",
txHash: "0x5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060",
},
});
console.log("Transaction details:", result.content);
}
async function poolSpotPricesExample(client) {
console.log("\n=== pool_spot_prices Example ===");
const result = await client.callTool({
name: "pool_spot_prices",
arguments: {
chainName: "eth-mainnet",
contractAddress: "0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8",
quoteCurrency: "USD",
},
});
console.log("Pool spot prices:", result.content);
}
async function getSupportedChainsResourceExample(client) {
console.log("\n=== supported-chains Resource Example ===");
const result = await client.readResource({
uri: "config://supported-chains",
});
if (result.contents &&
result.contents.length > 0 &&
result.contents[0] &&
"text" in result.contents[0]) {
const chains = JSON.parse(result.contents[0].text);
console.log("Supported chains from resource:", chains);
}
else {
console.log("No content found in supported-chains resource");
}
}
async function getQuoteCurrenciesResourceExample(client) {
console.log("\n=== quote-currencies Resource Example ===");
const result = await client.readResource({
uri: "config://quote-currencies",
});
if (result.contents &&
result.contents.length > 0 &&
result.contents[0] &&
"text" in result.contents[0]) {
const currencies = JSON.parse(result.contents[0].text);
console.log("Supported quote currencies from resource:", currencies);
}
else {
console.log("No content found in quote-currencies resource");
}
}
async function main() {
const transport = new StdioClientTransport({
command: "node",
args: [path.resolve(process.cwd(), "dist/index.js")],
});
const client = new Client({
name: "GoldRush MCP Example Client",
version: "1.0.0",
}, {
capabilities: {
tools: {},
resources: {},
},
});
try {
await client.connect(transport);
const tools = await client.listTools();
console.log("Available tools:", tools.tools.map((tool) => tool.name).join(", "));
const resources = await client.listResources();
console.log("Available resources:", resources.resources.map((resource) => resource.name).join(", "));
await tokenBalancesExample(client);
await historicalBalancesExample(client);
await transactionsExample(client);
await specificTransactionExample(client);
await poolSpotPricesExample(client);
await getSupportedChainsResourceExample(client);
await getQuoteCurrenciesResourceExample(client);
console.log("\nAll examples completed successfully");
}
catch (error) {
console.error("Error:", error);
}
finally {
await client.close();
console.log("Connection closed");
}
}
main().catch(console.error);
//# sourceMappingURL=example-client.js.map