UNPKG

lunarcrush-sdk

Version:

TypeScript/JavaScript SDK for LunarCrush API v4 with GraphQL and MCP support for AI workflows

1,301 lines (1,297 loc) 41.5 kB
import { GraphQLClient } from 'graphql-request'; import { Client } from '@modelcontextprotocol/sdk/client/index.js'; import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js'; // src/index.ts // src/generated/operations.ts var SystemHealthDocument = ` query SystemHealth { systemHealth { status uptime version timestamp } } `; var PingDocument = ` query Ping { ping { status timestamp } } `; var HealthDocument = ` query Health { health } `; var HelloDocument = ` query Hello { hello } `; var GetTopicsListDocument = ` query GetTopicsList { getTopicsList { topic title topic_rank topic_rank_1h_previous topic_rank_24h_previous num_contributors num_posts interactions_24h } } `; var GetTopicDocument = ` query GetTopic($topic: String!) { getTopic(topic: $topic) { topic title topic_rank related_topics types_count types_interactions types_sentiment types_sentiment_detail interactions_24h num_contributors num_posts categories trend } } `; var GetTopicWhatsupDocument = ` query GetTopicWhatsup($topic: String!) { getTopicWhatsup(topic: $topic) { summary } } `; var GetTopicTimeSeriesDocument = ` query GetTopicTimeSeries($topic: String!, $bucket: String, $interval: String, $start: UnixTimestamp, $end: UnixTimestamp) { getTopicTimeSeries( topic: $topic bucket: $bucket interval: $interval start: $start end: $end ) { time contributors_active contributors_created interactions posts_active posts_created sentiment spam alt_rank circulating_supply close galaxy_score high low market_cap market_dominance open social_dominance volume_24h } } `; var GetTopicTimeSeriesV2Document = ` query GetTopicTimeSeriesV2($topic: String!, $bucket: String) { getTopicTimeSeriesV2(topic: $topic, bucket: $bucket) { time contributors_active contributors_created interactions posts_active posts_created sentiment spam alt_rank circulating_supply close galaxy_score high low market_cap market_dominance open social_dominance volume_24h } } `; var GetTopicPostsDocument = ` query GetTopicPosts($topic: String!, $start: UnixTimestamp, $end: UnixTimestamp) { getTopicPosts(topic: $topic, start: $start, end: $end) { id post_type post_title post_link post_image post_created post_sentiment creator_id creator_name creator_display_name creator_followers creator_avatar interactions_24h interactions_total } } `; var GetTopicNewsDocument = ` query GetTopicNews($topic: String!) { getTopicNews(topic: $topic) { id post_type post_title post_link post_image post_created post_sentiment creator_id creator_name creator_display_name creator_followers creator_avatar interactions_24h interactions_total } } `; var GetTopicCreatorsDocument = ` query GetTopicCreators($topic: String!) { getTopicCreators(topic: $topic) { creator_id creator_name creator_avatar creator_followers creator_rank interactions_24h } } `; var GetCategoriesListDocument = ` query GetCategoriesList { getCategoriesList { category title category_rank category_rank_1h_previous category_rank_24h_previous interactions_24h num_contributors num_posts social_dominance } } `; var GetCategoryDocument = ` query GetCategory($category: String!) { getCategory(category: $category) { topic title related_topics types_count types_interactions types_sentiment types_sentiment_detail interactions_24h num_contributors num_posts trend } } `; var GetCategoryTopicsDocument = ` query GetCategoryTopics($category: String!) { getCategoryTopics(category: $category) { topic title topic_rank topic_rank_1h_previous topic_rank_24h_previous num_contributors social_dominance num_posts interactions_24h } } `; var GetCategoryTimeSeriesDocument = ` query GetCategoryTimeSeries($category: String!, $bucket: String, $interval: String, $start: UnixTimestamp, $end: UnixTimestamp) { getCategoryTimeSeries( category: $category bucket: $bucket interval: $interval start: $start end: $end ) { time contributors_active contributors_created interactions posts_active posts_created sentiment spam } } `; var GetCategoryPostsDocument = ` query GetCategoryPosts($category: String!, $start: UnixTimestamp, $end: UnixTimestamp) { getCategoryPosts(category: $category, start: $start, end: $end) { id post_type post_title post_link post_image post_created post_sentiment creator_id creator_name creator_display_name creator_followers creator_avatar interactions_24h interactions_total } } `; var GetCategoryNewsDocument = ` query GetCategoryNews($category: String!) { getCategoryNews(category: $category) { id post_title post_type post_link post_image post_created post_sentiment creator_id creator_name creator_display_name creator_followers creator_avatar interactions_24h interactions_total } } `; var GetCategoryCreatorsDocument = ` query GetCategoryCreators($category: String!) { getCategoryCreators(category: $category) { creator_id creator_name creator_avatar creator_followers creator_rank interactions_24h } } `; var GetCreatorsListDocument = ` query GetCreatorsList { getCreatorsList { creator_display_name creator_id creator_network creator_avatar creator_followers creator_name creator_posts creator_rank interactions_24h } } `; var GetCreatorDocument = ` query GetCreator($network: String!, $id: String!) { getCreator(network: $network, id: $id) { creator_id creator_name creator_display_name creator_avatar creator_followers creator_rank interactions_24h topic_influence { topic count percent rank } } } `; var GetCreatorTimeSeriesDocument = ` query GetCreatorTimeSeries($network: String!, $id: String!, $bucket: String, $interval: String, $start: UnixTimestamp, $end: UnixTimestamp) { getCreatorTimeSeries( network: $network id: $id bucket: $bucket interval: $interval start: $start end: $end ) { time followers interactions posts_active creator_rank } } `; var GetCreatorPostsDocument = ` query GetCreatorPosts($network: String!, $id: String!, $start: UnixTimestamp, $end: UnixTimestamp) { getCreatorPosts(network: $network, id: $id, start: $start, end: $end) { id post_type post_title post_created post_sentiment post_link post_image creator_id creator_name creator_display_name creator_followers creator_avatar interactions_24h interactions_total } } `; var GetCoinsListDocument = ` query GetCoinsList($sort: String, $filter: String, $limit: Int, $desc: String, $page: Int) { getCoinsList( sort: $sort filter: $filter limit: $limit desc: $desc page: $page ) { id symbol name price price_btc volume_24h volatility circulating_supply max_supply percent_change_1h percent_change_24h percent_change_7d percent_change_30d market_cap market_cap_rank interactions_24h social_volume_24h social_dominance market_dominance market_dominance_prev galaxy_score galaxy_score_previous alt_rank alt_rank_previous sentiment categories blockchains { type network address decimals } last_updated_price last_updated_price_by topic logo } } `; var GetCoinsListV2Document = ` query GetCoinsListV2($sort: String, $filter: String, $limit: Int, $desc: String, $page: Int) { getCoinsListV2( sort: $sort filter: $filter limit: $limit desc: $desc page: $page ) { id symbol name price price_btc volume_24h volatility circulating_supply max_supply percent_change_1h percent_change_24h percent_change_7d percent_change_30d market_cap market_cap_rank interactions_24h social_volume_24h social_dominance market_dominance market_dominance_prev galaxy_score galaxy_score_previous alt_rank alt_rank_previous sentiment categories blockchains { type network address decimals } last_updated_price last_updated_price_by topic logo } } `; var GetCoinDocument = ` query GetCoin($coin: String!) { getCoin(coin: $coin) { id name symbol price price_btc market_cap percent_change_24h percent_change_7d percent_change_30d volume_24h max_supply circulating_supply close galaxy_score alt_rank volatility market_cap_rank } } `; var GetCoinMetaDocument = ` query GetCoinMeta($coin: String!) { getCoinMeta(coin: $coin) { id name symbol market_categories updated blockchain { type network address decimals } short_summary description github_link website_link whitepaper_link twitter_link reddit_link header_image header_text videos coingecko_link coinmarketcap_link } } `; var GetCoinTimeSeriesDocument = ` query GetCoinTimeSeries($coin: String!, $bucket: String, $interval: String, $start: UnixTimestamp, $end: UnixTimestamp) { getCoinTimeSeries( coin: $coin bucket: $bucket interval: $interval start: $start end: $end ) { time contributors_active contributors_created interactions posts_active posts_created sentiment spam alt_rank circulating_supply close galaxy_score high low market_cap market_dominance open social_dominance volume_24h } } `; var GetStocksListDocument = ` query GetStocksList { getStocksList { id symbol name price volume_24h percent_change_24h market_cap market_cap_rank interactions_24h social_volume_24h social_dominance market_dominance market_dominance_prev galaxy_score galaxy_score_previous alt_rank alt_rank_previous sentiment categories last_updated_price last_updated_price_by topic logo } } `; var GetStocksListV2Document = ` query GetStocksListV2($sort: String, $limit: Int, $desc: String, $page: Int) { getStocksListV2(sort: $sort, limit: $limit, desc: $desc, page: $page) { id symbol name price volume_24h percent_change_24h market_cap market_cap_rank interactions_24h social_volume_24h social_dominance market_dominance market_dominance_prev galaxy_score galaxy_score_previous alt_rank alt_rank_previous sentiment categories last_updated_price last_updated_price_by topic logo } } `; var GetStockDocument = ` query GetStock($stock: String!) { getStock(stock: $stock) { id name symbol price market_cap percent_change_24h volume_24h close market_cap_rank } } `; var GetStockTimeSeriesDocument = ` query GetStockTimeSeries($stock: String!, $bucket: String, $interval: String, $start: UnixTimestamp, $end: UnixTimestamp) { getStockTimeSeries( stock: $stock bucket: $bucket interval: $interval start: $start end: $end ) { time close alt_rank contributors_active contributors_created galaxy_score high interactions low market_cap market_dominance open posts_active posts_created sentiment social_dominance spam } } `; var GetNftsListDocument = ` query GetNftsList($sort: String, $limit: Int, $desc: String, $page: Int) { getNftsList(sort: $sort, limit: $limit, desc: $desc, page: $page) { id name logo floor_price alt_rank base_crypto galaxy_score interactions_24h lunar_id market_cap percent_change_24h social_contributors social_dominance social_volume_24h volume_24h } } `; var GetNftsListV2Document = ` query GetNftsListV2($sort: String, $limit: Int, $desc: String, $page: Int) { getNftsListV2(sort: $sort, limit: $limit, desc: $desc, page: $page) { id name logo floor_price alt_rank base_crypto galaxy_score interactions_24h lunar_id market_cap percent_change_24h social_contributors social_dominance social_volume_24h volume_24h } } `; var GetNftDocument = ` query GetNft($id: String!) { getNft(id: $id) { id name floor_price market_cap percent_change_24h volume_24h } } `; var GetNftTimeSeriesDocument = ` query GetNftTimeSeries($id: String!, $bucket: String, $interval: String, $start: UnixTimestamp, $end: UnixTimestamp) { getNftTimeSeries( id: $id bucket: $bucket interval: $interval start: $start end: $end ) { time alt_rank contributors_active contributors_created interactions market_cap posts_active posts_created sentiment social_dominance } } `; var GetNftTimeSeriesV2Document = ` query GetNftTimeSeriesV2($nft: String!, $bucket: String, $interval: String, $start: UnixTimestamp, $end: UnixTimestamp) { getNftTimeSeriesV2( nft: $nft bucket: $bucket interval: $interval start: $start end: $end ) { time alt_rank contributors_active contributors_created interactions market_cap posts_active posts_created sentiment social_dominance } } `; var GetSystemChangesDocument = ` query GetSystemChanges($start: UnixTimestamp, $end: UnixTimestamp) { getSystemChanges(start: $start, end: $end) { asset_id asset_name asset_type change description time } } `; var GetPostDetailsDocument = ` query GetPostDetails($post_type: String!, $post_id: String!) { getPostDetails(post_type: $post_type, post_id: $post_id) { type id title description extraText metrics { bookmarks favorites retweets replies views } image { src width height } video images creator_id creator_name creator_display_name creator_avatar topics categories } } `; var GetPostTimeSeriesDocument = ` query GetPostTimeSeries($post_type: String!, $post_id: String!) { getPostTimeSeries(post_type: $post_type, post_id: $post_id) { time interactions } } `; var defaultWrapper = (action, _operationName, _operationType, _variables) => action(); function getSdk(client, withWrapper = defaultWrapper) { return { SystemHealth(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: SystemHealthDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "SystemHealth", "query", variables); }, Ping(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: PingDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "Ping", "query", variables); }, Health(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: HealthDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "Health", "query", variables); }, Hello(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: HelloDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "Hello", "query", variables); }, GetTopicsList(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetTopicsListDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetTopicsList", "query", variables); }, GetTopic(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetTopicDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetTopic", "query", variables); }, GetTopicWhatsup(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetTopicWhatsupDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetTopicWhatsup", "query", variables); }, GetTopicTimeSeries(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetTopicTimeSeriesDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetTopicTimeSeries", "query", variables); }, GetTopicTimeSeriesV2(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetTopicTimeSeriesV2Document, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetTopicTimeSeriesV2", "query", variables); }, GetTopicPosts(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetTopicPostsDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetTopicPosts", "query", variables); }, GetTopicNews(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetTopicNewsDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetTopicNews", "query", variables); }, GetTopicCreators(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetTopicCreatorsDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetTopicCreators", "query", variables); }, GetCategoriesList(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetCategoriesListDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetCategoriesList", "query", variables); }, GetCategory(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetCategoryDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetCategory", "query", variables); }, GetCategoryTopics(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetCategoryTopicsDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetCategoryTopics", "query", variables); }, GetCategoryTimeSeries(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetCategoryTimeSeriesDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetCategoryTimeSeries", "query", variables); }, GetCategoryPosts(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetCategoryPostsDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetCategoryPosts", "query", variables); }, GetCategoryNews(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetCategoryNewsDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetCategoryNews", "query", variables); }, GetCategoryCreators(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetCategoryCreatorsDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetCategoryCreators", "query", variables); }, GetCreatorsList(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetCreatorsListDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetCreatorsList", "query", variables); }, GetCreator(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetCreatorDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetCreator", "query", variables); }, GetCreatorTimeSeries(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetCreatorTimeSeriesDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetCreatorTimeSeries", "query", variables); }, GetCreatorPosts(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetCreatorPostsDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetCreatorPosts", "query", variables); }, GetCoinsList(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetCoinsListDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetCoinsList", "query", variables); }, GetCoinsListV2(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetCoinsListV2Document, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetCoinsListV2", "query", variables); }, GetCoin(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetCoinDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetCoin", "query", variables); }, GetCoinMeta(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetCoinMetaDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetCoinMeta", "query", variables); }, GetCoinTimeSeries(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetCoinTimeSeriesDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetCoinTimeSeries", "query", variables); }, GetStocksList(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetStocksListDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetStocksList", "query", variables); }, GetStocksListV2(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetStocksListV2Document, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetStocksListV2", "query", variables); }, GetStock(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetStockDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetStock", "query", variables); }, GetStockTimeSeries(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetStockTimeSeriesDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetStockTimeSeries", "query", variables); }, GetNftsList(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetNftsListDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetNftsList", "query", variables); }, GetNftsListV2(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetNftsListV2Document, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetNftsListV2", "query", variables); }, GetNft(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetNftDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetNft", "query", variables); }, GetNftTimeSeries(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetNftTimeSeriesDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetNftTimeSeries", "query", variables); }, GetNftTimeSeriesV2(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetNftTimeSeriesV2Document, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetNftTimeSeriesV2", "query", variables); }, GetSystemChanges(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetSystemChangesDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetSystemChanges", "query", variables); }, GetPostDetails(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetPostDetailsDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetPostDetails", "query", variables); }, GetPostTimeSeries(variables, requestHeaders, signal) { return withWrapper((wrappedRequestHeaders) => client.request({ document: GetPostTimeSeriesDocument, variables, requestHeaders: { ...requestHeaders, ...wrappedRequestHeaders }, signal }), "GetPostTimeSeries", "query", variables); } }; } var MCPError = class extends Error { constructor(message, toolName) { super(message); this.toolName = toolName; this.name = "MCPError"; } }; var LunarCrushMCP = class { client; config; constructor(apiKeyOrConfig) { this.config = this.buildConfig(apiKeyOrConfig); } buildConfig(input) { if (typeof input === "string") { return { apiKey: input, endpoint: "https://lunarcrush.ai/sse", timeout: 3e4 }; } if (!input.apiKey) { throw new MCPError("API key required"); } return { endpoint: "https://lunarcrush.ai/sse", timeout: 3e4, ...input }; } /** * Connect to MCP server */ async connect() { try { const transport = new SSEClientTransport( new URL(`${this.config.endpoint}?key=${this.config.apiKey}`) ); this.client = new Client({ name: "lunarcrush-sdk-mcp", version: "1.0.0" }); await this.client.connect(transport); await this.authenticate(this.config.apiKey); } catch (error) { throw new MCPError(`MCP connection failed: ${error.message}`); } } /** * Execute MCP tool with error handling */ async callTool(toolName, args) { if (!this.client) { await this.connect(); } try { console.log(`\u{1F504} Calling MCP tool: ${toolName} with args:`, args); const result = await this.client.callTool({ name: toolName, arguments: args }); const parsed = this.parseResponse(result); console.log(`\u2705 ${toolName} returned ${parsed.raw.length} characters`); return parsed; } catch (error) { console.error(`\u274C Tool ${toolName} failed:`, error.message); throw new MCPError(`Tool ${toolName} failed: ${error.message}`, toolName); } } /** * Parse MCP markdown response into structured data */ parseResponse(response) { var _a, _b; const text = ((_b = (_a = response.content) == null ? void 0 : _a[0]) == null ? void 0 : _b.text) || ""; const parsed = { raw: text, tables: this.parseMarkdownTables(text), tsv: this.parseTSV(text), metadata: this.extractMetadata(text) }; return parsed; } /** * Parse markdown tables into objects */ parseMarkdownTables(text) { const tables = []; const tableRegex = /\|(.+)\|\n\|[-:\s|]+\|\n((?:\|.+\|\n?)+)/g; let match; while ((match = tableRegex.exec(text)) !== null) { const headers = match[1].split("|").map((h) => h.trim()).filter((h) => h); const rows = match[2].trim().split("\n"); const tableData = rows.map((row) => { const cells = row.split("|").map((c) => c.trim()).filter((c) => c); const rowObj = {}; headers.forEach((header, i) => { rowObj[header] = cells[i] || ""; }); return rowObj; }); tables.push(...tableData); } return tables; } /** * Parse TSV data into objects */ parseTSV(text) { const lines = text.split("\n").filter((line) => line.includes(" ")); if (lines.length < 2) return []; const headers = lines[0].split(" "); return lines.slice(1).map((line) => { const values = line.split(" "); const obj = {}; headers.forEach((header, i) => { obj[header] = values[i] || ""; }); return obj; }); } /** * Extract metadata from markdown headers and text */ extractMetadata(text) { const metadata = {}; const titleMatch = text.match(/^#\s+(.+)$/m); if (titleMatch) metadata.title = titleMatch[1]; const imageMatches = text.match(/!\[([^\]]*)\]\(([^)]+)\)/g); if (imageMatches) { metadata.images = imageMatches.map((match) => { const [, alt, src] = match.match(/!\[([^\]]*)\]\(([^)]+)\)/) || []; return { alt, src }; }); } return metadata; } // ================================================================ // 🎯 CLEAN API - Direct function calls (no .get() or .list()) // ================================================================ /** * Get topics within a category * @example await mcp.list('cryptocurrencies') */ list = (category = "") => this.callTool("List", { category }); /** * Get sorted cryptocurrencies * @example await mcp.cryptocurrencies({ filter: 'ai', limit: 10 }) */ cryptocurrencies = (options = {}) => this.callTool("Cryptocurrencies", options); /** * Get sorted stocks * @example await mcp.stocks({ sector: 'technology', limit: 5 }) */ stocks = (options = {}) => this.callTool("Stocks", options); /** * Get full topic details * @example await mcp.topics('bitcoin') */ topics = (topic) => this.callTool("Topic", { topic }); /** * Get creator insights * @example await mcp.creators('elonmusk', 'x') */ creators = (screenName, network = "") => this.callTool("Creator", { screenName, network }); /** * Get specific post details * @example await mcp.posts('1234567890', 'x') */ posts = (id, network = "") => this.callTool("Post", { id, network }); /** * Get historical time series * @example await mcp.timeSeries('bitcoin', { metrics: ['sentiment'], interval: '1w' }) */ timeSeries = (topic, options = {}) => this.callTool("Topic_Time_Series", { topic, ...options }); /** * Get popular posts for a topic * @example await mcp.topicPosts('bitcoin', { interval: '1d' }) */ topicPosts = (topic, options = {}) => this.callTool("Topic_Posts", { topic, ...options }); /** * Universal search * @example await mcp.search('AI cryptocurrency') */ search = (query) => this.callTool("Search", { query }); /** * Direct API path access * @example await mcp.fetch('/topic/bitcoin') */ fetch = (id) => this.callTool("Fetch", { id }); /** * Authenticate session */ authenticate = (apiKey) => this.callTool("Authentication", { apiKey }); /** * Close MCP connection */ async close() { if (this.client) { await this.client.close(); this.client = void 0; } } }; // src/index.ts var LunarCrushError = class extends Error { constructor(message, statusCode, statusText) { super(message); this.statusCode = statusCode; this.statusText = statusText; this.name = "LunarCrushError"; } }; var LunarCrush = class { sdk; constructor(apiKeyOrConfig) { const config = this.buildConfig(apiKeyOrConfig); const client = new GraphQLClient(config.endpoint, { headers: { Authorization: `Bearer ${config.apiKey}`, "Content-Type": "application/json" }, // Remove mode and credentials for now to test fetch: async (url, options) => { return fetch(url, { ...options, mode: "cors" // Don't include credentials in SDK calls }); } }); this.sdk = getSdk(client, this.withErrorHandling); } buildConfig(input) { if (typeof input === "string") { return { apiKey: input, endpoint: "https://lunarcrush.cryptoguard-api.workers.dev/graphql" }; } const apiKey = input == null ? void 0 : input.apiKey; if (!apiKey) throw new LunarCrushError("API key required"); return { endpoint: (input == null ? void 0 : input.endpoint) || "https://lunarcrush.cryptoguard-api.workers.dev/graphql", ...input }; } withErrorHandling = async (action) => { var _a, _b, _c, _d; try { return await action(); } catch (error) { throw new LunarCrushError( ((_c = (_b = (_a = error.response) == null ? void 0 : _a.errors) == null ? void 0 : _b[0]) == null ? void 0 : _c.message) || error.message, (_d = error.response) == null ? void 0 : _d.status ); } }; // ================================================================ // 🎯 TOPICS API - Social Sentiment & AI Analysis // ================================================================ topics = { list: () => this.sdk.GetTopicsList().then((r) => r.getTopicsList), get: (topic) => this.sdk.GetTopic({ topic }).then((r) => r.getTopic), whatsup: (topic) => this.sdk.GetTopicWhatsup({ topic }).then((r) => r.getTopicWhatsup), timeSeries: (topic, options = {}) => this.sdk.GetTopicTimeSeries({ topic, ...options }).then((r) => r.getTopicTimeSeries), timeSeriesV2: (topic, bucket) => this.sdk.GetTopicTimeSeriesV2({ topic, bucket }).then((r) => r.getTopicTimeSeriesV2), posts: (topic, options = {}) => this.sdk.GetTopicPosts({ topic, ...options }).then((r) => r.getTopicPosts), news: (topic) => this.sdk.GetTopicNews({ topic }).then((r) => r.getTopicNews), creators: (topic) => this.sdk.GetTopicCreators({ topic }).then((r) => r.getTopicCreators) }; // ================================================================ // 📊 CATEGORIES API - Trend Analysis & Topic Aggregation // ================================================================ categories = { list: () => this.sdk.GetCategoriesList().then((r) => r.getCategoriesList), get: (category) => this.sdk.GetCategory({ category }).then((r) => r.getCategory), topics: (category) => this.sdk.GetCategoryTopics({ category }).then((r) => r.getCategoryTopics), timeSeries: (category, options = {}) => this.sdk.GetCategoryTimeSeries({ category, ...options }).then((r) => r.getCategoryTimeSeries), posts: (category, options = {}) => this.sdk.GetCategoryPosts({ category, ...options }).then((r) => r.getCategoryPosts), news: (category) => this.sdk.GetCategoryNews({ category }).then((r) => r.getCategoryNews), creators: (category) => this.sdk.GetCategoryCreators({ category }).then((r) => r.getCategoryCreators) }; // ================================================================ // 👑 CREATORS API - Influencer Analysis & Topic Influence // ================================================================ creators = { list: () => this.sdk.GetCreatorsList().then((r) => r.getCreatorsList), get: (network, id) => this.sdk.GetCreator({ network, id }).then((r) => r.getCreator), timeSeries: (network, id, options = {}) => this.sdk.GetCreatorTimeSeries({ network, id, ...options }).then((r) => r.getCreatorTimeSeries), posts: (network, id, options = {}) => this.sdk.GetCreatorPosts({ network, id, ...options }).then((r) => r.getCreatorPosts) }; // ================================================================ // 💰 COINS API - Crypto Social + Market Data Fusion // ================================================================ coins = { list: (options = {}) => this.sdk.GetCoinsList(options).then((r) => r.getCoinsList), listV2: (options = {}) => this.sdk.GetCoinsListV2(options).then((r) => r.getCoinsListV2), get: (coin) => this.sdk.GetCoin({ coin }).then((r) => r.getCoin), meta: (coin) => this.sdk.GetCoinMeta({ coin }).then((r) => r.getCoinMeta), timeSeries: (coin, options = {}) => this.sdk.GetCoinTimeSeries({ coin, ...options }).then((r) => r.getCoinTimeSeries) }; // ================================================================ // 📈 STOCKS API - Stock Social Sentiment Analysis // ================================================================ stocks = { list: () => this.sdk.GetStocksList().then((r) => r.getStocksList), listV2: (options = {}) => this.sdk.GetStocksListV2(options).then((r) => r.getStocksListV2), get: (stock) => this.sdk.GetStock({ stock }).then((r) => r.getStock), timeSeries: (stock, options = {}) => this.sdk.GetStockTimeSeries({ stock, ...options }).then((r) => r.getStockTimeSeries) }; // ================================================================ // 🖼️ NFTS API - NFT Collection Social Tracking // ================================================================ nfts = { list: (options = {}) => this.sdk.GetNftsList(options).then((r) => r.getNftsList), listV2: (options = {}) => this.sdk.GetNftsListV2(options).then((r) => r.getNftsListV2), get: (id) => this.sdk.GetNft({ id }).then((r) => r.getNft), timeSeries: (id, options = {}) => this.sdk.GetNftTimeSeries({ id, ...options }).then((r) => r.getNftTimeSeries), timeSeriesV2: (nft, options = {}) => this.sdk.GetNftTimeSeriesV2({ nft, ...options }).then((r) => r.getNftTimeSeriesV2) }; // ================================================================ // 📝 POSTS API - Viral Content Analysis // ================================================================ posts = { details: (post_type, post_id) => this.sdk.GetPostDetails({ post_type, post_id }).then((r) => r.getPostDetails), timeSeries: (post_type, post_id) => this.sdk.GetPostTimeSeries({ post_type, post_id }).then((r) => r.getPostTimeSeries) }; // ================================================================ // 🎯 SYSTEM API - Health & Monitoring // ================================================================ system = { health: () => this.sdk.SystemHealth().then((r) => r.systemHealth), ping: () => this.sdk.Ping().then((r) => r.ping), hello: () => this.sdk.Hello().then((r) => r.hello), changes: (options = {}) => this.sdk.GetSystemChanges(options).then((r) => r.getSystemChanges) }; // ================================================================ // 🔧 USER API - Preferences (Demo/Testing Only) // ================================================================ // user = { // The following methods are commented out because they do not exist in the SDK // updatePreferences: (input: { // theme?: string; // currency?: string; // notifications?: boolean; // favoriteTopics?: string[]; // }) => // this.sdk // .UpdateUserPreferences({ input }) // .then((r: any) => r.updateUserPreferences), // createTopic: (input: { // topic: string; // category: string; // description?: string; // }) => this.sdk.CreateTopic({ input }).then((r: any) => r.createTopic), // }; }; function createLunarCrush(apiKeyOrConfig) { return new LunarCrush(apiKeyOrConfig); } async function createLunarCrushMCP(apiKeyOrConfig) { const client = new LunarCrushMCP(apiKeyOrConfig); await client.connect(); return client; } var index_default = LunarCrush; export { LunarCrush, LunarCrushError, LunarCrushMCP, MCPError, createLunarCrush, createLunarCrushMCP, index_default as default }; //# sourceMappingURL=index.js.map //# sourceMappingURL=index.js.map