mcp-crypto-price 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +146 -0
- package/dist/config/index.js +6 -0
- package/dist/index.js +103 -0
- package/dist/services/__tests__/coincap.test.js +107 -0
- package/dist/services/__tests__/formatters.test.js +113 -0
- package/dist/services/coincap.js +60 -0
- package/dist/services/formatters.js +51 -0
- package/dist/tools/historical.js +35 -0
- package/dist/tools/index.js +3 -0
- package/dist/tools/market.js +31 -0
- package/dist/tools/price.js +30 -0
- package/dist/types/index.js +1 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Tracey Russell
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# Crypto Price & Market Analysis MCP Server
|
|
2
|
+
|
|
3
|
+
A Model Context Protocol (MCP) server that provides comprehensive cryptocurrency analysis using the CoinCap API. This server offers real-time price data, market analysis, and historical trends through an easy-to-use interface.
|
|
4
|
+
|
|
5
|
+
## 🚀 Quick Start
|
|
6
|
+
|
|
7
|
+
First, clone and build the repository:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
git clone https://github.com/truss44/mcp-crypto-price.git
|
|
11
|
+
cd mcp-crypto-price
|
|
12
|
+
npm install
|
|
13
|
+
npm run build
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Then add this configuration to your Claude Desktop config file:
|
|
17
|
+
|
|
18
|
+
- **MacOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
19
|
+
- **Windows**: `%APPDATA%/Claude/claude_desktop_config.json`
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"mcpServers": {
|
|
24
|
+
"mcp-crypto-price": {
|
|
25
|
+
"command": "node",
|
|
26
|
+
"args": ["/ABSOLUTE/PATH/TO/mcp-crypto-price/build/index.js"]
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Prerequisites
|
|
33
|
+
|
|
34
|
+
- Node.js 18+
|
|
35
|
+
- npm
|
|
36
|
+
- Claude for Desktop or another MCP client
|
|
37
|
+
|
|
38
|
+
Then, launch Claude Desktop and you're ready to go!
|
|
39
|
+
|
|
40
|
+
## Sample Prompts
|
|
41
|
+
|
|
42
|
+
- "What's the current price of Bitcoin?"
|
|
43
|
+
- "Show me market analysis for ETH"
|
|
44
|
+
- "Give me the 7-day price history for DOGE"
|
|
45
|
+
- "What are the top exchanges trading BTC?"
|
|
46
|
+
- "Show me the price trends for SOL with 1-hour intervals"
|
|
47
|
+
|
|
48
|
+
## Tools
|
|
49
|
+
|
|
50
|
+
#### get-crypto-price
|
|
51
|
+
|
|
52
|
+
Gets current price and 24h stats for any cryptocurrency, including:
|
|
53
|
+
- Current price in USD
|
|
54
|
+
- 24-hour price change
|
|
55
|
+
- Trading volume
|
|
56
|
+
- Market cap
|
|
57
|
+
- Market rank
|
|
58
|
+
|
|
59
|
+
#### get-market-analysis
|
|
60
|
+
|
|
61
|
+
Provides detailed market analysis including:
|
|
62
|
+
- Top 5 exchanges by volume
|
|
63
|
+
- Price variations across exchanges
|
|
64
|
+
- Volume distribution analysis
|
|
65
|
+
- VWAP (Volume Weighted Average Price)
|
|
66
|
+
|
|
67
|
+
#### get-historical-analysis
|
|
68
|
+
|
|
69
|
+
Analyzes historical price data with:
|
|
70
|
+
- Customizable time intervals (5min to 1 day)
|
|
71
|
+
- Support for up to 30 days of historical data
|
|
72
|
+
- Price trend analysis
|
|
73
|
+
- Volatility metrics
|
|
74
|
+
- High/low price ranges
|
|
75
|
+
|
|
76
|
+
## Development - local build
|
|
77
|
+
|
|
78
|
+
To build it locally:
|
|
79
|
+
|
|
80
|
+
- **MacOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
81
|
+
- **Windows**: `%APPDATA%/Claude/claude_desktop_config.json`
|
|
82
|
+
|
|
83
|
+
```json
|
|
84
|
+
{
|
|
85
|
+
"mcpServers": {
|
|
86
|
+
"mcp-crypto-price": {
|
|
87
|
+
"command": "node",
|
|
88
|
+
"args": ["/ABSOLUTE/PATH/TO/mcp-crypto-price/build/index.js"]
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Development
|
|
95
|
+
|
|
96
|
+
Install dependencies:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
npm install
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Build the server:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
npm run build
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
For development with auto-rebuild:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
npm run watch
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Run test suite:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
npm test
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Optional: CoinCap API Key
|
|
121
|
+
|
|
122
|
+
While not required, you can add an API key for higher rate limits:
|
|
123
|
+
|
|
124
|
+
```json
|
|
125
|
+
{
|
|
126
|
+
"mcpServers": {
|
|
127
|
+
"mcp-crypto-price": {
|
|
128
|
+
"command": "node",
|
|
129
|
+
"args": [
|
|
130
|
+
"/ABSOLUTE/PATH/TO/mcp-crypto-price/build/index.js"
|
|
131
|
+
],
|
|
132
|
+
"env": {
|
|
133
|
+
"COINCAP_API_KEY": "YOUR_API_KEY_HERE"
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Project Inspiration
|
|
141
|
+
|
|
142
|
+
This project was inspired by Alex Andru's [coincap-mcp](https://github.com/QuantGeekDev/coincap-mcp) project.
|
|
143
|
+
|
|
144
|
+
## 📜 License
|
|
145
|
+
|
|
146
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
5
|
+
import { SERVER_CONFIG } from './config/index.js';
|
|
6
|
+
import { handleGetPrice, handleGetMarketAnalysis, handleGetHistoricalAnalysis } from './tools/index.js';
|
|
7
|
+
// Create server instance
|
|
8
|
+
const server = new Server(SERVER_CONFIG, {
|
|
9
|
+
capabilities: {
|
|
10
|
+
tools: {},
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
// List available tools
|
|
14
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
15
|
+
return {
|
|
16
|
+
tools: [
|
|
17
|
+
{
|
|
18
|
+
name: "get-crypto-price",
|
|
19
|
+
description: "Get current price and 24h stats for a cryptocurrency",
|
|
20
|
+
inputSchema: {
|
|
21
|
+
type: "object",
|
|
22
|
+
properties: {
|
|
23
|
+
symbol: {
|
|
24
|
+
type: "string",
|
|
25
|
+
description: "Cryptocurrency symbol (e.g., BTC, ETH)",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
required: ["symbol"],
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "get-market-analysis",
|
|
33
|
+
description: "Get detailed market analysis including top exchanges and volume distribution",
|
|
34
|
+
inputSchema: {
|
|
35
|
+
type: "object",
|
|
36
|
+
properties: {
|
|
37
|
+
symbol: {
|
|
38
|
+
type: "string",
|
|
39
|
+
description: "Cryptocurrency symbol (e.g., BTC, ETH)",
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
required: ["symbol"],
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: "get-historical-analysis",
|
|
47
|
+
description: "Get historical price analysis with customizable timeframe",
|
|
48
|
+
inputSchema: {
|
|
49
|
+
type: "object",
|
|
50
|
+
properties: {
|
|
51
|
+
symbol: {
|
|
52
|
+
type: "string",
|
|
53
|
+
description: "Cryptocurrency symbol (e.g., BTC, ETH)",
|
|
54
|
+
},
|
|
55
|
+
interval: {
|
|
56
|
+
type: "string",
|
|
57
|
+
description: "Time interval (m5, m15, m30, h1, h2, h6, h12, d1)",
|
|
58
|
+
default: "h1",
|
|
59
|
+
},
|
|
60
|
+
days: {
|
|
61
|
+
type: "number",
|
|
62
|
+
description: "Number of days to analyze (1-30)",
|
|
63
|
+
default: 7,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
required: ["symbol"],
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
// Handle execution
|
|
73
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
74
|
+
const { name, arguments: args } = request.params;
|
|
75
|
+
try {
|
|
76
|
+
switch (name) {
|
|
77
|
+
case "get-crypto-price":
|
|
78
|
+
return await handleGetPrice(args);
|
|
79
|
+
case "get-market-analysis":
|
|
80
|
+
return await handleGetMarketAnalysis(args);
|
|
81
|
+
case "get-historical-analysis":
|
|
82
|
+
return await handleGetHistoricalAnalysis(args);
|
|
83
|
+
default:
|
|
84
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
if (error instanceof Error) {
|
|
89
|
+
throw new Error(`Tool execution failed: ${error.message}`);
|
|
90
|
+
}
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
// Start the server
|
|
95
|
+
async function main() {
|
|
96
|
+
const transport = new StdioServerTransport();
|
|
97
|
+
await server.connect(transport);
|
|
98
|
+
console.error("Crypto Price MCP Server running on stdio");
|
|
99
|
+
}
|
|
100
|
+
main().catch((error) => {
|
|
101
|
+
console.error("Fatal error in main():", error);
|
|
102
|
+
process.exit(1);
|
|
103
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { jest } from '@jest/globals';
|
|
2
|
+
import { getAssets, getMarkets, getHistoricalData, clearCache } from '../coincap.js';
|
|
3
|
+
// Mock global fetch
|
|
4
|
+
const mockFetch = jest.fn();
|
|
5
|
+
global.fetch = mockFetch;
|
|
6
|
+
// Suppress console.error during tests
|
|
7
|
+
console.error = jest.fn();
|
|
8
|
+
describe('CoinCap Service', () => {
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
jest.clearAllMocks();
|
|
11
|
+
mockFetch.mockReset();
|
|
12
|
+
clearCache();
|
|
13
|
+
});
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
clearCache();
|
|
16
|
+
});
|
|
17
|
+
describe('getAssets', () => {
|
|
18
|
+
it('should fetch assets successfully', async () => {
|
|
19
|
+
const mockResponse = {
|
|
20
|
+
data: [
|
|
21
|
+
{
|
|
22
|
+
id: 'bitcoin',
|
|
23
|
+
rank: '1',
|
|
24
|
+
symbol: 'BTC',
|
|
25
|
+
name: 'Bitcoin',
|
|
26
|
+
priceUsd: '50000.00'
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
};
|
|
30
|
+
mockFetch.mockImplementationOnce(() => Promise.resolve({
|
|
31
|
+
ok: true,
|
|
32
|
+
json: () => Promise.resolve(mockResponse)
|
|
33
|
+
}));
|
|
34
|
+
const result = await getAssets();
|
|
35
|
+
expect(result).toEqual(mockResponse);
|
|
36
|
+
expect(mockFetch).toHaveBeenCalledWith('https://api.coincap.io/v2/assets', expect.any(Object));
|
|
37
|
+
});
|
|
38
|
+
it('should handle fetch errors', async () => {
|
|
39
|
+
mockFetch.mockImplementationOnce(() => Promise.reject(new Error('Network error')));
|
|
40
|
+
const result = await getAssets();
|
|
41
|
+
expect(result).toBeNull();
|
|
42
|
+
expect(console.error).toHaveBeenCalled();
|
|
43
|
+
});
|
|
44
|
+
it('should handle non-ok response', async () => {
|
|
45
|
+
mockFetch.mockImplementationOnce(() => Promise.resolve({
|
|
46
|
+
ok: false,
|
|
47
|
+
status: 500,
|
|
48
|
+
statusText: 'Internal Server Error'
|
|
49
|
+
}));
|
|
50
|
+
const result = await getAssets();
|
|
51
|
+
expect(result).toBeNull();
|
|
52
|
+
expect(console.error).toHaveBeenCalled();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
describe('getMarkets', () => {
|
|
56
|
+
it('should fetch markets successfully', async () => {
|
|
57
|
+
const mockResponse = {
|
|
58
|
+
data: [
|
|
59
|
+
{
|
|
60
|
+
exchangeId: 'binance',
|
|
61
|
+
baseSymbol: 'BTC',
|
|
62
|
+
priceUsd: '50000.00'
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
};
|
|
66
|
+
mockFetch.mockImplementationOnce(() => Promise.resolve({
|
|
67
|
+
ok: true,
|
|
68
|
+
json: () => Promise.resolve(mockResponse)
|
|
69
|
+
}));
|
|
70
|
+
const result = await getMarkets('bitcoin');
|
|
71
|
+
expect(result).toEqual(mockResponse);
|
|
72
|
+
expect(mockFetch).toHaveBeenCalledWith('https://api.coincap.io/v2/assets/bitcoin/markets', expect.any(Object));
|
|
73
|
+
});
|
|
74
|
+
it('should handle fetch errors for markets', async () => {
|
|
75
|
+
mockFetch.mockImplementationOnce(() => Promise.reject(new Error('Network error')));
|
|
76
|
+
const result = await getMarkets('bitcoin');
|
|
77
|
+
expect(result).toBeNull();
|
|
78
|
+
expect(console.error).toHaveBeenCalled();
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
describe('getHistoricalData', () => {
|
|
82
|
+
it('should fetch historical data successfully', async () => {
|
|
83
|
+
const mockResponse = {
|
|
84
|
+
data: [
|
|
85
|
+
{
|
|
86
|
+
time: 1609459200000,
|
|
87
|
+
priceUsd: '45000.00',
|
|
88
|
+
date: '2021-01-01'
|
|
89
|
+
}
|
|
90
|
+
]
|
|
91
|
+
};
|
|
92
|
+
mockFetch.mockImplementationOnce(() => Promise.resolve({
|
|
93
|
+
ok: true,
|
|
94
|
+
json: () => Promise.resolve(mockResponse)
|
|
95
|
+
}));
|
|
96
|
+
const result = await getHistoricalData('bitcoin', 'h1', 1609459200000, 1609545600000);
|
|
97
|
+
expect(result).toEqual(mockResponse);
|
|
98
|
+
expect(mockFetch).toHaveBeenCalledWith(expect.stringContaining('https://api.coincap.io/v2/assets/bitcoin/history'), expect.any(Object));
|
|
99
|
+
});
|
|
100
|
+
it('should handle fetch errors for historical data', async () => {
|
|
101
|
+
mockFetch.mockImplementationOnce(() => Promise.reject(new Error('Network error')));
|
|
102
|
+
const result = await getHistoricalData('bitcoin', 'h1', 1609459200000, 1609545600000);
|
|
103
|
+
expect(result).toBeNull();
|
|
104
|
+
expect(console.error).toHaveBeenCalled();
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
});
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { formatPriceInfo, formatMarketAnalysis, formatHistoricalAnalysis } from '../formatters.js';
|
|
2
|
+
describe('Formatters', () => {
|
|
3
|
+
describe('formatPriceInfo', () => {
|
|
4
|
+
it('should format price info correctly', () => {
|
|
5
|
+
const asset = {
|
|
6
|
+
id: 'bitcoin',
|
|
7
|
+
rank: '1',
|
|
8
|
+
symbol: 'BTC',
|
|
9
|
+
name: 'Bitcoin',
|
|
10
|
+
priceUsd: '50000.00',
|
|
11
|
+
changePercent24Hr: '5.25',
|
|
12
|
+
volumeUsd24Hr: '30000000000',
|
|
13
|
+
marketCapUsd: '1000000000000',
|
|
14
|
+
supply: '19000000',
|
|
15
|
+
maxSupply: '21000000',
|
|
16
|
+
vwap24Hr: '49500.00'
|
|
17
|
+
};
|
|
18
|
+
const formatted = formatPriceInfo(asset);
|
|
19
|
+
expect(formatted).toContain('Bitcoin (BTC)');
|
|
20
|
+
expect(formatted).toContain('Price: $50000.00');
|
|
21
|
+
expect(formatted).toContain('24h Change: 5.25%');
|
|
22
|
+
expect(formatted).toContain('24h Volume: $30000.00M');
|
|
23
|
+
expect(formatted).toContain('Market Cap: $1000.00B');
|
|
24
|
+
expect(formatted).toContain('Rank: #1');
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
describe('formatMarketAnalysis', () => {
|
|
28
|
+
it('should format market analysis correctly', () => {
|
|
29
|
+
const asset = {
|
|
30
|
+
id: 'bitcoin',
|
|
31
|
+
rank: '1',
|
|
32
|
+
symbol: 'BTC',
|
|
33
|
+
name: 'Bitcoin',
|
|
34
|
+
priceUsd: '50000.00',
|
|
35
|
+
changePercent24Hr: '5.25',
|
|
36
|
+
volumeUsd24Hr: '30000000000',
|
|
37
|
+
marketCapUsd: '1000000000000',
|
|
38
|
+
supply: '19000000',
|
|
39
|
+
maxSupply: '21000000',
|
|
40
|
+
vwap24Hr: '49500.00'
|
|
41
|
+
};
|
|
42
|
+
const markets = [
|
|
43
|
+
{
|
|
44
|
+
exchangeId: 'binance',
|
|
45
|
+
baseSymbol: 'BTC',
|
|
46
|
+
quoteSymbol: 'USD',
|
|
47
|
+
priceUsd: '50100.00',
|
|
48
|
+
volumeUsd24Hr: '10000000000',
|
|
49
|
+
percentExchangeVolume: '33.33'
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
exchangeId: 'coinbase',
|
|
53
|
+
baseSymbol: 'BTC',
|
|
54
|
+
quoteSymbol: 'USD',
|
|
55
|
+
priceUsd: '50000.00',
|
|
56
|
+
volumeUsd24Hr: '8000000000',
|
|
57
|
+
percentExchangeVolume: '26.67'
|
|
58
|
+
}
|
|
59
|
+
];
|
|
60
|
+
const formatted = formatMarketAnalysis(asset, markets);
|
|
61
|
+
expect(formatted).toContain('Market Analysis for Bitcoin (BTC)');
|
|
62
|
+
expect(formatted).toContain('Current Price: $50000.00');
|
|
63
|
+
expect(formatted).toContain('24h Volume: $30000.00M');
|
|
64
|
+
expect(formatted).toContain('VWAP (24h): $49500.00');
|
|
65
|
+
expect(formatted).toContain('binance: $50100.00');
|
|
66
|
+
expect(formatted).toContain('coinbase: $50000.00');
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
describe('formatHistoricalAnalysis', () => {
|
|
70
|
+
it('should format historical analysis correctly', () => {
|
|
71
|
+
const asset = {
|
|
72
|
+
id: 'bitcoin',
|
|
73
|
+
rank: '1',
|
|
74
|
+
symbol: 'BTC',
|
|
75
|
+
name: 'Bitcoin',
|
|
76
|
+
priceUsd: '50000.00',
|
|
77
|
+
changePercent24Hr: '5.25',
|
|
78
|
+
volumeUsd24Hr: '30000000000',
|
|
79
|
+
marketCapUsd: '1000000000000',
|
|
80
|
+
supply: '19000000',
|
|
81
|
+
maxSupply: '21000000',
|
|
82
|
+
vwap24Hr: '49500.00'
|
|
83
|
+
};
|
|
84
|
+
const history = [
|
|
85
|
+
{
|
|
86
|
+
time: 1609459200000,
|
|
87
|
+
priceUsd: '45000.00',
|
|
88
|
+
circulatingSupply: '18500000',
|
|
89
|
+
date: '2021-01-01'
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
time: 1609545600000,
|
|
93
|
+
priceUsd: '48000.00',
|
|
94
|
+
circulatingSupply: '18500000',
|
|
95
|
+
date: '2021-01-02'
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
time: 1609632000000,
|
|
99
|
+
priceUsd: '50000.00',
|
|
100
|
+
circulatingSupply: '18500000',
|
|
101
|
+
date: '2021-01-03'
|
|
102
|
+
}
|
|
103
|
+
];
|
|
104
|
+
const formatted = formatHistoricalAnalysis(asset, history);
|
|
105
|
+
expect(formatted).toContain('Historical Analysis for Bitcoin (BTC)');
|
|
106
|
+
expect(formatted).toContain('Period High: $50000.00');
|
|
107
|
+
expect(formatted).toContain('Period Low: $45000.00');
|
|
108
|
+
expect(formatted).toContain('Price Change: 11.11%');
|
|
109
|
+
expect(formatted).toContain('Current Price: $50000.00');
|
|
110
|
+
expect(formatted).toContain('Starting Price: $45000.00');
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { COINCAP_API_BASE, CACHE_TTL } from '../config/index.js';
|
|
2
|
+
const cache = new Map();
|
|
3
|
+
// Expose cache clear function for testing
|
|
4
|
+
export function clearCache() {
|
|
5
|
+
cache.clear();
|
|
6
|
+
}
|
|
7
|
+
function getCachedData(key) {
|
|
8
|
+
const entry = cache.get(key);
|
|
9
|
+
if (!entry)
|
|
10
|
+
return null;
|
|
11
|
+
const now = Date.now();
|
|
12
|
+
if (now - entry.timestamp > CACHE_TTL) {
|
|
13
|
+
cache.delete(key);
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
return entry.data;
|
|
17
|
+
}
|
|
18
|
+
function setCacheData(key, data) {
|
|
19
|
+
cache.set(key, {
|
|
20
|
+
data,
|
|
21
|
+
timestamp: Date.now()
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
async function makeCoinCapRequest(endpoint) {
|
|
25
|
+
// Check cache first
|
|
26
|
+
const cachedData = getCachedData(endpoint);
|
|
27
|
+
if (cachedData) {
|
|
28
|
+
return cachedData;
|
|
29
|
+
}
|
|
30
|
+
const headers = {};
|
|
31
|
+
const apiKey = process.env.COINCAP_API_KEY;
|
|
32
|
+
if (apiKey) {
|
|
33
|
+
headers['Authorization'] = `Bearer ${apiKey}`;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const response = await fetch(`${COINCAP_API_BASE}${endpoint}`, {
|
|
37
|
+
headers
|
|
38
|
+
});
|
|
39
|
+
if (!response.ok) {
|
|
40
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
41
|
+
}
|
|
42
|
+
const data = await response.json();
|
|
43
|
+
// Cache the successful response
|
|
44
|
+
setCacheData(endpoint, data);
|
|
45
|
+
return data;
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
console.error("Error making CoinCap request:", error);
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export async function getAssets() {
|
|
53
|
+
return makeCoinCapRequest('/assets');
|
|
54
|
+
}
|
|
55
|
+
export async function getMarkets(assetId) {
|
|
56
|
+
return makeCoinCapRequest(`/assets/${assetId}/markets`);
|
|
57
|
+
}
|
|
58
|
+
export async function getHistoricalData(assetId, interval, start, end) {
|
|
59
|
+
return makeCoinCapRequest(`/assets/${assetId}/history?interval=${interval}&start=${start}&end=${end}`);
|
|
60
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export function formatPriceInfo(asset) {
|
|
2
|
+
const price = parseFloat(asset.priceUsd).toFixed(2);
|
|
3
|
+
const change = parseFloat(asset.changePercent24Hr).toFixed(2);
|
|
4
|
+
const volume = (parseFloat(asset.volumeUsd24Hr) / 1000000).toFixed(2);
|
|
5
|
+
const marketCap = (parseFloat(asset.marketCapUsd) / 1000000000).toFixed(2);
|
|
6
|
+
return [
|
|
7
|
+
`${asset.name} (${asset.symbol})`,
|
|
8
|
+
`Price: $${price}`,
|
|
9
|
+
`24h Change: ${change}%`,
|
|
10
|
+
`24h Volume: $${volume}M`,
|
|
11
|
+
`Market Cap: $${marketCap}B`,
|
|
12
|
+
`Rank: #${asset.rank}`,
|
|
13
|
+
].join('\n');
|
|
14
|
+
}
|
|
15
|
+
export function formatMarketAnalysis(asset, markets) {
|
|
16
|
+
const totalVolume = markets.reduce((sum, market) => sum + parseFloat(market.volumeUsd24Hr), 0);
|
|
17
|
+
const topMarkets = markets
|
|
18
|
+
.sort((a, b) => parseFloat(b.volumeUsd24Hr) - parseFloat(a.volumeUsd24Hr))
|
|
19
|
+
.slice(0, 5);
|
|
20
|
+
const marketInfo = topMarkets.map(market => {
|
|
21
|
+
const volumePercent = (parseFloat(market.volumeUsd24Hr) / totalVolume * 100).toFixed(2);
|
|
22
|
+
const volume = (parseFloat(market.volumeUsd24Hr) / 1000000).toFixed(2);
|
|
23
|
+
return `${market.exchangeId}: $${market.priceUsd} (Volume: $${volume}M, ${volumePercent}% of total)`;
|
|
24
|
+
}).join('\n');
|
|
25
|
+
return [
|
|
26
|
+
`Market Analysis for ${asset.name} (${asset.symbol})`,
|
|
27
|
+
`Current Price: $${parseFloat(asset.priceUsd).toFixed(2)}`,
|
|
28
|
+
`24h Volume: $${(parseFloat(asset.volumeUsd24Hr) / 1000000).toFixed(2)}M`,
|
|
29
|
+
`VWAP (24h): $${parseFloat(asset.vwap24Hr || '0').toFixed(2)}`,
|
|
30
|
+
'\nTop 5 Markets by Volume:',
|
|
31
|
+
marketInfo
|
|
32
|
+
].join('\n');
|
|
33
|
+
}
|
|
34
|
+
export function formatHistoricalAnalysis(asset, history) {
|
|
35
|
+
const currentPrice = parseFloat(asset.priceUsd);
|
|
36
|
+
const oldestPrice = parseFloat(history[0].priceUsd);
|
|
37
|
+
const highestPrice = Math.max(...history.map(h => parseFloat(h.priceUsd)));
|
|
38
|
+
const lowestPrice = Math.min(...history.map(h => parseFloat(h.priceUsd)));
|
|
39
|
+
const priceChange = ((currentPrice - oldestPrice) / oldestPrice * 100).toFixed(2);
|
|
40
|
+
return [
|
|
41
|
+
`Historical Analysis for ${asset.name} (${asset.symbol})`,
|
|
42
|
+
`Period High: $${highestPrice.toFixed(2)}`,
|
|
43
|
+
`Period Low: $${lowestPrice.toFixed(2)}`,
|
|
44
|
+
`Price Change: ${priceChange}%`,
|
|
45
|
+
`Current Price: $${currentPrice.toFixed(2)}`,
|
|
46
|
+
`Starting Price: $${oldestPrice.toFixed(2)}`,
|
|
47
|
+
'\nVolatility Analysis:',
|
|
48
|
+
`Price Range: $${(highestPrice - lowestPrice).toFixed(2)}`,
|
|
49
|
+
`Range Percentage: ${((highestPrice - lowestPrice) / lowestPrice * 100).toFixed(2)}%`
|
|
50
|
+
].join('\n');
|
|
51
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { getAssets, getHistoricalData } from '../services/coincap.js';
|
|
3
|
+
import { formatHistoricalAnalysis } from '../services/formatters.js';
|
|
4
|
+
export const GetHistoricalAnalysisSchema = z.object({
|
|
5
|
+
symbol: z.string().min(1),
|
|
6
|
+
interval: z.enum(['m5', 'm15', 'm30', 'h1', 'h2', 'h6', 'h12', 'd1']).default('h1'),
|
|
7
|
+
days: z.number().min(1).max(30).default(7),
|
|
8
|
+
});
|
|
9
|
+
export async function handleGetHistoricalAnalysis(args) {
|
|
10
|
+
const { symbol, interval, days } = GetHistoricalAnalysisSchema.parse(args);
|
|
11
|
+
const upperSymbol = symbol.toUpperCase();
|
|
12
|
+
const assetsData = await getAssets();
|
|
13
|
+
if (!assetsData) {
|
|
14
|
+
return {
|
|
15
|
+
content: [{ type: "text", text: "Failed to retrieve cryptocurrency data" }],
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const asset = assetsData.data.find((a) => a.symbol.toUpperCase() === upperSymbol);
|
|
19
|
+
if (!asset) {
|
|
20
|
+
return {
|
|
21
|
+
content: [{ type: "text", text: `Could not find cryptocurrency with symbol ${upperSymbol}` }],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const end = Date.now();
|
|
25
|
+
const start = end - (days * 24 * 60 * 60 * 1000);
|
|
26
|
+
const historyData = await getHistoricalData(asset.id, interval, start, end);
|
|
27
|
+
if (!historyData || !historyData.data.length) {
|
|
28
|
+
return {
|
|
29
|
+
content: [{ type: "text", text: "Failed to retrieve historical data" }],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
content: [{ type: "text", text: formatHistoricalAnalysis(asset, historyData.data) }],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { getAssets, getMarkets } from '../services/coincap.js';
|
|
3
|
+
import { formatMarketAnalysis } from '../services/formatters.js';
|
|
4
|
+
export const GetMarketAnalysisSchema = z.object({
|
|
5
|
+
symbol: z.string().min(1),
|
|
6
|
+
});
|
|
7
|
+
export async function handleGetMarketAnalysis(args) {
|
|
8
|
+
const { symbol } = GetMarketAnalysisSchema.parse(args);
|
|
9
|
+
const upperSymbol = symbol.toUpperCase();
|
|
10
|
+
const assetsData = await getAssets();
|
|
11
|
+
if (!assetsData) {
|
|
12
|
+
return {
|
|
13
|
+
content: [{ type: "text", text: "Failed to retrieve cryptocurrency data" }],
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const asset = assetsData.data.find((a) => a.symbol.toUpperCase() === upperSymbol);
|
|
17
|
+
if (!asset) {
|
|
18
|
+
return {
|
|
19
|
+
content: [{ type: "text", text: `Could not find cryptocurrency with symbol ${upperSymbol}` }],
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const marketsData = await getMarkets(asset.id);
|
|
23
|
+
if (!marketsData) {
|
|
24
|
+
return {
|
|
25
|
+
content: [{ type: "text", text: "Failed to retrieve market data" }],
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
content: [{ type: "text", text: formatMarketAnalysis(asset, marketsData.data) }],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { getAssets } from '../services/coincap.js';
|
|
3
|
+
import { formatPriceInfo } from '../services/formatters.js';
|
|
4
|
+
export const GetPriceArgumentsSchema = z.object({
|
|
5
|
+
symbol: z.string().min(1),
|
|
6
|
+
});
|
|
7
|
+
export async function handleGetPrice(args) {
|
|
8
|
+
const { symbol } = GetPriceArgumentsSchema.parse(args);
|
|
9
|
+
const upperSymbol = symbol.toUpperCase();
|
|
10
|
+
const assetsData = await getAssets();
|
|
11
|
+
if (!assetsData) {
|
|
12
|
+
return {
|
|
13
|
+
content: [{ type: "text", text: "Failed to retrieve cryptocurrency data" }],
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const asset = assetsData.data.find((a) => a.symbol.toUpperCase() === upperSymbol);
|
|
17
|
+
if (!asset) {
|
|
18
|
+
return {
|
|
19
|
+
content: [
|
|
20
|
+
{
|
|
21
|
+
type: "text",
|
|
22
|
+
text: `Could not find cryptocurrency with symbol ${upperSymbol}`,
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
content: [{ type: "text", text: formatPriceInfo(asset) }],
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mcp-crypto-price",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "A Model Context Protocol (MCP) server that provides real-time cryptocurrency data and analysis through CoinCap's API. Features include price tracking, market analysis, and historical trends.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Tracey Russell"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"bin": {
|
|
11
|
+
"mcp-crypto-price": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"dist/**/*"
|
|
16
|
+
],
|
|
17
|
+
"main": "./dist/index.js",
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc && shx chmod +x dist/*.js",
|
|
20
|
+
"prepare": "npm run build",
|
|
21
|
+
"start": "node dist/index.js",
|
|
22
|
+
"watch": "tsc -w",
|
|
23
|
+
"inspector": "npx @modelcontextprotocol/inspector dist/index.js",
|
|
24
|
+
"test": "jest",
|
|
25
|
+
"test:coverage": "jest --coverage"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@modelcontextprotocol/sdk": "^1.4.1",
|
|
29
|
+
"zod": "^3.22.4"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/jest": "^29.5.14",
|
|
33
|
+
"@types/node": "^20.11.0",
|
|
34
|
+
"jest": "^29.7.0",
|
|
35
|
+
"shx": "^0.3.4",
|
|
36
|
+
"ts-jest": "^29.2.5",
|
|
37
|
+
"typescript": "^5.3.3"
|
|
38
|
+
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=18.0.0"
|
|
41
|
+
},
|
|
42
|
+
"keywords": [
|
|
43
|
+
"mcp",
|
|
44
|
+
"modelcontextprotocol",
|
|
45
|
+
"claude",
|
|
46
|
+
"crypto",
|
|
47
|
+
"cryptocurrency",
|
|
48
|
+
"coincap",
|
|
49
|
+
"price",
|
|
50
|
+
"market-analysis",
|
|
51
|
+
"trading",
|
|
52
|
+
"finance"
|
|
53
|
+
],
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"access": "public"
|
|
56
|
+
},
|
|
57
|
+
"repository": {
|
|
58
|
+
"type": "git",
|
|
59
|
+
"url": "git+https://github.com/truss44/mcp-crypto-price.git"
|
|
60
|
+
},
|
|
61
|
+
"bugs": {
|
|
62
|
+
"url": "https://github.com/truss44/mcp-crypto-price/issues"
|
|
63
|
+
},
|
|
64
|
+
"homepage": "https://github.com/truss44/mcp-crypto-price#readme"
|
|
65
|
+
}
|