market-data-analyzer 2.0.0
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.
Potentially problematic release.
This version of market-data-analyzer might be problematic. Click here for more details.
- package/README.md +159 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +267 -0
- package/dist/index.js.map +1 -0
- package/dist/tools/analyze_portfolio.d.ts +14 -0
- package/dist/tools/analyze_portfolio.d.ts.map +1 -0
- package/dist/tools/analyze_portfolio.js +155 -0
- package/dist/tools/analyze_portfolio.js.map +1 -0
- package/dist/tools/analyze_stock.d.ts +8 -0
- package/dist/tools/analyze_stock.d.ts.map +1 -0
- package/dist/tools/analyze_stock.js +211 -0
- package/dist/tools/analyze_stock.js.map +1 -0
- package/dist/tools/compare_assets.d.ts +8 -0
- package/dist/tools/compare_assets.d.ts.map +1 -0
- package/dist/tools/compare_assets.js +138 -0
- package/dist/tools/compare_assets.js.map +1 -0
- package/dist/tools/crypto_analysis.d.ts +8 -0
- package/dist/tools/crypto_analysis.d.ts.map +1 -0
- package/dist/tools/crypto_analysis.js +192 -0
- package/dist/tools/crypto_analysis.js.map +1 -0
- package/dist/tools/market_overview.d.ts +8 -0
- package/dist/tools/market_overview.d.ts.map +1 -0
- package/dist/tools/market_overview.js +223 -0
- package/dist/tools/market_overview.js.map +1 -0
- package/dist/tools/screen_stocks.d.ts +19 -0
- package/dist/tools/screen_stocks.d.ts.map +1 -0
- package/dist/tools/screen_stocks.js +122 -0
- package/dist/tools/screen_stocks.js.map +1 -0
- package/dist/types.d.ts +158 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/api.d.ts +37 -0
- package/dist/utils/api.d.ts.map +1 -0
- package/dist/utils/api.js +228 -0
- package/dist/utils/api.js.map +1 -0
- package/dist/utils/cache.d.ts +20 -0
- package/dist/utils/cache.d.ts.map +1 -0
- package/dist/utils/cache.js +52 -0
- package/dist/utils/cache.js.map +1 -0
- package/dist/utils/math.d.ts +30 -0
- package/dist/utils/math.d.ts.map +1 -0
- package/dist/utils/math.js +300 -0
- package/dist/utils/math.js.map +1 -0
- package/package.json +30 -0
- package/src/index.ts +329 -0
- package/src/tools/analyze_portfolio.ts +204 -0
- package/src/tools/analyze_stock.ts +204 -0
- package/src/tools/compare_assets.ts +181 -0
- package/src/tools/crypto_analysis.ts +221 -0
- package/src/tools/market_overview.ts +236 -0
- package/src/tools/screen_stocks.ts +154 -0
- package/src/types.ts +175 -0
- package/src/utils/api.ts +262 -0
- package/src/utils/cache.ts +65 -0
- package/src/utils/math.ts +332 -0
- package/tsconfig.json +19 -0
package/README.md
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# Market Data Analyzer MCP Server
|
|
2
|
+
|
|
3
|
+
Finance-focused MCP server providing live market data analysis. Analyze stocks with technical indicators, screen for opportunities, track portfolios, compare assets, monitor market conditions, and analyze crypto -- all powered by free APIs (Yahoo Finance + CoinGecko).
|
|
4
|
+
|
|
5
|
+
## Pricing
|
|
6
|
+
|
|
7
|
+
| Plan | Price | Includes |
|
|
8
|
+
|------|-------|----------|
|
|
9
|
+
| **Basic** | $15/mo | `analyze_stock`, `screen_stocks`, `market_overview` |
|
|
10
|
+
| **Pro** | $25/mo | All 6 tools + priority data refresh |
|
|
11
|
+
|
|
12
|
+
## Tools
|
|
13
|
+
|
|
14
|
+
### `analyze_stock`
|
|
15
|
+
Deep analysis of a stock symbol with live Yahoo Finance data.
|
|
16
|
+
|
|
17
|
+
**Output:** Price overview, SMA (20/50/200), RSI (14), MACD (12,26,9), support/resistance levels, golden/death cross detection, signal summary.
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
{ "symbol": "AAPL" }
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### `screen_stocks`
|
|
24
|
+
Screen ~70 popular stocks by criteria with live data.
|
|
25
|
+
|
|
26
|
+
**Filters:** Market cap range, P/E ratio, sector, volume threshold, price range.
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"sector": "tech",
|
|
31
|
+
"max_pe": 40,
|
|
32
|
+
"min_market_cap": 500000000000,
|
|
33
|
+
"limit": 10
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### `analyze_portfolio`
|
|
38
|
+
Analyze a portfolio of holdings with live price lookup.
|
|
39
|
+
|
|
40
|
+
**Output:** Total value, P&L per position, allocation %, sector breakdown, diversification score (HHI-based), concentration warnings.
|
|
41
|
+
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"holdings": [
|
|
45
|
+
{ "symbol": "AAPL", "shares": 100, "avg_cost": 150.00 },
|
|
46
|
+
{ "symbol": "MSFT", "shares": 50, "avg_cost": 380.00 },
|
|
47
|
+
{ "symbol": "JPM", "shares": 75, "avg_cost": 195.00 }
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### `compare_assets`
|
|
53
|
+
Compare 2-5 assets side by side over a configurable period.
|
|
54
|
+
|
|
55
|
+
**Output:** Returns, volatility, Sharpe ratio, max drawdown, correlation matrix, rankings.
|
|
56
|
+
|
|
57
|
+
```json
|
|
58
|
+
{
|
|
59
|
+
"symbols": ["AAPL", "MSFT", "GOOGL"],
|
|
60
|
+
"period": "1y"
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### `market_overview`
|
|
65
|
+
Live market snapshot with no arguments needed.
|
|
66
|
+
|
|
67
|
+
**Output:** Major indices (S&P 500, NASDAQ, DOW, Russell 2000), VIX interpretation, sector ETF performance, crypto & commodities, market sentiment score.
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### `crypto_analysis`
|
|
74
|
+
Crypto-specific analysis via CoinGecko free API.
|
|
75
|
+
|
|
76
|
+
**Output:** Price, 24h/7d/30d changes, volume, market cap, dominance, supply metrics, ATH/ATL, fear & greed approximation, global crypto market context.
|
|
77
|
+
|
|
78
|
+
```json
|
|
79
|
+
{ "symbol": "BTC" }
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Installation
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
npm install
|
|
86
|
+
npm run build
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Usage
|
|
90
|
+
|
|
91
|
+
### Stdio transport (default)
|
|
92
|
+
```bash
|
|
93
|
+
node dist/index.js
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### SSE transport
|
|
97
|
+
```bash
|
|
98
|
+
node dist/index.js --sse
|
|
99
|
+
# or with custom port
|
|
100
|
+
PORT=8080 node dist/index.js --sse
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Claude Desktop configuration
|
|
104
|
+
```json
|
|
105
|
+
{
|
|
106
|
+
"mcpServers": {
|
|
107
|
+
"market-data-analyzer": {
|
|
108
|
+
"command": "node",
|
|
109
|
+
"args": ["/path/to/market-data-analyzer/dist/index.js"]
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### SSE endpoints
|
|
116
|
+
- `GET /sse` -- SSE connection endpoint
|
|
117
|
+
- `POST /messages?sessionId=<id>` -- Message endpoint
|
|
118
|
+
- `GET /health` -- Health check
|
|
119
|
+
|
|
120
|
+
## Data Sources
|
|
121
|
+
|
|
122
|
+
| Source | Used By | Rate Limits |
|
|
123
|
+
|--------|---------|-------------|
|
|
124
|
+
| Yahoo Finance (free) | `analyze_stock`, `screen_stocks`, `analyze_portfolio`, `compare_assets`, `market_overview` | Unofficial, best-effort |
|
|
125
|
+
| CoinGecko (free API) | `crypto_analysis` | 10-30 calls/min |
|
|
126
|
+
|
|
127
|
+
All price data is cached in-memory with a 5-minute TTL to minimize API calls and improve response times.
|
|
128
|
+
|
|
129
|
+
## Technical Details
|
|
130
|
+
|
|
131
|
+
- **Runtime:** Node.js 18+
|
|
132
|
+
- **Language:** TypeScript (strict mode, ES modules)
|
|
133
|
+
- **Protocol:** Model Context Protocol (MCP) via `@modelcontextprotocol/sdk`
|
|
134
|
+
- **Dependencies:** `@modelcontextprotocol/sdk` + `zod` only
|
|
135
|
+
- **Caching:** In-memory with 5-minute TTL for all price data
|
|
136
|
+
- **Calculations:** SMA, EMA, RSI, MACD, Sharpe ratio, max drawdown, HHI diversification, support/resistance -- all implemented from scratch
|
|
137
|
+
|
|
138
|
+
## Project Structure
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
src/
|
|
142
|
+
index.ts # Server setup, tool registration, transports
|
|
143
|
+
types.ts # TypeScript interfaces
|
|
144
|
+
tools/
|
|
145
|
+
analyze_stock.ts # Stock analysis with technical indicators
|
|
146
|
+
screen_stocks.ts # Stock screener with live data
|
|
147
|
+
analyze_portfolio.ts # Portfolio analytics
|
|
148
|
+
compare_assets.ts # Multi-asset comparison
|
|
149
|
+
market_overview.ts # Market snapshot
|
|
150
|
+
crypto_analysis.ts # Crypto analysis via CoinGecko
|
|
151
|
+
utils/
|
|
152
|
+
api.ts # Yahoo Finance + CoinGecko API helpers
|
|
153
|
+
cache.ts # In-memory TTL cache
|
|
154
|
+
math.ts # Financial math (SMA, RSI, MACD, etc.)
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## License
|
|
158
|
+
|
|
159
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Market Data Analyzer -- MCP Server
|
|
4
|
+
*
|
|
5
|
+
* Finance-focused MCP server with live data from Yahoo Finance and CoinGecko.
|
|
6
|
+
* Tools: analyze_stock, screen_stocks, analyze_portfolio, compare_assets,
|
|
7
|
+
* market_overview, crypto_analysis.
|
|
8
|
+
*
|
|
9
|
+
* Transports: stdio (default) or SSE (--sse flag).
|
|
10
|
+
*/
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA;;;;;;;;GAQG"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Market Data Analyzer -- MCP Server
|
|
4
|
+
*
|
|
5
|
+
* Finance-focused MCP server with live data from Yahoo Finance and CoinGecko.
|
|
6
|
+
* Tools: analyze_stock, screen_stocks, analyze_portfolio, compare_assets,
|
|
7
|
+
* market_overview, crypto_analysis.
|
|
8
|
+
*
|
|
9
|
+
* Transports: stdio (default) or SSE (--sse flag).
|
|
10
|
+
*/
|
|
11
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
12
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
13
|
+
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
|
|
14
|
+
import { z } from "zod";
|
|
15
|
+
import http from "node:http";
|
|
16
|
+
import { handleAnalyzeStock } from "./tools/analyze_stock.js";
|
|
17
|
+
import { handleScreenStocks } from "./tools/screen_stocks.js";
|
|
18
|
+
import { handleAnalyzePortfolio } from "./tools/analyze_portfolio.js";
|
|
19
|
+
import { handleCompareAssets } from "./tools/compare_assets.js";
|
|
20
|
+
import { handleMarketOverview } from "./tools/market_overview.js";
|
|
21
|
+
import { handleCryptoAnalysis } from "./tools/crypto_analysis.js";
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
// Server setup
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
const server = new McpServer({
|
|
26
|
+
name: "market-data-analyzer",
|
|
27
|
+
version: "2.0.0",
|
|
28
|
+
});
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
// Tool: analyze_stock
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
server.tool("analyze_stock", "Deep analysis of a stock symbol: price, moving averages (SMA 20/50/200), RSI, MACD, support/resistance levels. Uses live Yahoo Finance data.", {
|
|
33
|
+
symbol: z
|
|
34
|
+
.string()
|
|
35
|
+
.describe("Stock ticker symbol (e.g. 'AAPL', 'MSFT', 'TSLA')"),
|
|
36
|
+
}, async ({ symbol }) => {
|
|
37
|
+
try {
|
|
38
|
+
const result = await handleAnalyzeStock(symbol.toUpperCase());
|
|
39
|
+
return { content: [{ type: "text", text: result }] };
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
return {
|
|
43
|
+
content: [
|
|
44
|
+
{
|
|
45
|
+
type: "text",
|
|
46
|
+
text: `Error analyzing ${symbol}: ${err instanceof Error ? err.message : String(err)}`,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
isError: true,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
// Tool: screen_stocks
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
server.tool("screen_stocks", "Screen stocks by criteria: market cap range, P/E ratio, sector, volume threshold. Returns top matches with key metrics. Fetches live data from Yahoo Finance for ~70 popular stocks.", {
|
|
57
|
+
min_market_cap: z
|
|
58
|
+
.number()
|
|
59
|
+
.optional()
|
|
60
|
+
.describe("Minimum market cap in USD (e.g. 1000000000 for $1B)"),
|
|
61
|
+
max_market_cap: z.number().optional().describe("Maximum market cap in USD"),
|
|
62
|
+
min_pe: z.number().optional().describe("Minimum trailing P/E ratio"),
|
|
63
|
+
max_pe: z.number().optional().describe("Maximum trailing P/E ratio"),
|
|
64
|
+
sector: z
|
|
65
|
+
.string()
|
|
66
|
+
.optional()
|
|
67
|
+
.describe("Sector filter (partial match, e.g. 'tech', 'health', 'energy')"),
|
|
68
|
+
min_volume: z.number().optional().describe("Minimum daily trading volume"),
|
|
69
|
+
min_price: z.number().optional().describe("Minimum stock price"),
|
|
70
|
+
max_price: z.number().optional().describe("Maximum stock price"),
|
|
71
|
+
limit: z
|
|
72
|
+
.number()
|
|
73
|
+
.int()
|
|
74
|
+
.min(1)
|
|
75
|
+
.max(50)
|
|
76
|
+
.optional()
|
|
77
|
+
.describe("Max results to return (default: 25)"),
|
|
78
|
+
}, async (criteria) => {
|
|
79
|
+
try {
|
|
80
|
+
const result = await handleScreenStocks(criteria);
|
|
81
|
+
return { content: [{ type: "text", text: result }] };
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
return {
|
|
85
|
+
content: [
|
|
86
|
+
{
|
|
87
|
+
type: "text",
|
|
88
|
+
text: `Error screening stocks: ${err instanceof Error ? err.message : String(err)}`,
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
isError: true,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
// ---------------------------------------------------------------------------
|
|
96
|
+
// Tool: analyze_portfolio
|
|
97
|
+
// ---------------------------------------------------------------------------
|
|
98
|
+
server.tool("analyze_portfolio", "Analyze a portfolio of holdings. Provide positions with symbol, shares, and average cost. Returns total value, P&L per position, allocation %, diversification score, and risk metrics. Fetches live prices from Yahoo Finance.", {
|
|
99
|
+
holdings: z
|
|
100
|
+
.array(z.object({
|
|
101
|
+
symbol: z.string().describe("Ticker symbol (e.g. 'AAPL')"),
|
|
102
|
+
shares: z.number().describe("Number of shares held"),
|
|
103
|
+
avg_cost: z.number().describe("Average cost per share"),
|
|
104
|
+
}))
|
|
105
|
+
.min(1)
|
|
106
|
+
.describe("Array of portfolio holdings"),
|
|
107
|
+
}, async ({ holdings }) => {
|
|
108
|
+
try {
|
|
109
|
+
const result = await handleAnalyzePortfolio(holdings);
|
|
110
|
+
return { content: [{ type: "text", text: result }] };
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
return {
|
|
114
|
+
content: [
|
|
115
|
+
{
|
|
116
|
+
type: "text",
|
|
117
|
+
text: `Error analyzing portfolio: ${err instanceof Error ? err.message : String(err)}`,
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
isError: true,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
// ---------------------------------------------------------------------------
|
|
125
|
+
// Tool: compare_assets
|
|
126
|
+
// ---------------------------------------------------------------------------
|
|
127
|
+
server.tool("compare_assets", "Compare 2-5 assets side by side: returns, volatility, correlation, Sharpe ratio approximation over a given period. Uses Yahoo Finance historical data.", {
|
|
128
|
+
symbols: z
|
|
129
|
+
.array(z.string())
|
|
130
|
+
.min(2)
|
|
131
|
+
.max(5)
|
|
132
|
+
.describe("Array of 2-5 ticker symbols to compare (e.g. ['AAPL', 'MSFT', 'GOOGL'])"),
|
|
133
|
+
period: z
|
|
134
|
+
.enum(["1mo", "3mo", "6mo", "1y", "2y", "5y"])
|
|
135
|
+
.optional()
|
|
136
|
+
.describe("Comparison period (default: '6mo')"),
|
|
137
|
+
}, async ({ symbols, period }) => {
|
|
138
|
+
try {
|
|
139
|
+
const result = await handleCompareAssets(symbols.map((s) => s.toUpperCase()), period ?? "6mo");
|
|
140
|
+
return { content: [{ type: "text", text: result }] };
|
|
141
|
+
}
|
|
142
|
+
catch (err) {
|
|
143
|
+
return {
|
|
144
|
+
content: [
|
|
145
|
+
{
|
|
146
|
+
type: "text",
|
|
147
|
+
text: `Error comparing assets: ${err instanceof Error ? err.message : String(err)}`,
|
|
148
|
+
},
|
|
149
|
+
],
|
|
150
|
+
isError: true,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
// ---------------------------------------------------------------------------
|
|
155
|
+
// Tool: market_overview
|
|
156
|
+
// ---------------------------------------------------------------------------
|
|
157
|
+
server.tool("market_overview", "Current market snapshot: major indices (S&P 500, NASDAQ, DOW), sector performance via ETFs, market breadth indicators, VIX, crypto, and commodities. Live data from Yahoo Finance.", {}, async () => {
|
|
158
|
+
try {
|
|
159
|
+
const result = await handleMarketOverview();
|
|
160
|
+
return { content: [{ type: "text", text: result }] };
|
|
161
|
+
}
|
|
162
|
+
catch (err) {
|
|
163
|
+
return {
|
|
164
|
+
content: [
|
|
165
|
+
{
|
|
166
|
+
type: "text",
|
|
167
|
+
text: `Error fetching market overview: ${err instanceof Error ? err.message : String(err)}`,
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
isError: true,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
// ---------------------------------------------------------------------------
|
|
175
|
+
// Tool: crypto_analysis
|
|
176
|
+
// ---------------------------------------------------------------------------
|
|
177
|
+
server.tool("crypto_analysis", "Crypto-specific analysis: price, 24h volume, market dominance, fear/greed index approximation, supply metrics, ATH/ATL data. Uses CoinGecko free API.", {
|
|
178
|
+
symbol: z
|
|
179
|
+
.string()
|
|
180
|
+
.describe("Cryptocurrency symbol or name (e.g. 'BTC', 'ETH', 'SOL', 'bitcoin')"),
|
|
181
|
+
}, async ({ symbol }) => {
|
|
182
|
+
try {
|
|
183
|
+
const result = await handleCryptoAnalysis(symbol);
|
|
184
|
+
return { content: [{ type: "text", text: result }] };
|
|
185
|
+
}
|
|
186
|
+
catch (err) {
|
|
187
|
+
return {
|
|
188
|
+
content: [
|
|
189
|
+
{
|
|
190
|
+
type: "text",
|
|
191
|
+
text: `Error analyzing crypto ${symbol}: ${err instanceof Error ? err.message : String(err)}`,
|
|
192
|
+
},
|
|
193
|
+
],
|
|
194
|
+
isError: true,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
// ---------------------------------------------------------------------------
|
|
199
|
+
// Transport: stdio or SSE
|
|
200
|
+
// ---------------------------------------------------------------------------
|
|
201
|
+
async function main() {
|
|
202
|
+
const useSSE = process.argv.includes("--sse");
|
|
203
|
+
if (useSSE) {
|
|
204
|
+
const port = parseInt(process.env.PORT ?? "3000", 10);
|
|
205
|
+
const transports = new Map();
|
|
206
|
+
const httpServer = http.createServer(async (req, res) => {
|
|
207
|
+
// CORS headers
|
|
208
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
209
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
|
|
210
|
+
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
|
|
211
|
+
if (req.method === "OPTIONS") {
|
|
212
|
+
res.writeHead(204);
|
|
213
|
+
res.end();
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const url = new URL(req.url ?? "/", `http://localhost:${port}`);
|
|
217
|
+
if (url.pathname === "/sse" && req.method === "GET") {
|
|
218
|
+
const transport = new SSEServerTransport("/messages", res);
|
|
219
|
+
const sessionId = transport.sessionId;
|
|
220
|
+
transports.set(sessionId, transport);
|
|
221
|
+
res.on("close", () => {
|
|
222
|
+
transports.delete(sessionId);
|
|
223
|
+
});
|
|
224
|
+
await server.connect(transport);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (url.pathname === "/messages" && req.method === "POST") {
|
|
228
|
+
const sessionId = url.searchParams.get("sessionId");
|
|
229
|
+
if (!sessionId || !transports.has(sessionId)) {
|
|
230
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
231
|
+
res.end(JSON.stringify({ error: "Invalid or missing sessionId" }));
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
const transport = transports.get(sessionId);
|
|
235
|
+
await transport.handlePostMessage(req, res);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
if (url.pathname === "/health") {
|
|
239
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
240
|
+
res.end(JSON.stringify({
|
|
241
|
+
status: "ok",
|
|
242
|
+
server: "market-data-analyzer",
|
|
243
|
+
version: "2.0.0",
|
|
244
|
+
}));
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
res.writeHead(404, { "Content-Type": "application/json" });
|
|
248
|
+
res.end(JSON.stringify({ error: "Not found" }));
|
|
249
|
+
});
|
|
250
|
+
httpServer.listen(port, () => {
|
|
251
|
+
console.error(`Market Data Analyzer MCP server (SSE) listening on port ${port}`);
|
|
252
|
+
console.error(` SSE endpoint: http://localhost:${port}/sse`);
|
|
253
|
+
console.error(` Messages endpoint: http://localhost:${port}/messages`);
|
|
254
|
+
console.error(` Health check: http://localhost:${port}/health`);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
const transport = new StdioServerTransport();
|
|
259
|
+
await server.connect(transport);
|
|
260
|
+
console.error("Market Data Analyzer MCP server running on stdio");
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
main().catch((err) => {
|
|
264
|
+
console.error("Fatal error:", err);
|
|
265
|
+
process.exit(1);
|
|
266
|
+
});
|
|
267
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA;;;;;;;;GAQG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAElE,8EAA8E;AAC9E,eAAe;AACf,8EAA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AAO,CAAC,KAAK,CAAC,oCAAoC,IAAI,MAAM,CAAC,CAAC;YAC9D,OAAO,CAAC,KAAK,CAAC,yCAAyC,IAAI,WAAW,CAAC,CAAC;YACxE,OAAO,CAAC,KAAK,CAAC,oCAAoC,IAAI,SAAS,CAAC,CAAC;QACnE,CAAC,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;QAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAChC,OAAO,CAAC,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACpE,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC;IACnC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* analyze_portfolio -- Portfolio analytics with live prices.
|
|
3
|
+
*
|
|
4
|
+
* Takes an array of { symbol, shares, avg_cost } holdings, fetches
|
|
5
|
+
* current prices from Yahoo Finance, and returns P&L, allocation,
|
|
6
|
+
* diversification score, and risk metrics.
|
|
7
|
+
*/
|
|
8
|
+
export interface PortfolioHolding {
|
|
9
|
+
symbol: string;
|
|
10
|
+
shares: number;
|
|
11
|
+
avg_cost: number;
|
|
12
|
+
}
|
|
13
|
+
export declare function handleAnalyzePortfolio(holdings: PortfolioHolding[]): Promise<string>;
|
|
14
|
+
//# sourceMappingURL=analyze_portfolio.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyze_portfolio.d.ts","sourceRoot":"","sources":["../../src/tools/analyze_portfolio.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AAgBD,wBAAsB,sBAAsB,CAC1C,QAAQ,EAAE,gBAAgB,EAAE,GAC3B,OAAO,CAAC,MAAM,CAAC,CA0KjB"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* analyze_portfolio -- Portfolio analytics with live prices.
|
|
3
|
+
*
|
|
4
|
+
* Takes an array of { symbol, shares, avg_cost } holdings, fetches
|
|
5
|
+
* current prices from Yahoo Finance, and returns P&L, allocation,
|
|
6
|
+
* diversification score, and risk metrics.
|
|
7
|
+
*/
|
|
8
|
+
import { yahooQuote } from "../utils/api.js";
|
|
9
|
+
import { formatCurrency } from "../utils/math.js";
|
|
10
|
+
export async function handleAnalyzePortfolio(holdings) {
|
|
11
|
+
if (holdings.length === 0) {
|
|
12
|
+
throw new Error("At least one holding is required.");
|
|
13
|
+
}
|
|
14
|
+
// Fetch live quotes for all symbols
|
|
15
|
+
const symbols = holdings.map((h) => h.symbol);
|
|
16
|
+
const quotes = await yahooQuote(symbols);
|
|
17
|
+
const quoteMap = new Map(quotes.map((q) => [q.symbol, q]));
|
|
18
|
+
// Build position analysis
|
|
19
|
+
let totalValue = 0;
|
|
20
|
+
let totalCost = 0;
|
|
21
|
+
const positions = holdings.map((h) => {
|
|
22
|
+
const q = quoteMap.get(h.symbol);
|
|
23
|
+
const currentPrice = q?.regularMarketPrice ?? 0;
|
|
24
|
+
const marketValue = h.shares * currentPrice;
|
|
25
|
+
const costBasis = h.shares * h.avg_cost;
|
|
26
|
+
totalValue += marketValue;
|
|
27
|
+
totalCost += costBasis;
|
|
28
|
+
return {
|
|
29
|
+
symbol: h.symbol,
|
|
30
|
+
name: q?.shortName ?? q?.longName ?? h.symbol,
|
|
31
|
+
shares: h.shares,
|
|
32
|
+
avgCost: h.avg_cost,
|
|
33
|
+
currentPrice,
|
|
34
|
+
marketValue,
|
|
35
|
+
costBasis,
|
|
36
|
+
pnl: marketValue - costBasis,
|
|
37
|
+
pnlPercent: costBasis > 0 ? ((marketValue - costBasis) / costBasis) * 100 : 0,
|
|
38
|
+
allocationPercent: 0, // calculated below
|
|
39
|
+
sector: q?.sector ?? "Unknown",
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
// Calculate allocation percentages
|
|
43
|
+
for (const p of positions) {
|
|
44
|
+
p.allocationPercent = totalValue > 0 ? (p.marketValue / totalValue) * 100 : 0;
|
|
45
|
+
}
|
|
46
|
+
// Sort by market value descending
|
|
47
|
+
positions.sort((a, b) => b.marketValue - a.marketValue);
|
|
48
|
+
// Sector breakdown
|
|
49
|
+
const sectorAlloc = {};
|
|
50
|
+
for (const p of positions) {
|
|
51
|
+
sectorAlloc[p.sector] = (sectorAlloc[p.sector] ?? 0) + p.allocationPercent;
|
|
52
|
+
}
|
|
53
|
+
// Diversification score (HHI-based, 0-100 where 100 = perfectly diversified)
|
|
54
|
+
const weights = positions.map((p) => p.allocationPercent / 100);
|
|
55
|
+
const hhi = weights.reduce((s, w) => s + w * w, 0);
|
|
56
|
+
const n = weights.length;
|
|
57
|
+
const minHHI = n > 0 ? 1 / n : 1;
|
|
58
|
+
const divScore = n <= 1 ? 0 : Math.round((1 - (hhi - minHHI) / (1 - minHHI)) * 100);
|
|
59
|
+
// Risk warnings
|
|
60
|
+
const warnings = [];
|
|
61
|
+
for (const p of positions) {
|
|
62
|
+
if (p.allocationPercent > 30) {
|
|
63
|
+
warnings.push(`HIGH CONCENTRATION: ${p.symbol} is ${p.allocationPercent.toFixed(1)}% of portfolio.`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
for (const [sector, pct] of Object.entries(sectorAlloc)) {
|
|
67
|
+
if (pct > 50) {
|
|
68
|
+
warnings.push(`SECTOR RISK: ${sector} represents ${pct.toFixed(1)}% of portfolio.`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
for (const p of positions) {
|
|
72
|
+
if (p.pnlPercent < -20) {
|
|
73
|
+
warnings.push(`SIGNIFICANT LOSS: ${p.symbol} is down ${Math.abs(p.pnlPercent).toFixed(1)}%.`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (n < 5) {
|
|
77
|
+
warnings.push(`LOW DIVERSIFICATION: Only ${n} position(s). Consider adding more holdings.`);
|
|
78
|
+
}
|
|
79
|
+
if (Object.keys(sectorAlloc).length < 3 && n >= 3) {
|
|
80
|
+
warnings.push("LIMITED SECTOR EXPOSURE: Portfolio spans fewer than 3 sectors.");
|
|
81
|
+
}
|
|
82
|
+
// Any positions where we couldn't fetch a price?
|
|
83
|
+
const missingPrices = positions.filter((p) => p.currentPrice === 0);
|
|
84
|
+
for (const p of missingPrices) {
|
|
85
|
+
warnings.push(`MISSING DATA: Could not fetch price for ${p.symbol}. Values may be inaccurate.`);
|
|
86
|
+
}
|
|
87
|
+
// Format output
|
|
88
|
+
const lines = [];
|
|
89
|
+
lines.push("# Portfolio Analysis");
|
|
90
|
+
lines.push("");
|
|
91
|
+
// Summary
|
|
92
|
+
lines.push("## Summary");
|
|
93
|
+
lines.push("");
|
|
94
|
+
lines.push("| Metric | Value |");
|
|
95
|
+
lines.push("|--------|-------|");
|
|
96
|
+
lines.push(`| Total Value | ${formatCurrency(totalValue)} |`);
|
|
97
|
+
lines.push(`| Total Cost Basis | ${formatCurrency(totalCost)} |`);
|
|
98
|
+
const totalPnl = totalValue - totalCost;
|
|
99
|
+
const totalPnlPct = totalCost > 0 ? ((totalPnl) / totalCost) * 100 : 0;
|
|
100
|
+
lines.push(`| Total P&L | ${totalPnl >= 0 ? "+" : ""}${formatCurrency(totalPnl)} (${totalPnlPct >= 0 ? "+" : ""}${totalPnlPct.toFixed(2)}%) |`);
|
|
101
|
+
lines.push(`| Positions | ${n} |`);
|
|
102
|
+
lines.push(`| Sectors | ${Object.keys(sectorAlloc).length} |`);
|
|
103
|
+
lines.push(`| Diversification Score | ${divScore}/100 |`);
|
|
104
|
+
lines.push("");
|
|
105
|
+
// Positions
|
|
106
|
+
lines.push("## Positions");
|
|
107
|
+
lines.push("");
|
|
108
|
+
lines.push("| Symbol | Name | Shares | Avg Cost | Price | Value | P&L | P&L% | Alloc% |");
|
|
109
|
+
lines.push("|--------|------|--------|----------|-------|-------|-----|------|--------|");
|
|
110
|
+
for (const p of positions) {
|
|
111
|
+
const pnlSign = p.pnl >= 0 ? "+" : "";
|
|
112
|
+
lines.push(`| ${p.symbol} | ${p.name.slice(0, 20)} | ${p.shares} | $${p.avgCost.toFixed(2)} | $${p.currentPrice.toFixed(2)} | ${formatCurrency(p.marketValue)} | ${pnlSign}${formatCurrency(p.pnl)} | ${pnlSign}${p.pnlPercent.toFixed(2)}% | ${p.allocationPercent.toFixed(1)}% |`);
|
|
113
|
+
}
|
|
114
|
+
lines.push("");
|
|
115
|
+
// Sector allocation
|
|
116
|
+
lines.push("## Sector Allocation");
|
|
117
|
+
lines.push("");
|
|
118
|
+
lines.push("| Sector | Allocation |");
|
|
119
|
+
lines.push("|--------|------------|");
|
|
120
|
+
const sortedSectors = Object.entries(sectorAlloc).sort((a, b) => b[1] - a[1]);
|
|
121
|
+
for (const [sector, pct] of sortedSectors) {
|
|
122
|
+
const bar = "=".repeat(Math.round(pct / 2));
|
|
123
|
+
lines.push(`| ${sector} | ${pct.toFixed(1)}% ${bar} |`);
|
|
124
|
+
}
|
|
125
|
+
lines.push("");
|
|
126
|
+
// Winners and losers
|
|
127
|
+
const winners = [...positions].sort((a, b) => b.pnlPercent - a.pnlPercent);
|
|
128
|
+
if (winners.length > 0) {
|
|
129
|
+
lines.push("## Top Performers");
|
|
130
|
+
lines.push("");
|
|
131
|
+
const top3 = winners.slice(0, Math.min(3, winners.length));
|
|
132
|
+
for (const p of top3) {
|
|
133
|
+
lines.push(`- **${p.symbol}**: ${p.pnlPercent >= 0 ? "+" : ""}${p.pnlPercent.toFixed(2)}% (${p.pnl >= 0 ? "+" : ""}${formatCurrency(p.pnl)})`);
|
|
134
|
+
}
|
|
135
|
+
lines.push("");
|
|
136
|
+
const bottom3 = winners.slice(-Math.min(3, winners.length)).reverse();
|
|
137
|
+
lines.push("## Underperformers");
|
|
138
|
+
lines.push("");
|
|
139
|
+
for (const p of bottom3) {
|
|
140
|
+
lines.push(`- **${p.symbol}**: ${p.pnlPercent >= 0 ? "+" : ""}${p.pnlPercent.toFixed(2)}% (${p.pnl >= 0 ? "+" : ""}${formatCurrency(p.pnl)})`);
|
|
141
|
+
}
|
|
142
|
+
lines.push("");
|
|
143
|
+
}
|
|
144
|
+
// Risk warnings
|
|
145
|
+
if (warnings.length > 0) {
|
|
146
|
+
lines.push("## Risk Warnings");
|
|
147
|
+
lines.push("");
|
|
148
|
+
for (const w of warnings) {
|
|
149
|
+
lines.push(`- ${w}`);
|
|
150
|
+
}
|
|
151
|
+
lines.push("");
|
|
152
|
+
}
|
|
153
|
+
return lines.join("\n");
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=analyze_portfolio.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyze_portfolio.js","sourceRoot":"","sources":["../../src/tools/analyze_portfolio.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAsBlD,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,QAA4B;IAE5B,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IAED,oCAAoC;IACpC,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAC9C,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC,CAAC;IACzC,MAAM,QAAQ,GAAG,IAAI,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C;QACf,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;YACzB,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACvB,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACjB,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* analyze_stock -- Deep analysis of a stock symbol.
|
|
3
|
+
*
|
|
4
|
+
* Fetches live data from Yahoo Finance, computes SMA 20/50/200, RSI,
|
|
5
|
+
* MACD, and support/resistance levels.
|
|
6
|
+
*/
|
|
7
|
+
export declare function handleAnalyzeStock(symbol: string): Promise<string>;
|
|
8
|
+
//# sourceMappingURL=analyze_stock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyze_stock.d.ts","sourceRoot":"","sources":["../../src/tools/analyze_stock.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAaH,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAyLxE"}
|