crypto.ts•9.22 kB
import { z } from "zod";
import { CryptoClient } from "../api/crypto/CryptoClient.js";
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
/**
* Register all cryptocurrency-related tools with the MCP server
* @param server The MCP server instance
* @param accessToken The Financial Modeling Prep API access token (optional when using lazy loading)
*/
export function registerCryptoTools(
server: McpServer,
accessToken?: string
): void {
const cryptoClient = new CryptoClient(accessToken);
server.tool(
"getCryptocurrencyList",
"Access a comprehensive list of all cryptocurrencies traded on exchanges worldwide with the FMP Cryptocurrencies Overview API. Get detailed information on each cryptocurrency to inform your investment strategies.",
{},
async () => {
try {
const results = await cryptoClient.getList();
return {
content: [{ type: "text", text: JSON.stringify(results, null, 2) }],
};
} catch (error) {
return {
content: [
{
type: "text",
text: `Error: ${
error instanceof Error ? error.message : String(error)
}`,
},
],
isError: true,
};
}
});
server.tool(
"getCryptocurrencyQuote",
"Access real-time quotes for all cryptocurrencies with the FMP Full Cryptocurrency Quote API. Obtain comprehensive price data including current, high, low, and open prices.",
{
symbol: z.string().describe("Cryptocurrency symbol (e.g., BTCUSD)"),
},
async ({ symbol }) => {
try {
const results = await cryptoClient.getQuote(symbol);
return {
content: [{ type: "text", text: JSON.stringify(results, null, 2) }],
};
} catch (error) {
return {
content: [
{
type: "text",
text: `Error: ${
error instanceof Error ? error.message : String(error)
}`,
},
],
isError: true,
};
}
}
);
server.tool(
"getCryptocurrencyShortQuote",
"Access real-time cryptocurrency quotes with the FMP Cryptocurrency Quick Quote API. Get a concise overview of current crypto prices, changes, and trading volume for a wide range of digital assets.",
{
symbol: z.string().describe("Cryptocurrency symbol (e.g., BTCUSD)"),
},
async ({ symbol }) => {
try {
const results = await cryptoClient.getShortQuote(symbol);
return {
content: [{ type: "text", text: JSON.stringify(results, null, 2) }],
};
} catch (error) {
return {
content: [
{
type: "text",
text: `Error: ${
error instanceof Error ? error.message : String(error)
}`,
},
],
isError: true,
};
}
}
);
server.tool(
"getCryptocurrencyBatchQuotes",
"Access live price data for a wide range of cryptocurrencies with the FMP Real-Time Cryptocurrency Batch Quotes API. Get real-time updates on prices, market changes, and trading volumes for digital assets in a single request.",
{
short: z.boolean().optional().describe("Get short quotes instead of full quotes"),
},
async ({ short }) => {
try {
const results = await cryptoClient.getBatchQuotes(short);
return {
content: [{ type: "text", text: JSON.stringify(results, null, 2) }],
};
} catch (error) {
return {
content: [
{
type: "text",
text: `Error: ${
error instanceof Error ? error.message : String(error)
}`,
},
],
isError: true,
};
}
}
);
server.tool(
"getCryptocurrencyHistoricalLightChart",
"Access historical end-of-day prices for a variety of cryptocurrencies with the Historical Cryptocurrency Price Snapshot API. Track trends in price and trading volume over time to better understand market behavior.",
{
symbol: z.string().describe("Cryptocurrency symbol (e.g., BTCUSD)"),
from: z.string().optional().describe("Start date (YYYY-MM-DD)"),
to: z.string().optional().describe("End date (YYYY-MM-DD)"),
},
async ({ symbol, from, to }) => {
try {
const results = await cryptoClient.getHistoricalLightChart(
symbol,
from,
to
);
return {
content: [{ type: "text", text: JSON.stringify(results, null, 2) }],
};
} catch (error) {
return {
content: [
{
type: "text",
text: `Error: ${
error instanceof Error ? error.message : String(error)
}`,
},
],
isError: true,
};
}
}
);
server.tool(
"getCryptocurrencyHistoricalFullChart",
"Access comprehensive end-of-day (EOD) price data for cryptocurrencies with the Full Historical Cryptocurrency Data API. Analyze long-term price trends, market movements, and trading volumes to inform strategic decisions.",
{
symbol: z.string().describe("Cryptocurrency symbol (e.g., BTCUSD)"),
from: z.string().optional().describe("Start date (YYYY-MM-DD)"),
to: z.string().optional().describe("End date (YYYY-MM-DD)"),
},
async ({ symbol, from, to }) => {
try {
const results = await cryptoClient.getHistoricalFullChart(
symbol,
from,
to
);
return {
content: [{ type: "text", text: JSON.stringify(results, null, 2) }],
};
} catch (error) {
return {
content: [
{
type: "text",
text: `Error: ${
error instanceof Error ? error.message : String(error)
}`,
},
],
isError: true,
};
}
}
);
server.tool(
"getCryptocurrency1MinuteData",
"Get real-time, 1-minute interval price data for cryptocurrencies with the 1-Minute Cryptocurrency Intraday Data API. Monitor short-term price fluctuations and trading volume to stay updated on market movements.",
{
symbol: z.string().describe("Cryptocurrency symbol (e.g., BTCUSD)"),
from: z.string().optional().describe("Start date (YYYY-MM-DD)"),
to: z.string().optional().describe("End date (YYYY-MM-DD)"),
},
async ({ symbol, from, to }) => {
try {
const results = await cryptoClient.get1MinuteData(symbol, from, to);
return {
content: [{ type: "text", text: JSON.stringify(results, null, 2) }],
};
} catch (error) {
return {
content: [
{
type: "text",
text: `Error: ${
error instanceof Error ? error.message : String(error)
}`,
},
],
isError: true,
};
}
}
);
server.tool(
"getCryptocurrency5MinuteData",
"Analyze short-term price trends with the 5-Minute Interval Cryptocurrency Data API. Access real-time, intraday price data for cryptocurrencies to monitor rapid market movements and optimize trading strategies.",
{
symbol: z.string().describe("Cryptocurrency symbol (e.g., BTCUSD)"),
from: z.string().optional().describe("Start date (YYYY-MM-DD)"),
to: z.string().optional().describe("End date (YYYY-MM-DD)"),
},
async ({ symbol, from, to }) => {
try {
const results = await cryptoClient.get5MinuteData(symbol, from, to);
return {
content: [{ type: "text", text: JSON.stringify(results, null, 2) }],
};
} catch (error) {
return {
content: [
{
type: "text",
text: `Error: ${
error instanceof Error ? error.message : String(error)
}`,
},
],
isError: true,
};
}
}
);
server.tool(
"getCryptocurrency1HourData",
"Access detailed 1-hour intraday price data for cryptocurrencies with the 1-Hour Interval Cryptocurrency Data API. Track hourly price movements to gain insights into market trends and make informed trading decisions throughout the day.",
{
symbol: z.string().describe("Cryptocurrency symbol (e.g., BTCUSD)"),
from: z.string().optional().describe("Start date (YYYY-MM-DD)"),
to: z.string().optional().describe("End date (YYYY-MM-DD)"),
},
async ({ symbol, from, to }) => {
try {
const results = await cryptoClient.get1HourData(symbol, from, to);
return {
content: [{ type: "text", text: JSON.stringify(results, null, 2) }],
};
} catch (error) {
return {
content: [
{
type: "text",
text: `Error: ${
error instanceof Error ? error.message : String(error)
}`,
},
],
isError: true,
};
}
}
);
}