finmap-mcp 1.0.5

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 ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
package/README.md ADDED
@@ -0,0 +1,320 @@
1
+ # Finmap MCP Server
2
+
3
+ A Model Context Protocol (MCP) server that provides comprehensive financial market data from [finmap.org](https://finmap.org). Access historical market data for multiple global stock exchanges through a standardized MCP interface.
4
+
5
+ ## Features
6
+
7
+ - **Comprehensive Data**: Market capitalization, trading volume, price changes, sector analysis
8
+ - **Interactive Charts**: Direct links to finmap.org visualizations
9
+ - **Both Remote & Local**: Cloudflare Workers hosted server + npm package
10
+ - **Rich Metadata**: Company information, sector classifications, historical data
11
+
12
+ ## Supported Exchanges
13
+
14
+ | Exchange | Code | Country | Earliest Data |
15
+ |----------|------|---------|---------------|
16
+ | Moscow Exchange | `moex` | Russia | 2011-12-19 |
17
+ | New York Stock Exchange | `nyse` | USA | 2024-12-09 |
18
+ | NASDAQ | `nasdaq` | USA | 2024-12-09 |
19
+ | American Stock Exchange | `amex` | USA | 2024-12-09 |
20
+ | All US Markets | `us-all` | USA | 2024-12-09 |
21
+ | London Stock Exchange | `lse` | UK | 2025-02-07 |
22
+ | Borsa Istanbul | `bist` | Turkey | 2015-11-30 |
23
+
24
+ ## Installation & Usage
25
+
26
+ ### Option 1: Remote Server (Hosted)
27
+
28
+ Connect to our hosted MCP server without any installation:
29
+
30
+ **Server URL**: `https://mcp.finmap.org`
31
+
32
+ **Claude Desktop Configuration**:
33
+ ```json
34
+ {
35
+ "mcpServers": {
36
+ "finmap": {
37
+ "command": "npx",
38
+ "args": ["mcp-remote", "https://mcp.finmap.org"]
39
+ }
40
+ }
41
+ }
42
+ ```
43
+
44
+ ### Option 2: Local Package (npm)
45
+
46
+ Install and run locally for better performance and offline access:
47
+
48
+ ```bash
49
+ # Install globally
50
+ npm install -g finmap-mcp
51
+
52
+ # Or use directly
53
+ npx finmap-mcp
54
+ ```
55
+
56
+ **Claude Desktop Configuration**:
57
+ ```json
58
+ {
59
+ "mcpServers": {
60
+ "finmap": {
61
+ "command": "npx",
62
+ "args": ["finmap-mcp"]
63
+ }
64
+ }
65
+ }
66
+ ```
67
+
68
+ ## Available Tools
69
+
70
+ ### 1. `get-marketdata`
71
+ Get market overview with sector breakdown for any exchange.
72
+
73
+ **Parameters:**
74
+ - `stockExchange`: `"moex" | "nyse" | "nasdaq" | "amex" | "lse" | "bist" | "us-all"`
75
+ - `year`, `month`, `day` (optional): Specific date, defaults to latest
76
+
77
+ **Example Response:**
78
+ ```json
79
+ {
80
+ "date": "2025-08-19",
81
+ "exchange": "MOEX",
82
+ "marketTotal": {
83
+ "name": "Moscow Exchange",
84
+ "marketCap": 56179679584186.7,
85
+ "marketCapChangePct": -0.62,
86
+ "volume": 31210807020,
87
+ "value": 138591002400,
88
+ "numTrades": 3433146,
89
+ "itemsPerSector": 460
90
+ },
91
+ "sectors": [
92
+ {
93
+ "name": "Finance",
94
+ "marketCap": 11302744020274.61,
95
+ "marketCapChangePct": -0.41,
96
+ "volume": 246255138,
97
+ "value": 30553933296,
98
+ "numTrades": 465750,
99
+ "itemsPerSector": 30
100
+ }
101
+ ],
102
+ "charts": {
103
+ "histogram": "https://finmap.org/?chartType=histogram&dataType=marketcap&exchange=moex",
104
+ "treemap": "https://finmap.org/?chartType=treemap&dataType=marketcap&exchange=moex&date=2025-08-19"
105
+ }
106
+ }
107
+ ```
108
+
109
+ ### 2. `get-tickers`
110
+ List all available company tickers for an exchange with optional sector filtering.
111
+
112
+ **Parameters:**
113
+ - `stockExchange`: Exchange identifier
114
+ - `englishNames`: `true` (default) | `false` - Use English or original company names
115
+ - `sector` (optional): Filter by specific sector
116
+
117
+ ### 3. `get-marketdata-by-ticker`
118
+ Get detailed information for a specific company ticker.
119
+
120
+ **Parameters:**
121
+ - `stockExchange`: Exchange identifier
122
+ - `ticker`: Company ticker symbol (case-sensitive)
123
+ - `year`, `month`, `day` (optional): Historical date
124
+
125
+ **Example Response:**
126
+ ```json
127
+ {
128
+ "exchange": "MOEX",
129
+ "country": "",
130
+ "type": "",
131
+ "sector": "Finance",
132
+ "industry": "",
133
+ "currencyId": "",
134
+ "ticker": "T",
135
+ "nameEng": "IPJSC TCS Holding",
136
+ "nameEngShort": "",
137
+ "nameOriginal": "ТКС Холдинг МКПАО ао",
138
+ "nameOriginalShort": "ТКСХолд ао",
139
+ "priceOpen": 3406.2,
140
+ "priceLastSale": 3404.8,
141
+ "priceChangePct": -0.04,
142
+ "volume": 3720294,
143
+ "value": 12722573698,
144
+ "numTrades": 96979,
145
+ "marketCap": 914012195902,
146
+ "listedFrom": "2024-11-27",
147
+ "listedTill": "",
148
+ "wikiPageIdEng": "51138388\r",
149
+ "wikiPageIdOriginal": "3124277",
150
+ "itemsPerSector": 0
151
+ }
152
+ ```
153
+
154
+ ### 4. `get-top-marketdata`
155
+ Get top performing companies sorted by various metrics.
156
+
157
+ **Parameters:**
158
+ - `stockExchange`: Exchange identifier
159
+ - `sortBy`: `"marketCap" | "priceChangePct" | "volume" | "value" | "numTrades"`
160
+ - `order`: `"desc" | "asc"` (default: desc)
161
+ - `limit`: Number of results (1-500, default: 10)
162
+
163
+ **Example Response:**
164
+
165
+ ```json
166
+ {
167
+ "date": "2025-08-19",
168
+ "exchange": "NASDAQ",
169
+ "sortBy": "marketCap",
170
+ "order": "desc",
171
+ "limit": 3,
172
+ "count": 3,
173
+ "filteredSecurities": [
174
+ {
175
+ "ticker": "NVDA",
176
+ "name": "NVIDIA Corporation Common Stock",
177
+ "sector": "Technology",
178
+ "priceLastSale": 175.64,
179
+ "priceChangePct": -3.5,
180
+ "marketCap": 4285616000000,
181
+ "volume": 183881555,
182
+ "value": 0,
183
+ "numTrades": 0
184
+ },
185
+ {
186
+ "ticker": "MSFT",
187
+ "name": "Microsoft Corporation Common Stock",
188
+ "sector": "Technology",
189
+ "priceLastSale": 509.77,
190
+ "priceChangePct": -1.418,
191
+ "marketCap": 3789205225023,
192
+ "volume": 21116203,
193
+ "value": 0,
194
+ "numTrades": 0
195
+ },
196
+ {
197
+ "ticker": "AAPL",
198
+ "name": "Apple Inc. Common Stock",
199
+ "sector": "Technology",
200
+ "priceLastSale": 230.56,
201
+ "priceChangePct": -0.143,
202
+ "marketCap": 3421600318400,
203
+ "volume": 37671194,
204
+ "value": 0,
205
+ "numTrades": 0
206
+ }
207
+ ]
208
+ }
209
+ ```
210
+
211
+ ### 5. `get-company-info`
212
+ Get detailed company information including business description (US market only).
213
+
214
+ **Parameters:**
215
+ - `stockExchange`: `"nasdaq" | "nyse" | "amex"`
216
+ - `ticker`: Company ticker symbol
217
+
218
+ **Example Response:**
219
+
220
+ ```json
221
+ {
222
+ "ModuleTitle": {
223
+ "label": "Module Title",
224
+ "value": "Company Description"
225
+ },
226
+ "CompanyName": {
227
+ "label": "Company Name",
228
+ "value": "Sprouts Farmers Market, Inc."
229
+ },
230
+ "Symbol": {
231
+ "label": "Symbol",
232
+ "value": "SFM"
233
+ },
234
+ "Address": {
235
+ "label": "Address",
236
+ "value": "5455 EAST HIGH STREET,SUITE 111, PHOENIX, Arizona, 85054, United States"
237
+ },
238
+ "Phone": {
239
+ "label": "Phone",
240
+ "value": "+1 480 814-8016"
241
+ },
242
+ "Industry": {
243
+ "label": "Industry",
244
+ "value": "Food Chains"
245
+ },
246
+ "Sector": {
247
+ "label": "Sector",
248
+ "value": "Consumer Staples"
249
+ },
250
+ "Region": {
251
+ "label": "Region",
252
+ "value": "North America"
253
+ },
254
+ "CompanyDescription": {
255
+ "label": "Company Description",
256
+ "value": "Sprouts Farmers Market is an American specialty grocer offering an assortment highlighting fresh and naturally derived products. Its offerings are especially focused on produce, which constituted around 21% of sales in fiscal 2021. Founded in 2002, the chain is most heavily concentrated in California, which accounted for over one third of its 374 stores as of the end of fiscal 2021. All of the company's operations are in the United States, with its stores largely located in the southern half of the country. The firm sells roughly 20,000 products (of which around 70% are attribute driven, such as organic, plant-based, or catering to the keto or paleo diet), with private-label products accounting for about 16% of sales in fiscal 2021. Perishable items accounted for 58% of fiscal 2021 sales."
257
+ },
258
+ "CompanyUrl": {
259
+ "label": "Company Url",
260
+ "value": "https://www.sprouts.com"
261
+ },
262
+ "KeyExecutives": {
263
+ "label": "Key Executives",
264
+ "value": [
265
+ {
266
+ "name": "Jack Loudon Sinclair",
267
+ "title": "Chief Executive Officer & Director"
268
+ },
269
+ {
270
+ "name": "James Bahrenburg",
271
+ "title": "Chief Technology Officer"
272
+ },
273
+ {
274
+ "name": "Nicholas Konat",
275
+ "title": "President & Chief Operating Officer"
276
+ }
277
+ ]
278
+ }
279
+ },
280
+ "message": null,
281
+ "status": {
282
+ "rCode": 200,
283
+ "bCodeMessage": null,
284
+ "developerMessage": null
285
+ }
286
+ }
287
+ ```
288
+
289
+ ## Example Prompts
290
+
291
+ ### Market Analysis
292
+ > "Get the current market data for MOEX and show me the top 3 sectors by market cap"
293
+
294
+ > "Compare the top 10 companies by market cap on NYSE vs NASDAQ"
295
+
296
+ > "Show me all energy sector companies on MOEX with their current prices"
297
+
298
+ ### Historical Data
299
+ > "Get GAZP stock data for December 15, 2024"
300
+
301
+ > "Show me the market performance of BIST for the last trading day of 2024"
302
+
303
+ ### Sector Research
304
+ > "List all technology companies on NASDAQ and sort them by trading volume"
305
+
306
+ > "Get detailed information about Apple (AAPL) including company description"
307
+
308
+ ### Interactive Exploration
309
+ > "Show me a treemap visualization of MOEX market cap by sector"
310
+
311
+ > "Get the histogram view of market cap distribution for US markets"
312
+
313
+
314
+ ## Data Provider
315
+
316
+ Data is sourced from [finmap.org](https://finmap.org) - an interactive platform for financial market visualization and analysis.
317
+
318
+ - **Website**: https://finmap.org
319
+ - **GitHub**: https://github.com/finmap-org
320
+ - **Donate**: [Patreon](https://patreon.com/finmap) | [Boosty](https://boosty.to/finmap)
package/dist/core.js ADDED
@@ -0,0 +1,471 @@
1
+ import { z } from "zod";
2
+ const BASE_URL = "https://finmap.org";
3
+ const DATA_BASE_URL = "https://raw.githubusercontent.com/finmap-org";
4
+ const INFO = {
5
+ provider: "finmap.org",
6
+ description: "Discover interactive stock charts and curated news at finmap.org",
7
+ github: "https://github.com/finmap-org",
8
+ donate: {
9
+ patreon: "https://patreon.com/finmap",
10
+ boosty: "https://boosty.to/finmap",
11
+ },
12
+ issues: "https://github.com/finmap-org/mcp-server/issues",
13
+ feedback: "contact@finmap.org",
14
+ };
15
+ const INDICES = {
16
+ EXCHANGE: 0,
17
+ COUNTRY: 1,
18
+ TYPE: 2,
19
+ SECTOR: 3,
20
+ INDUSTRY: 4,
21
+ CURRENCY_ID: 5,
22
+ TICKER: 6,
23
+ NAME_ENG: 7,
24
+ NAME_ENG_SHORT: 8,
25
+ NAME_ORIGINAL: 9,
26
+ NAME_ORIGINAL_SHORT: 10,
27
+ PRICE_OPEN: 11,
28
+ PRICE_LAST_SALE: 12,
29
+ PRICE_CHANGE_PCT: 13,
30
+ VOLUME: 14,
31
+ VALUE: 15,
32
+ NUM_TRADES: 16,
33
+ MARKET_CAP: 17,
34
+ LISTED_FROM: 18,
35
+ LISTED_TILL: 19,
36
+ WIKI_PAGE_ID_ENG: 20,
37
+ WIKI_PAGE_ID_ORIGINAL: 21,
38
+ ITEMS_PER_SECTOR: 22,
39
+ };
40
+ const EXCHANGE_TO_COUNTRY_MAP = {
41
+ amex: "us",
42
+ nasdaq: "us",
43
+ nyse: "us",
44
+ "us-all": "us",
45
+ lse: "uk",
46
+ moex: "russia",
47
+ bist: "turkey",
48
+ };
49
+ const MIN_AVAILABLE_DATES = {
50
+ amex: "2024-12-09",
51
+ nasdaq: "2024-12-09",
52
+ nyse: "2024-12-09",
53
+ "us-all": "2024-12-09",
54
+ lse: "2025-02-07",
55
+ moex: "2011-12-19",
56
+ bist: "2015-11-30",
57
+ };
58
+ const commonInputSchema = {
59
+ stockExchange: z
60
+ .enum(["amex", "nasdaq", "nyse", "us-all", "lse", "moex", "bist"])
61
+ .describe(`Stock exchange identifier:
62
+ amex - American Stock Exchange;
63
+ nasdaq - Nasdaq;
64
+ nyse - New York Stock Exchange;
65
+ us-all - AmEx, Nasdaq and NYSE combined;
66
+ lse - London Stock Exchange;
67
+ moex - Moscow Exchange;
68
+ bist - Borsa Istanbul (Turkish Stock Exchange)`),
69
+ year: z.number().int().min(2012).optional(),
70
+ month: z.number().int().min(1).max(12).optional(),
71
+ day: z.number().int().min(1).max(31).optional(),
72
+ };
73
+ function buildDateString(year, month, day) {
74
+ const currentDate = new Date();
75
+ const y = year ?? currentDate.getFullYear();
76
+ const m = month ?? currentDate.getMonth() + 1;
77
+ const d = day ?? currentDate.getDate();
78
+ return `${y.toString()}/${m.toString().padStart(2, "0")}/${d.toString().padStart(2, "0")}`;
79
+ }
80
+ function validateAndFormatDate(dateString) {
81
+ const formattedDate = dateString.replaceAll("/", "-");
82
+ z.string().date().parse(formattedDate);
83
+ const dayOfWeek = new Date(formattedDate).getDay();
84
+ if (dayOfWeek === 0 || dayOfWeek === 6) {
85
+ throw new Error("Data is only available for work days (Monday to Friday)");
86
+ }
87
+ return formattedDate;
88
+ }
89
+ async function fetchMarketData(stockExchange, formattedDate) {
90
+ const country = EXCHANGE_TO_COUNTRY_MAP[stockExchange];
91
+ const date = formattedDate.replaceAll("-", "/");
92
+ const url = `${DATA_BASE_URL}/data-${country}/refs/heads/main/marketdata/${date}/${stockExchange}.json`;
93
+ const response = await fetch(url);
94
+ if (response.status === 404) {
95
+ throw new Error(`Not found, try another date. The date must be on or after ${MIN_AVAILABLE_DATES[stockExchange]} for ${stockExchange}`);
96
+ }
97
+ return response.json();
98
+ }
99
+ async function fetchSecurityInfo(exchange, ticker) {
100
+ const firstLetter = ticker.charAt(0).toUpperCase();
101
+ const url = `${DATA_BASE_URL}/data-us/refs/heads/main/securities/${exchange}/${firstLetter}/${ticker}.json`;
102
+ const response = await fetch(url);
103
+ if (response.status === 404) {
104
+ throw new Error(`Security ${ticker} not found on ${exchange}`);
105
+ }
106
+ const data = (await response.json());
107
+ return data;
108
+ }
109
+ export function registerFinmapTools(server) {
110
+ server.registerResource("minimum-dates", "finmap://minimum-dates", {
111
+ title: "Minimum date for stock exchange",
112
+ description: "Earliest available dates for each exchange",
113
+ mimeType: "application/json",
114
+ }, async () => {
115
+ return {
116
+ contents: [
117
+ {
118
+ uri: "finmap://minimum-dates",
119
+ text: JSON.stringify(MIN_AVAILABLE_DATES, null, 2),
120
+ },
121
+ ],
122
+ };
123
+ });
124
+ server.registerTool("get-marketdata", {
125
+ title: "Get Marketdata",
126
+ description: "Get the market capitalization, volume, value and number of trades for the entire market and for each sector on a given date. If date is not provided, returns the latest available data",
127
+ inputSchema: commonInputSchema,
128
+ }, async ({ stockExchange, year, month, day, }) => {
129
+ try {
130
+ const dateString = buildDateString(year, month, day);
131
+ const formattedDate = validateAndFormatDate(dateString);
132
+ const marketDataResponse = await fetchMarketData(stockExchange, formattedDate);
133
+ const sectorItems = marketDataResponse.securities.data.filter((securityItem) => securityItem[INDICES.TYPE] === "sector");
134
+ const result = {
135
+ info: INFO,
136
+ charts: {
137
+ histogram: `${BASE_URL}/?chartType=histogram&dataType=marketcap&exchange=${stockExchange}`,
138
+ treemap: `${BASE_URL}/?chartType=treemap&dataType=marketcap&exchange=${stockExchange}&date=${formattedDate}`,
139
+ },
140
+ date: formattedDate,
141
+ exchange: stockExchange.toUpperCase(),
142
+ descriptions: {
143
+ marketCap: "Market capitalization - total value of all shares outstanding",
144
+ marketCapChangePct: "Percentage change in market capitalization from previous period",
145
+ volume: "Trading volume - total number of shares traded",
146
+ value: "Trading value - total monetary value of shares traded",
147
+ numTrades: "Number of trades - total count of executed trades",
148
+ itemsPerSector: "Number of items in the sector",
149
+ },
150
+ marketTotal: {},
151
+ sectors: [],
152
+ };
153
+ sectorItems.forEach((sectorItem) => {
154
+ const sectorData = {
155
+ name: sectorItem[INDICES.TICKER],
156
+ marketCap: sectorItem[INDICES.MARKET_CAP],
157
+ marketCapChangePct: sectorItem[INDICES.PRICE_CHANGE_PCT],
158
+ volume: sectorItem[INDICES.VOLUME],
159
+ value: sectorItem[INDICES.VALUE],
160
+ numTrades: sectorItem[INDICES.NUM_TRADES],
161
+ itemsPerSector: sectorItem[INDICES.ITEMS_PER_SECTOR],
162
+ };
163
+ if (sectorItem[INDICES.SECTOR] === "") {
164
+ result.marketTotal = sectorData;
165
+ }
166
+ else {
167
+ result.sectors.push(sectorData);
168
+ }
169
+ });
170
+ return {
171
+ content: [
172
+ {
173
+ type: "text",
174
+ text: JSON.stringify(result, null, 2),
175
+ },
176
+ ],
177
+ };
178
+ }
179
+ catch (error) {
180
+ return {
181
+ content: [
182
+ {
183
+ type: "text",
184
+ text: `ERROR: ${error instanceof Error ? error.message : String(error)}`,
185
+ },
186
+ ],
187
+ };
188
+ }
189
+ });
190
+ server.registerTool("get-tickers", {
191
+ title: "Get Tickers",
192
+ description: "Get tickers and company names on a given date. If date is not provided, returns the latest available data",
193
+ inputSchema: {
194
+ ...commonInputSchema,
195
+ englishNames: z
196
+ .boolean()
197
+ .default(true)
198
+ .optional()
199
+ .describe(`If false, returns the original company names instead of the English ones`),
200
+ sector: z
201
+ .string()
202
+ .optional()
203
+ .describe(`If provided, filters the results to the specified sector`),
204
+ },
205
+ }, async ({ stockExchange, year, month, day, englishNames, sector, }) => {
206
+ try {
207
+ const dateString = buildDateString(year, month, day);
208
+ const formattedDate = validateAndFormatDate(dateString);
209
+ const marketDataResponse = await fetchMarketData(stockExchange, formattedDate);
210
+ const tickersResult = {
211
+ date: formattedDate,
212
+ exchange: stockExchange.toUpperCase(),
213
+ sector: sector || "all",
214
+ englishNames: englishNames ?? true,
215
+ itemsPerSector: 0,
216
+ sectors: {},
217
+ };
218
+ const result = {
219
+ info: INFO,
220
+ charts: {
221
+ histogram: `${BASE_URL}/?chartType=histogram&dataType=marketcap&exchange=${stockExchange}`,
222
+ treemap: `${BASE_URL}/?chartType=treemap&dataType=marketcap&exchange=${stockExchange}&date=${formattedDate}`,
223
+ },
224
+ ...tickersResult,
225
+ };
226
+ const filteredSecurities = marketDataResponse.securities.data.filter((securityItem) => securityItem[INDICES.TYPE] !== "sector" &&
227
+ securityItem[INDICES.SECTOR] !== "" &&
228
+ (!sector || securityItem[INDICES.SECTOR] === sector));
229
+ const groupedBySector = filteredSecurities.reduce((accumulator, securityItem) => {
230
+ const sectorName = securityItem[INDICES.SECTOR];
231
+ if (!accumulator[sectorName])
232
+ accumulator[sectorName] = [];
233
+ accumulator[sectorName].push(securityItem);
234
+ return accumulator;
235
+ }, {});
236
+ for (const [sectorName, sectorSecurities] of Object.entries(groupedBySector)) {
237
+ const validTickerPairs = sectorSecurities
238
+ .map((securityItem) => {
239
+ const ticker = securityItem[INDICES.TICKER];
240
+ const companyName = englishNames
241
+ ? securityItem[INDICES.NAME_ENG]
242
+ : securityItem[INDICES.NAME_ORIGINAL_SHORT] ||
243
+ securityItem[INDICES.NAME_ENG];
244
+ return ticker && companyName
245
+ ? [ticker, companyName]
246
+ : null;
247
+ })
248
+ .filter((entry) => entry !== null)
249
+ .sort(([a], [b]) => a.localeCompare(b));
250
+ const tickersMap = Object.fromEntries(validTickerPairs);
251
+ if (Object.keys(tickersMap).length > 0) {
252
+ result.sectors[sectorName] = {
253
+ count: Object.keys(tickersMap).length,
254
+ tickers: tickersMap,
255
+ };
256
+ result.itemsPerSector += Object.keys(tickersMap).length;
257
+ }
258
+ }
259
+ return {
260
+ content: [
261
+ {
262
+ type: "text",
263
+ text: JSON.stringify(result, null, 2),
264
+ },
265
+ ],
266
+ };
267
+ }
268
+ catch (error) {
269
+ return {
270
+ content: [
271
+ {
272
+ type: "text",
273
+ text: `ERROR: ${error instanceof Error ? error.message : String(error)}`,
274
+ },
275
+ ],
276
+ };
277
+ }
278
+ });
279
+ server.registerTool("get-marketdata-by-ticker", {
280
+ title: "Get Market Data by Ticker",
281
+ description: "Get market data for a specific ticker on a given date",
282
+ inputSchema: {
283
+ ...commonInputSchema,
284
+ ticker: z
285
+ .string()
286
+ .describe("The ticker symbol to get market data for. Case-sensitive"),
287
+ },
288
+ }, async ({ stockExchange, year, month, day, ticker, }) => {
289
+ try {
290
+ const dateString = buildDateString(year, month, day);
291
+ const formattedDate = validateAndFormatDate(dateString);
292
+ const marketDataResponse = await fetchMarketData(stockExchange, formattedDate);
293
+ const marketData = marketDataResponse.securities.data.find((securityItem) => securityItem[INDICES.TYPE] !== "sector" &&
294
+ securityItem[INDICES.TICKER] === ticker);
295
+ if (!marketData) {
296
+ throw new Error(`Ticker ${ticker} not found on ${stockExchange} for date ${formattedDate}`);
297
+ }
298
+ const result = {
299
+ info: INFO,
300
+ charts: {
301
+ histogram: `${BASE_URL}/?chartType=histogram&dataType=marketcap&exchange=${stockExchange}`,
302
+ treemap: `${BASE_URL}/?chartType=treemap&dataType=marketcap&exchange=${stockExchange}&date=${formattedDate}`,
303
+ },
304
+ exchange: marketData[INDICES.EXCHANGE],
305
+ country: marketData[INDICES.COUNTRY],
306
+ type: marketData[INDICES.TYPE],
307
+ sector: marketData[INDICES.SECTOR],
308
+ industry: marketData[INDICES.INDUSTRY],
309
+ currencyId: marketData[INDICES.CURRENCY_ID],
310
+ ticker: marketData[INDICES.TICKER],
311
+ nameEng: marketData[INDICES.NAME_ENG],
312
+ nameEngShort: marketData[INDICES.NAME_ENG_SHORT],
313
+ nameOriginal: marketData[INDICES.NAME_ORIGINAL],
314
+ nameOriginalShort: marketData[INDICES.NAME_ORIGINAL_SHORT],
315
+ priceOpen: marketData[INDICES.PRICE_OPEN],
316
+ priceLastSale: marketData[INDICES.PRICE_LAST_SALE],
317
+ priceChangePct: marketData[INDICES.PRICE_CHANGE_PCT],
318
+ volume: marketData[INDICES.VOLUME],
319
+ value: marketData[INDICES.VALUE],
320
+ numTrades: marketData[INDICES.NUM_TRADES],
321
+ marketCap: marketData[INDICES.MARKET_CAP],
322
+ listedFrom: marketData[INDICES.LISTED_FROM],
323
+ listedTill: marketData[INDICES.LISTED_TILL],
324
+ wikiPageIdEng: marketData[INDICES.WIKI_PAGE_ID_ENG],
325
+ wikiPageIdOriginal: marketData[INDICES.WIKI_PAGE_ID_ORIGINAL],
326
+ itemsPerSector: marketData[INDICES.ITEMS_PER_SECTOR],
327
+ };
328
+ return {
329
+ content: [
330
+ {
331
+ type: "text",
332
+ text: JSON.stringify(result, null, 2),
333
+ },
334
+ ],
335
+ };
336
+ }
337
+ catch (error) {
338
+ return {
339
+ content: [
340
+ {
341
+ type: "text",
342
+ text: `ERROR: ${error instanceof Error ? error.message : String(error)}`,
343
+ },
344
+ ],
345
+ };
346
+ }
347
+ });
348
+ server.registerTool("get-top-marketdata", {
349
+ title: "Get Top Market Data",
350
+ description: "Get top N market data items sorted by specified field and order. Excludes sector-level data",
351
+ inputSchema: {
352
+ ...commonInputSchema,
353
+ sortBy: z
354
+ .enum(["priceChangePct", "marketCap", "value", "volume", "numTrades"])
355
+ .describe(`marketCap: Market capitalization - total value of all shares outstanding;
356
+ priceChangePct: Percentage change in share price from previous trading session;
357
+ volume: Trading volume - total number of shares traded;
358
+ value: Trading value - total monetary value of shares traded;
359
+ numTrades: Number of trades - total count of executed trades;
360
+ itemsPerSector: Number of items in the sector`),
361
+ order: z.enum(["asc", "desc"]).default("desc").describe("Sort order"),
362
+ limit: z
363
+ .number()
364
+ .int()
365
+ .min(1)
366
+ .max(500)
367
+ .default(10)
368
+ .describe("Number of items to return"),
369
+ },
370
+ }, async ({ stockExchange, year, month, day, sortBy, order, limit, }) => {
371
+ try {
372
+ const dateString = buildDateString(year, month, day);
373
+ const formattedDate = validateAndFormatDate(dateString);
374
+ const marketDataResponse = await fetchMarketData(stockExchange, formattedDate);
375
+ const filteredSecurities = marketDataResponse.securities.data
376
+ .filter((securityItem) => securityItem[INDICES.TYPE] !== "sector" &&
377
+ securityItem[INDICES.SECTOR] !== "")
378
+ .map((securityItem) => ({
379
+ ticker: securityItem[INDICES.TICKER],
380
+ name: securityItem[INDICES.NAME_ENG],
381
+ sector: securityItem[INDICES.SECTOR],
382
+ priceLastSale: securityItem[INDICES.PRICE_LAST_SALE],
383
+ priceChangePct: securityItem[INDICES.PRICE_CHANGE_PCT],
384
+ marketCap: securityItem[INDICES.MARKET_CAP],
385
+ volume: securityItem[INDICES.VOLUME],
386
+ value: securityItem[INDICES.VALUE],
387
+ numTrades: securityItem[INDICES.NUM_TRADES],
388
+ }))
389
+ .sort((a, b) => {
390
+ const aVal = a[sortBy];
391
+ const bVal = b[sortBy];
392
+ return order === "desc" ? bVal - aVal : aVal - bVal;
393
+ })
394
+ .slice(0, limit || 10);
395
+ const result = {
396
+ info: INFO,
397
+ charts: {
398
+ histogram: `${BASE_URL}/?chartType=histogram&dataType=marketcap&exchange=${stockExchange}`,
399
+ treemap: `${BASE_URL}/?chartType=treemap&dataType=marketcap&exchange=${stockExchange}&date=${formattedDate}`,
400
+ },
401
+ date: formattedDate,
402
+ exchange: stockExchange.toUpperCase(),
403
+ sortBy: sortBy,
404
+ order: order || "desc",
405
+ limit: limit || 10,
406
+ count: filteredSecurities.length,
407
+ filteredSecurities,
408
+ };
409
+ return {
410
+ content: [
411
+ {
412
+ type: "text",
413
+ text: JSON.stringify(result, null, 2),
414
+ },
415
+ ],
416
+ };
417
+ }
418
+ catch (error) {
419
+ return {
420
+ content: [
421
+ {
422
+ type: "text",
423
+ text: `ERROR: ${error instanceof Error ? error.message : String(error)}`,
424
+ },
425
+ ],
426
+ };
427
+ }
428
+ });
429
+ server.registerTool("get-company-info", {
430
+ title: "Get Company Description",
431
+ description: "Get detailed information for a US company by provided ticker (NASDAQ, NYSE, AMEX only)",
432
+ inputSchema: {
433
+ exchange: z
434
+ .enum(["nasdaq", "nyse", "amex"])
435
+ .describe("US exchange identifier"),
436
+ ticker: z
437
+ .string()
438
+ .describe("The ticker symbol to get information for. Case-sensitive"),
439
+ },
440
+ }, async ({ exchange, ticker }) => {
441
+ try {
442
+ const securityInfo = await fetchSecurityInfo(exchange, ticker);
443
+ const result = {
444
+ info: INFO,
445
+ charts: {
446
+ histogram: `${BASE_URL}/?chartType=histogram&dataType=marketcap&exchange=${exchange}`,
447
+ treemap: `${BASE_URL}/?chartType=treemap&dataType=marketcap&exchange=${exchange}`,
448
+ },
449
+ ...securityInfo,
450
+ };
451
+ return {
452
+ content: [
453
+ {
454
+ type: "text",
455
+ text: JSON.stringify(result, null, 2),
456
+ },
457
+ ],
458
+ };
459
+ }
460
+ catch (error) {
461
+ return {
462
+ content: [
463
+ {
464
+ type: "text",
465
+ text: `ERROR: ${error instanceof Error ? error.message : String(error)}`,
466
+ },
467
+ ],
468
+ };
469
+ }
470
+ });
471
+ }
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ import { registerFinmapTools } from "./core.js";
3
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
4
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
5
+ const server = new McpServer({
6
+ name: "finmap-mcp",
7
+ version: "1.0.0",
8
+ });
9
+ registerFinmapTools(server);
10
+ const transport = new StdioServerTransport();
11
+ await server.connect(transport);
package/package.json ADDED
@@ -0,0 +1,88 @@
1
+ {
2
+ "name": "finmap-mcp",
3
+ "version": "1.0.5",
4
+ "description": "MCP server providing financial market data from finmap.org",
5
+ "main": "./dist/stdio-server.js",
6
+ "type": "module",
7
+ "bin": {
8
+ "finmap-mcp": "./dist/stdio-server.js"
9
+ },
10
+ "files": [
11
+ "dist/core.js",
12
+ "dist/stdio-server.js",
13
+ "README.md",
14
+ "LICENSE"
15
+ ],
16
+ "keywords": [
17
+ "agent",
18
+ "agentic",
19
+ "ai",
20
+ "financial-data",
21
+ "historical-data",
22
+ "llm",
23
+ "market-capitalization",
24
+ "market-data",
25
+ "market-sectors",
26
+ "market-value",
27
+ "mcp",
28
+ "mcp-server",
29
+ "modelcontextprotocol",
30
+ "stock-exchange",
31
+ "stock-market",
32
+ "stock-price-data",
33
+ "tickers"
34
+ ],
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "https://github.com/finmap-org/mcp-server.git"
38
+ },
39
+ "homepage": "https://github.com/finmap-org/mcp-server#readme",
40
+ "bugs": {
41
+ "url": "https://github.com/finmap-org/mcp-server/issues"
42
+ },
43
+ "author": {
44
+ "name": "finmap.org",
45
+ "email": "contact@finmap.org",
46
+ "url": "https://finmap.org"
47
+ },
48
+ "license": "LGPL-3.0-or-later",
49
+ "funding": [
50
+ {
51
+ "type": "patreon",
52
+ "url": "https://patreon.com/finmap"
53
+ },
54
+ "https://boosty.to/finmap"
55
+ ],
56
+ "engines": {
57
+ "node": ">=18.0.0"
58
+ },
59
+ "scripts": {
60
+ "clean": "rimraf dist",
61
+ "build": "npm run clean && npm run build:stdio && npm run build:worker",
62
+ "build:stdio": "npm run clean && tsc --project tsconfig.stdio.json",
63
+ "build:worker": "wrangler build",
64
+ "dev:stdio": "tsx src/stdio-server.ts",
65
+ "dev:worker": "wrangler dev",
66
+ "deploy": "wrangler deploy",
67
+ "format": "biome format --write",
68
+ "lint:fix": "biome lint --fix",
69
+ "start": "wrangler dev",
70
+ "cf-typegen": "wrangler types",
71
+ "type-check": "tsc --noEmit",
72
+ "prepublishOnly": "npm run build:stdio",
73
+ "package": "npm run build:stdio && npm pack --pack-destination dist"
74
+ },
75
+ "dependencies": {
76
+ "@modelcontextprotocol/sdk": "1.17.3",
77
+ "agents": "^0.0.113",
78
+ "zod": "^3.25.76"
79
+ },
80
+ "devDependencies": {
81
+ "@biomejs/biome": "^2.2.0",
82
+ "@types/node": "^24.3.0",
83
+ "rimraf": "^6.0.1",
84
+ "tsx": "^4.20.4",
85
+ "typescript": "5.9.2",
86
+ "wrangler": "^4.30.0"
87
+ }
88
+ }