stockquotes-mcp 1.0.3
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 +257 -0
- package/README.sample1.png +0 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +146 -0
- package/dist/index.js.map +1 -0
- package/dist/server.d.ts +34 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +66 -0
- package/dist/server.js.map +1 -0
- package/dist/stockQuotesService.d.ts +39 -0
- package/dist/stockQuotesService.d.ts.map +1 -0
- package/dist/stockQuotesService.js +140 -0
- package/dist/stockQuotesService.js.map +1 -0
- package/dist/toolRegistration.d.ts +9 -0
- package/dist/toolRegistration.d.ts.map +1 -0
- package/dist/toolRegistration.js +81 -0
- package/dist/toolRegistration.js.map +1 -0
- package/dist/transports/HttpTransportStrategy.d.ts +52 -0
- package/dist/transports/HttpTransportStrategy.d.ts.map +1 -0
- package/dist/transports/HttpTransportStrategy.js +167 -0
- package/dist/transports/HttpTransportStrategy.js.map +1 -0
- package/dist/transports/StdioTransportStrategy.d.ts +37 -0
- package/dist/transports/StdioTransportStrategy.d.ts.map +1 -0
- package/dist/transports/StdioTransportStrategy.js +54 -0
- package/dist/transports/StdioTransportStrategy.js.map +1 -0
- package/dist/transports/TransportFactory.d.ts +16 -0
- package/dist/transports/TransportFactory.d.ts.map +1 -0
- package/dist/transports/TransportFactory.js +24 -0
- package/dist/transports/TransportFactory.js.map +1 -0
- package/dist/transports/TransportStrategy.d.ts +24 -0
- package/dist/transports/TransportStrategy.d.ts.map +1 -0
- package/dist/transports/TransportStrategy.js +2 -0
- package/dist/transports/TransportStrategy.js.map +1 -0
- package/dist/types.d.ts +105 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +12 -0
- package/dist/types.js.map +1 -0
- package/dist/yahooFinanceClient.d.ts +14 -0
- package/dist/yahooFinanceClient.d.ts.map +1 -0
- package/dist/yahooFinanceClient.js +20 -0
- package/dist/yahooFinanceClient.js.map +1 -0
- package/package.json +86 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Lionel Schiepers
|
|
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,257 @@
|
|
|
1
|
+
# 📈 MCP Stock Quotes Server
|
|
2
|
+
|
|
3
|
+
[](https://github.com/lionelschiepers/StockQuotes.MCP/actions/workflows/build.yml)
|
|
4
|
+
[](https://codecov.io/github/lionelschiepers/StockQuotes.MCP)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
[](https://modelcontextprotocol.io/)
|
|
8
|
+
|
|
9
|
+
**Empower your AI assistants with real-time financial market data.**
|
|
10
|
+
|
|
11
|
+
This **Model Context Protocol (MCP)** server seamlessly bridges the gap between LLMs (like Claude, Gemini, etc.) and Yahoo Finance, enabling intelligent agents to access, analyze, and discuss live stock market trends, historical data, and financial metrics.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## 📖 Table of Contents
|
|
16
|
+
|
|
17
|
+
- [Why Use This?](#-why-use-this)
|
|
18
|
+
- [Features](#-features)
|
|
19
|
+
- [Quick Start](#-quick-start)
|
|
20
|
+
- [Installation](#-installation)
|
|
21
|
+
- [Usage](#-usage)
|
|
22
|
+
- [Available Tools](#-available-mcp-tools)
|
|
23
|
+
- [Example Interaction](#-example-interaction)
|
|
24
|
+
- [Integration Guide](#-integration-with-ai-platforms)
|
|
25
|
+
- [Cline](#cline)
|
|
26
|
+
- [Gemini CLI](#gemini-cli)
|
|
27
|
+
- [Docker Support](#-docker-usage)
|
|
28
|
+
- [Development](#-development)
|
|
29
|
+
- [License](#-license)
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## 💡 Why Use This?
|
|
34
|
+
|
|
35
|
+
AI models are powerful, but they often lack real-time knowledge. By connecting them to this MCP server, you unlock their ability to:
|
|
36
|
+
|
|
37
|
+
* **Analyze Market Trends**: "Compare the P/E ratio of Apple vs. Microsoft."
|
|
38
|
+
* **Track Portfolios**: "What is the current value of 10 shares of NVDA?"
|
|
39
|
+
* **Research Companies**: "Get me the latest market cap and 52-week range for Tesla."
|
|
40
|
+
* **Contextualize News**: "How did the latest earnings report affect Google's stock price today?"
|
|
41
|
+
|
|
42
|
+
It transforms your AI from a static text generator into a dynamic financial analyst.
|
|
43
|
+
|
|
44
|
+
## 🚀 Features
|
|
45
|
+
|
|
46
|
+
* **Real-time Data**: Instant access to prices, volume, market cap, and more via Yahoo Finance.
|
|
47
|
+
* **Dual Transport**: Supports `stdio` (for local CLIs) and `SSE/HTTP` (for remote/web clients).
|
|
48
|
+
* **Smart Search**: Fuzzy search for stocks by company name or ticker symbol.
|
|
49
|
+
* **Multi-Asset Support**: Works with Stocks, ETFs, Cryptocurrencies, and Indices.
|
|
50
|
+
* **Type-Safe**: Built with 100% TypeScript for reliability.
|
|
51
|
+
* **Production Ready**: Includes Docker support, CI/CD pipelines, and comprehensive testing.
|
|
52
|
+
|
|
53
|
+
## ⚡ Quick Start
|
|
54
|
+
|
|
55
|
+
For those who want to get up and running immediately:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# Clone and Install
|
|
59
|
+
git clone https://github.com/lionelschiepers/StockQuotes.MCP.git
|
|
60
|
+
cd StockQuotes.MCP
|
|
61
|
+
npm install
|
|
62
|
+
|
|
63
|
+
# Build
|
|
64
|
+
npm run build
|
|
65
|
+
|
|
66
|
+
# Start (Stdio Mode - default for most MCP clients)
|
|
67
|
+
npm run start:stdio
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## 🛠 Installation
|
|
71
|
+
|
|
72
|
+
### Prerequisites
|
|
73
|
+
|
|
74
|
+
* Node.js 22.0.0 or higher (LTS)
|
|
75
|
+
* npm 9.0.0 or higher
|
|
76
|
+
|
|
77
|
+
### Step-by-Step
|
|
78
|
+
|
|
79
|
+
1. **Clone the repository**
|
|
80
|
+
```bash
|
|
81
|
+
git clone https://github.com/lionelschiepers/StockQuotes.MCP.git
|
|
82
|
+
cd StockQuotes.MCP
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
2. **Install dependencies**
|
|
86
|
+
```bash
|
|
87
|
+
npm install
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
3. **Build the project**
|
|
91
|
+
```bash
|
|
92
|
+
npm run build
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## 🚦 Usage
|
|
96
|
+
|
|
97
|
+
### Command Line Options
|
|
98
|
+
|
|
99
|
+
| Command | Description |
|
|
100
|
+
| :--- | :--- |
|
|
101
|
+
| `npm run start:stdio` | Starts server with Standard I/O transport (Best for local AI agents). |
|
|
102
|
+
| `npm run start:http` | Starts server with HTTP transport on port 3000. |
|
|
103
|
+
| `npm run dev` | Runs in development mode with hot-reloading. |
|
|
104
|
+
|
|
105
|
+
### Available MCP Tools
|
|
106
|
+
|
|
107
|
+
Your AI agent will have access to the following tools:
|
|
108
|
+
|
|
109
|
+
#### 1. `get_stock_quote`
|
|
110
|
+
Fetches detailed financial data for a specific ticker.
|
|
111
|
+
|
|
112
|
+
* **Example Prompt:** "What is the price of AAPL?"
|
|
113
|
+
* **Returns:** Price, Currency, Market Cap, Exchange, etc.
|
|
114
|
+
|
|
115
|
+
#### 2. `search_stocks`
|
|
116
|
+
Finds ticker symbols based on company names.
|
|
117
|
+
|
|
118
|
+
* **Example Prompt:** "Find the ticker for 'Hims & Hers'."
|
|
119
|
+
* **Returns:** List of matching symbols and names.
|
|
120
|
+
|
|
121
|
+
#### 3. `get_historical_data`
|
|
122
|
+
Fetches historical stock data for a specific date range.
|
|
123
|
+
|
|
124
|
+
* **Example Prompt:** "Get AAPL historical data from 2024-01-01 to 2024-01-31."
|
|
125
|
+
* **Returns:** Array of daily prices including date, close, high, low, and volume.
|
|
126
|
+
|
|
127
|
+
## 💬 Example Interaction
|
|
128
|
+
|
|
129
|
+
Here is a real-world example of how an AI assistant (like Gemini) uses this MCP server to perform data analysis:
|
|
130
|
+
|
|
131
|
+
**User Prompt:**
|
|
132
|
+
> "Using stock-quotes: Calculate the average price of AAPL for the last 200, 50 and 20 days. Output is {[{days, average}]}. Keep only 2 decimals for the numbers."
|
|
133
|
+
|
|
134
|
+
**AI Response:**
|
|
135
|
+
```json
|
|
136
|
+
[
|
|
137
|
+
{
|
|
138
|
+
"days": 200,
|
|
139
|
+
"average": 233.12
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
"days": 50,
|
|
143
|
+
"average": 272.62
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
"days": 20,
|
|
147
|
+
"average": 270.57
|
|
148
|
+
}
|
|
149
|
+
]
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+

|
|
153
|
+
|
|
154
|
+
## 🤖 Integration with AI Platforms
|
|
155
|
+
|
|
156
|
+
### Cline
|
|
157
|
+
|
|
158
|
+
To use with [Cline](https://github.com/cline/cline), add this to your MCP settings file:
|
|
159
|
+
|
|
160
|
+
```json
|
|
161
|
+
{
|
|
162
|
+
"mcpServers": {
|
|
163
|
+
"stock-quotes": {
|
|
164
|
+
"command": "node",
|
|
165
|
+
"args": ["/absolute/path/to/StockQuotes.MCP/dist/index.js", "--transport", "stdio"],
|
|
166
|
+
"disabled": false,
|
|
167
|
+
"autoApprove": []
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Gemini CLI
|
|
174
|
+
|
|
175
|
+
Integrate with the Gemini CLI tool using one of these methods:
|
|
176
|
+
|
|
177
|
+
**Method 1: Direct Command**
|
|
178
|
+
```bash
|
|
179
|
+
gemini mcp add stock-quotes node "C:\Path\To\StockQuotes.MCP\dist\index.js --transport stdio"
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
**Method 2: Settings Configuration**
|
|
183
|
+
Edit your `~/.gemini/settings.json`:
|
|
184
|
+
|
|
185
|
+
```json
|
|
186
|
+
// CLI
|
|
187
|
+
{
|
|
188
|
+
"mcpServers": {
|
|
189
|
+
"stock-quotes": {
|
|
190
|
+
"command": "node",
|
|
191
|
+
"args": [
|
|
192
|
+
"./dist/index.js",
|
|
193
|
+
"--transport",
|
|
194
|
+
"stdio"
|
|
195
|
+
]
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
```json
|
|
203
|
+
// HTTP
|
|
204
|
+
{
|
|
205
|
+
"mcpServers": {
|
|
206
|
+
"stock-quotes": {
|
|
207
|
+
"httpUrl": "http://servername:port/mcp",
|
|
208
|
+
"headers": {
|
|
209
|
+
"Accept": "application/json, text/event-stream"
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## 🐳 Docker Usage
|
|
217
|
+
|
|
218
|
+
Run the server in an isolated container.
|
|
219
|
+
|
|
220
|
+
**Build:**
|
|
221
|
+
```bash
|
|
222
|
+
docker build -t stockquotes-mcp:latest .
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
**Run (HTTP Mode):**
|
|
226
|
+
```bash
|
|
227
|
+
docker run -p 3000:3000 stockquotes-mcp:latest
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## 💻 Development
|
|
231
|
+
|
|
232
|
+
### Project Structure
|
|
233
|
+
```
|
|
234
|
+
StockQuotes.MCP/
|
|
235
|
+
├── src/ # Source code
|
|
236
|
+
├── tests/ # Jest tests
|
|
237
|
+
├── .github/ # CI/CD Workflows
|
|
238
|
+
└── ...
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Quality Checks
|
|
242
|
+
* **Test:** `npm test`
|
|
243
|
+
* **Lint:** `npm run lint`
|
|
244
|
+
* **Format:** `npm run format`
|
|
245
|
+
|
|
246
|
+
## 📄 License
|
|
247
|
+
|
|
248
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
249
|
+
|
|
250
|
+
## 🙏 Acknowledgments
|
|
251
|
+
|
|
252
|
+
* [Yahoo Finance2](https://github.com/gadicc/yahoo-finance2) API wrapper.
|
|
253
|
+
* [Model Context Protocol](https://modelcontextprotocol.io/) standard.
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
*Disclaimer: This tool is for educational purposes. Data provided by Yahoo Finance may be delayed. Validate all financial data before making investment decisions.*
|
|
Binary file
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Main entry point for the MCP Stock Quotes Server
|
|
4
|
+
*
|
|
5
|
+
* This server provides tools for fetching stock quotes from Yahoo Finance
|
|
6
|
+
* through the Model Context Protocol (MCP).
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* node dist/index.js --transport stdio # Start with stdio transport
|
|
10
|
+
* node dist/index.js --transport http # Start with HTTP transport (port 3000)
|
|
11
|
+
*/
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA;;;;;;;;;GASG"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Main entry point for the MCP Stock Quotes Server
|
|
4
|
+
*
|
|
5
|
+
* This server provides tools for fetching stock quotes from Yahoo Finance
|
|
6
|
+
* through the Model Context Protocol (MCP).
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* node dist/index.js --transport stdio # Start with stdio transport
|
|
10
|
+
* node dist/index.js --transport http # Start with HTTP transport (port 3000)
|
|
11
|
+
*/
|
|
12
|
+
import { createServer } from './server.js';
|
|
13
|
+
// Parse command line arguments
|
|
14
|
+
function parseArgs() {
|
|
15
|
+
const args = process.argv.slice(2);
|
|
16
|
+
const result = {
|
|
17
|
+
transport: 'stdio',
|
|
18
|
+
httpPort: 3000,
|
|
19
|
+
httpHost: '0.0.0.0',
|
|
20
|
+
};
|
|
21
|
+
for (let i = 0; i < args.length; i++) {
|
|
22
|
+
const arg = args[i];
|
|
23
|
+
switch (arg) {
|
|
24
|
+
case '--transport':
|
|
25
|
+
case '-t':
|
|
26
|
+
if (i + 1 < args.length) {
|
|
27
|
+
const transport = args[++i].toLowerCase();
|
|
28
|
+
if (['stdio', 'http'].includes(transport)) {
|
|
29
|
+
result.transport = transport;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
console.error(`Invalid transport: ${transport}`);
|
|
33
|
+
console.error('Valid transports: stdio, http');
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
break;
|
|
38
|
+
case '--http-port':
|
|
39
|
+
case '--httpPort':
|
|
40
|
+
if (i + 1 < args.length) {
|
|
41
|
+
result.httpPort = Number.parseInt(args[++i], 10);
|
|
42
|
+
if (Number.isNaN(result.httpPort) || result.httpPort <= 0 || result.httpPort > 65535) {
|
|
43
|
+
console.error('Invalid HTTP port. Port must be between 1 and 65535');
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
break;
|
|
48
|
+
case '--http-host':
|
|
49
|
+
case '--httpHost':
|
|
50
|
+
if (i + 1 < args.length) {
|
|
51
|
+
result.httpHost = args[++i];
|
|
52
|
+
}
|
|
53
|
+
break;
|
|
54
|
+
case '--help':
|
|
55
|
+
case '-h':
|
|
56
|
+
printHelp();
|
|
57
|
+
process.exit(0);
|
|
58
|
+
break;
|
|
59
|
+
case '--version':
|
|
60
|
+
case '-v':
|
|
61
|
+
console.log('StockQuotes.MCP version 1.0.0');
|
|
62
|
+
process.exit(0);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Print help message
|
|
69
|
+
*/
|
|
70
|
+
function printHelp() {
|
|
71
|
+
console.log(`
|
|
72
|
+
MCP Stock Quotes Server
|
|
73
|
+
|
|
74
|
+
Usage: node dist/index.js [options]
|
|
75
|
+
|
|
76
|
+
Options:
|
|
77
|
+
--transport, -t <stdio|http>
|
|
78
|
+
Specify the transport type to use (default: stdio)
|
|
79
|
+
|
|
80
|
+
--http-port <port>
|
|
81
|
+
Specify the HTTP port for HTTP transport (default: 3000)
|
|
82
|
+
|
|
83
|
+
--http-host <host>
|
|
84
|
+
Specify the HTTP host to bind to (default: 0.0.0.0)
|
|
85
|
+
|
|
86
|
+
--help, -h
|
|
87
|
+
Show this help message
|
|
88
|
+
|
|
89
|
+
--version, -v
|
|
90
|
+
Show version information
|
|
91
|
+
|
|
92
|
+
Examples:
|
|
93
|
+
# Start with stdio transport (for CLI tools)
|
|
94
|
+
node dist/index.js --transport stdio
|
|
95
|
+
|
|
96
|
+
# Start with HTTP transport on port 8080
|
|
97
|
+
node dist/index.js --transport http --http-port 8080
|
|
98
|
+
|
|
99
|
+
# Start with HTTP transport on localhost
|
|
100
|
+
node dist/index.js --transport http --http-host localhost
|
|
101
|
+
|
|
102
|
+
For more information, visit: https://github.com/lionelschiepers/StockQuotes.MCP
|
|
103
|
+
`);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Main function to start the server
|
|
107
|
+
*/
|
|
108
|
+
async function main() {
|
|
109
|
+
console.log('MCP Stock Quotes Server');
|
|
110
|
+
console.log('========================');
|
|
111
|
+
const args = parseArgs();
|
|
112
|
+
console.log(`Starting server with ${args.transport} transport...`);
|
|
113
|
+
try {
|
|
114
|
+
await createServer({
|
|
115
|
+
name: 'stock-quotes-server',
|
|
116
|
+
version: '1.0.0',
|
|
117
|
+
transport: args.transport,
|
|
118
|
+
httpPort: args.httpPort,
|
|
119
|
+
httpHost: args.httpHost,
|
|
120
|
+
});
|
|
121
|
+
console.log('Server started successfully');
|
|
122
|
+
if (args.transport === 'http') {
|
|
123
|
+
console.log('Press Ctrl+C to stop the server');
|
|
124
|
+
await new Promise(() => { });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
console.error('Failed to start server:', error);
|
|
129
|
+
process.exit(1);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// Handle graceful shutdown
|
|
133
|
+
process.on('SIGINT', () => {
|
|
134
|
+
console.log('\nShutting down server...');
|
|
135
|
+
process.exit(0);
|
|
136
|
+
});
|
|
137
|
+
process.on('SIGTERM', () => {
|
|
138
|
+
console.log('\nShutting down server...');
|
|
139
|
+
process.exit(0);
|
|
140
|
+
});
|
|
141
|
+
// Start the server
|
|
142
|
+
main().catch((error) => {
|
|
143
|
+
console.error('Unhandled error:', error);
|
|
144
|
+
process.exit(1);
|
|
145
|
+
});
|
|
146
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA;;;;;;;;;GASG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,+BAA+B;AAC/B,SAAS,SAAS;IAChB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACnC,MAAM,MAAM,GAAG;QACb,SAAS,EAAE,OAAwB;QACnC,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,SAAS;KACpB,CAAC;IAEF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAEpB,QAAQ,GAAG,EAAE,CAAC;YACZ,KAAK,aAAa,CAAC;YACnB,KAAK,IAAI;gBACP,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;oBACxB,MAAM,SAAS,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAmB,CAAC;oBAC3D,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;wBAC1C,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC;oBAC/B,CAAC;yBAAM,CAAC;wBACN,OAAO,CAAC,KAAK,CAAC,sBAAsB,SAAS,EAAE,CAAC,CAAC;wBACjD,OAAO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,CAAC,CAAC;IACzC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,mBAAmB;AACnB,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;IACzC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { StockQuotesService } from './stockQuotesService.js';
|
|
2
|
+
import type { ServerConfig } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* MCP Server for Stock Quotes using Yahoo Finance
|
|
5
|
+
*/
|
|
6
|
+
export declare class StockQuotesServer {
|
|
7
|
+
private config;
|
|
8
|
+
private stockService;
|
|
9
|
+
private transportStrategy;
|
|
10
|
+
/**
|
|
11
|
+
* Create a new instance of the StockQuotesServer
|
|
12
|
+
* @param config - Server configuration
|
|
13
|
+
* @param stockService - Stock quotes service (dependency injected)
|
|
14
|
+
*/
|
|
15
|
+
constructor(config: ServerConfig, stockService: StockQuotesService);
|
|
16
|
+
/**
|
|
17
|
+
* Connect to the appropriate transport using the strategy pattern
|
|
18
|
+
*/
|
|
19
|
+
connect(): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Get the Express app instance (for testing or custom transport setups)
|
|
22
|
+
* Only available for HTTP transport
|
|
23
|
+
*/
|
|
24
|
+
getApp(): unknown;
|
|
25
|
+
/**
|
|
26
|
+
* Close the server and cleanup resources
|
|
27
|
+
*/
|
|
28
|
+
close(): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Factory function to create and start the server
|
|
32
|
+
*/
|
|
33
|
+
export declare function createServer(config?: Partial<ServerConfig>): Promise<StockQuotesServer>;
|
|
34
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAKlE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAO/C;;GAEG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,YAAY,CAAqB;IACzC,OAAO,CAAC,iBAAiB,CAAoB;IAE7C;;;;OAIG;gBACS,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,kBAAkB;IAMlE;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAM9B;;;OAGG;IACH,MAAM,IAAI,OAAO;IAQjB;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAe7F"}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { StockQuotesService as StockQuotesServiceImpl } from './stockQuotesService.js';
|
|
2
|
+
import { registerToolsOnServer } from './toolRegistration.js';
|
|
3
|
+
import { TransportFactory } from './transports/TransportFactory.js';
|
|
4
|
+
import { YahooFinanceClient } from './yahooFinanceClient.js';
|
|
5
|
+
/**
|
|
6
|
+
* MCP Server for Stock Quotes using Yahoo Finance
|
|
7
|
+
*/
|
|
8
|
+
export class StockQuotesServer {
|
|
9
|
+
config;
|
|
10
|
+
stockService;
|
|
11
|
+
transportStrategy;
|
|
12
|
+
/**
|
|
13
|
+
* Create a new instance of the StockQuotesServer
|
|
14
|
+
* @param config - Server configuration
|
|
15
|
+
* @param stockService - Stock quotes service (dependency injected)
|
|
16
|
+
*/
|
|
17
|
+
constructor(config, stockService) {
|
|
18
|
+
this.config = config;
|
|
19
|
+
this.stockService = stockService;
|
|
20
|
+
this.transportStrategy = TransportFactory.createTransport(config, this.stockService);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Connect to the appropriate transport using the strategy pattern
|
|
24
|
+
*/
|
|
25
|
+
async connect() {
|
|
26
|
+
const server = this.transportStrategy.getServer();
|
|
27
|
+
registerToolsOnServer(server, this.stockService);
|
|
28
|
+
await this.transportStrategy.connect();
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Get the Express app instance (for testing or custom transport setups)
|
|
32
|
+
* Only available for HTTP transport
|
|
33
|
+
*/
|
|
34
|
+
getApp() {
|
|
35
|
+
const strategy = this.transportStrategy;
|
|
36
|
+
if (typeof strategy.getApp === 'function') {
|
|
37
|
+
return strategy.getApp();
|
|
38
|
+
}
|
|
39
|
+
throw new Error('Express app is only available for HTTP transport');
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Close the server and cleanup resources
|
|
43
|
+
*/
|
|
44
|
+
async close() {
|
|
45
|
+
await this.transportStrategy.close();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Factory function to create and start the server
|
|
50
|
+
*/
|
|
51
|
+
export async function createServer(config) {
|
|
52
|
+
const serverConfig = {
|
|
53
|
+
name: 'stock-quotes-server',
|
|
54
|
+
version: '1.0.0',
|
|
55
|
+
transport: 'stdio',
|
|
56
|
+
httpPort: 3000,
|
|
57
|
+
httpHost: '0.0.0.0',
|
|
58
|
+
...config,
|
|
59
|
+
};
|
|
60
|
+
const yahooClient = new YahooFinanceClient();
|
|
61
|
+
const stockService = new StockQuotesServiceImpl(yahooClient);
|
|
62
|
+
const server = new StockQuotesServer(serverConfig, stockService);
|
|
63
|
+
await server.connect();
|
|
64
|
+
return server;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.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CAAC,MAA8B;IAC/D,MAAM,YAAY,GAAiB;QACjC,IAAI,EAAE,qBAAqB;QAC3B,OAAO,EAAE,OAAO;QAChB,SAAS,EAAE,OAAO;QAClB,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,SAAS;QACnB,GAAG,MAAM;KACV,CAAC;IAEF,MAAM,WAAW,GAAG,IAAI,kBAAkB,EAAE,CAAC;IAC7C,MAAM,YAAY,GAAG,IAAI,sBAAsB,CAAC,WAAW,CAAC,CAAC;IAC7D,MAAM,MAAM,GAAG,IAAI,iBAAiB,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;IACjE,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;IACvB,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { HistoricalData, StockQuoteInput, StockQuoteResponse, StockSearchResult } from './types.js';
|
|
2
|
+
import type { YahooClient } from './yahooFinanceClient.js';
|
|
3
|
+
/**
|
|
4
|
+
* Service for fetching stock quotes from Yahoo Finance
|
|
5
|
+
*/
|
|
6
|
+
export declare class StockQuotesService {
|
|
7
|
+
private readonly yahooClient;
|
|
8
|
+
/**
|
|
9
|
+
* Create a new instance of the StockQuotesService
|
|
10
|
+
*/
|
|
11
|
+
constructor(yahooClient: YahooClient);
|
|
12
|
+
/**
|
|
13
|
+
* Fetch a stock quote for the given ticker symbol
|
|
14
|
+
* @param input - The stock quote input containing the ticker and optional fields
|
|
15
|
+
* @returns Promise<StockQuoteResponse> - The stock quote data
|
|
16
|
+
*/
|
|
17
|
+
getQuote(input: StockQuoteInput): Promise<StockQuoteResponse>;
|
|
18
|
+
/**
|
|
19
|
+
* Fetch multiple stock quotes at once
|
|
20
|
+
* @param tickers - Array of ticker symbols
|
|
21
|
+
* @returns Promise<Map<string, StockQuoteResponse>> - Map of ticker to stock quote data
|
|
22
|
+
*/
|
|
23
|
+
getMultipleQuotes(tickers: string[]): Promise<Map<string, StockQuoteResponse>>;
|
|
24
|
+
/**
|
|
25
|
+
* Search for a company by name or ticker
|
|
26
|
+
* @param query - Search query string
|
|
27
|
+
* @returns Promise<Array<{symbol: string, name: string, exchange: string}>> - Search results
|
|
28
|
+
*/
|
|
29
|
+
search(query: string): Promise<StockSearchResult[]>;
|
|
30
|
+
/**
|
|
31
|
+
* Fetches historical stock data for a given ticker, from a start date to an end date.
|
|
32
|
+
* @param ticker - Stock ticker symbol (e.g., AAPL)
|
|
33
|
+
* @param fromDate - Start date in 'YYYY-MM-DD' format
|
|
34
|
+
* @param toDate - End date in 'YYYY-MM-DD' format
|
|
35
|
+
* @returns Promise<number[]> - An array of closing prices for each day.
|
|
36
|
+
*/
|
|
37
|
+
getHistoricalData(ticker: string, fromDate: string, toDate: string): Promise<HistoricalData[]>;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=stockQuotesService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stockQuotesService.d.ts","sourceRoot":"","sources":["../src/stockQuotesService.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EAIlB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D;;GAEG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;IAE1C;;OAEG;gBACS,WAAW,EAAE,WAAW;IAIpC;;;;OAIG;IACG,QAAQ,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAC;IA8DnE;;;;OAIG;IACG,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAepF;;;;OAIG;IACG,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC;IA2BzD;;;;;;OAMG;IACG,iBAAiB,CACrB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,cAAc,EAAE,CAAC;CA6B7B"}
|