@covalenthq/goldrush-mcp-server
Version:
GoldRush MCP Server for interacting with Covalent GoldRush API
181 lines • 6.95 kB
JavaScript
import { validQuoteValues } from "../utils/constants.js";
import { PARAM_DESCRIPTIONS, TOOL_DESCRIPTIONS, } from "../utils/generated-descriptions.js";
import { stringifyWithBigInt } from "../utils/helpers.js";
import { ChainName, } from "@covalenthq/client-sdk";
import { z } from "zod";
export function addTransactionServiceTools(server, goldRushClient) {
server.tool("transaction", TOOL_DESCRIPTIONS["transaction"], {
chainName: z
.enum(Object.values(ChainName))
.describe(PARAM_DESCRIPTIONS["transaction"]["chainName"]),
txHash: z
.string()
.describe(PARAM_DESCRIPTIONS["transaction"]["txHash"]),
quoteCurrency: z
.enum(Object.values(validQuoteValues))
.optional()
.describe(PARAM_DESCRIPTIONS["transaction"]["quoteCurrency"]),
noLogs: z
.boolean()
.optional()
.default(true)
.describe(PARAM_DESCRIPTIONS["transaction"]["noLogs"]),
withInternal: z
.boolean()
.optional()
.describe(PARAM_DESCRIPTIONS["transaction"]["withInternal"]),
withState: z
.boolean()
.optional()
.describe(PARAM_DESCRIPTIONS["transaction"]["withState"]),
withInputData: z
.boolean()
.optional()
.describe(PARAM_DESCRIPTIONS["transaction"]["withInputData"]),
}, async (params) => {
try {
const response = await goldRushClient.TransactionService.getTransaction(params.chainName, params.txHash, {
quoteCurrency: params.quoteCurrency,
noLogs: params.noLogs,
withInternal: params.withInternal,
withState: params.withState,
withInputData: params.withInputData,
});
return {
content: [
{
type: "text",
text: stringifyWithBigInt(response.data),
},
],
};
}
catch (error) {
return {
content: [{ type: "text", text: `Error: ${error}` }],
isError: true,
};
}
});
server.tool("transaction_summary", TOOL_DESCRIPTIONS["transaction_summary"], {
chainName: z
.enum(Object.values(ChainName))
.describe(PARAM_DESCRIPTIONS["transaction_summary"]["chainName"]),
walletAddress: z
.string()
.describe(PARAM_DESCRIPTIONS["transaction_summary"]["walletAddress"]),
quoteCurrency: z
.enum(Object.values(validQuoteValues))
.optional()
.describe(PARAM_DESCRIPTIONS["transaction_summary"]["quoteCurrency"]),
withGas: z
.boolean()
.optional()
.describe(PARAM_DESCRIPTIONS["transaction_summary"]["withGas"]),
}, async (params) => {
try {
const response = await goldRushClient.TransactionService.getTransactionSummary(params.chainName, params.walletAddress, {
quoteCurrency: params.quoteCurrency,
withGas: params.withGas,
});
return {
content: [
{
type: "text",
text: stringifyWithBigInt(response.data),
},
],
};
}
catch (err) {
return {
content: [{ type: "text", text: `Error: ${err}` }],
isError: true,
};
}
});
server.tool("transactions_for_address", TOOL_DESCRIPTIONS["transactions_for_address"], {
chainName: z
.enum(Object.values(ChainName))
.describe(PARAM_DESCRIPTIONS["transactions_for_address"]["chainName"]),
walletAddress: z
.string()
.describe(PARAM_DESCRIPTIONS["transactions_for_address"]["walletAddress"]),
page: z
.number()
.describe(PARAM_DESCRIPTIONS["transactions_for_address"]["page"]),
quoteCurrency: z
.enum(Object.values(validQuoteValues))
.optional()
.describe(PARAM_DESCRIPTIONS["transactions_for_address"]["quoteCurrency"]),
noLogs: z
.boolean()
.optional()
.default(true)
.describe(PARAM_DESCRIPTIONS["transactions_for_address"]["noLogs"]),
blockSignedAtAsc: z
.boolean()
.optional()
.describe(PARAM_DESCRIPTIONS["transactions_for_address"]["blockSignedAtAsc"]),
}, async (params) => {
try {
const response = await goldRushClient.TransactionService.getPaginatedTransactionsForAddress(params.chainName, params.walletAddress, params.page, {
quoteCurrency: params.quoteCurrency,
noLogs: params.noLogs,
blockSignedAtAsc: params.blockSignedAtAsc,
});
return {
content: [
{
type: "text",
text: stringifyWithBigInt(response.data),
},
],
};
}
catch (err) {
return {
content: [{ type: "text", text: `Error: ${err}` }],
isError: true,
};
}
});
server.tool("transactions_for_block", TOOL_DESCRIPTIONS["transactions_for_block"], {
chainName: z
.enum(Object.values(ChainName))
.describe(PARAM_DESCRIPTIONS["transactions_for_block"]["chainName"]),
blockHeight: z
.union([z.string(), z.number(), z.literal("latest")])
.describe(PARAM_DESCRIPTIONS["transactions_for_block"]["blockHeight"]),
quoteCurrency: z
.enum(Object.values(validQuoteValues))
.optional()
.describe(PARAM_DESCRIPTIONS["transactions_for_block"]["quoteCurrency"]),
noLogs: z
.boolean()
.optional()
.describe(PARAM_DESCRIPTIONS["transactions_for_block"]["noLogs"]),
}, async (params) => {
try {
const response = await goldRushClient.TransactionService.getTransactionsForBlockByPage(params.chainName, params.blockHeight, 0, {
quoteCurrency: params.quoteCurrency,
noLogs: params.noLogs,
});
return {
content: [
{
type: "text",
text: stringifyWithBigInt(response.data),
},
],
};
}
catch (err) {
return {
content: [{ type: "text", text: `Error: ${err}` }],
isError: true,
};
}
});
}
//# sourceMappingURL=TransactionService.js.map