openmarkets 0.1.0.dev118__tar.gz → 0.1.0.dev119__tar.gz
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.
- {openmarkets-0.1.0.dev118 → openmarkets-0.1.0.dev119}/PKG-INFO +27 -24
- {openmarkets-0.1.0.dev118 → openmarkets-0.1.0.dev119}/README.md +2 -2
- {openmarkets-0.1.0.dev118 → openmarkets-0.1.0.dev119}/pyproject.toml +31 -35
- openmarkets-0.1.0.dev119/src/openmarkets/__init__.py +8 -0
- openmarkets-0.1.0.dev119/src/openmarkets/__main__.py +13 -0
- openmarkets-0.1.0.dev119/src/openmarkets/core/__init__.py +8 -0
- openmarkets-0.1.0.dev119/src/openmarkets/core/config.py +90 -0
- openmarkets-0.1.0.dev119/src/openmarkets/core/exceptions.py +22 -0
- openmarkets-0.1.0.dev119/src/openmarkets/core/fastmcp.py +79 -0
- openmarkets-0.1.0.dev119/src/openmarkets/core/serializers.py +52 -0
- openmarkets-0.1.0.dev119/src/openmarkets/core/server.py +87 -0
- openmarkets-0.1.0.dev119/src/openmarkets/core/toolset.py +120 -0
- openmarkets-0.1.0.dev119/src/openmarkets/core/types.py +11 -0
- openmarkets-0.1.0.dev119/src/openmarkets/schemas/analysis.py +104 -0
- openmarkets-0.1.0.dev119/src/openmarkets/schemas/company.py +15 -0
- openmarkets-0.1.0.dev119/src/openmarkets/schemas/financials.py +457 -0
- openmarkets-0.1.0.dev119/src/openmarkets/schemas/funds.py +197 -0
- openmarkets-0.1.0.dev119/src/openmarkets/schemas/holdings.py +122 -0
- openmarkets-0.1.0.dev119/src/openmarkets/schemas/markets.py +73 -0
- openmarkets-0.1.0.dev119/src/openmarkets/schemas/options.py +161 -0
- openmarkets-0.1.0.dev119/src/openmarkets/schemas/sector_industry.py +334 -0
- openmarkets-0.1.0.dev119/src/openmarkets/schemas/stock.py +358 -0
- openmarkets-0.1.0.dev119/src/openmarkets/schemas/technical_analysis.py +34 -0
- openmarkets-0.1.0.dev119/src/openmarkets/services/yfinance/analysis.py +114 -0
- openmarkets-0.1.0.dev119/src/openmarkets/services/yfinance/financials.py +111 -0
- openmarkets-0.1.0.dev119/src/openmarkets/services/yfinance/funds.py +149 -0
- openmarkets-0.1.0.dev119/src/openmarkets/services/yfinance/holdings.py +82 -0
- openmarkets-0.1.0.dev119/src/openmarkets/services/yfinance/markets.py +31 -0
- openmarkets-0.1.0.dev119/src/openmarkets/services/yfinance/options.py +201 -0
- openmarkets-0.1.0.dev119/src/openmarkets/services/yfinance/sector_industry.py +195 -0
- openmarkets-0.1.0.dev119/src/openmarkets/services/yfinance/stock.py +204 -0
- openmarkets-0.1.0.dev119/src/openmarkets/services/yfinance/technical_analysis.py +128 -0
- {openmarkets-0.1.0.dev118 → openmarkets-0.1.0.dev119}/src/openmarkets/tools/__init__.py +0 -3
- {openmarkets-0.1.0.dev118 → openmarkets-0.1.0.dev119}/src/openmarkets/tools/analyst_data.py +2 -2
- {openmarkets-0.1.0.dev118 → openmarkets-0.1.0.dev119}/src/openmarkets/tools/calendar.py +13 -5
- {openmarkets-0.1.0.dev118 → openmarkets-0.1.0.dev119}/src/openmarkets/tools/corporate_actions.py +16 -12
- {openmarkets-0.1.0.dev118 → openmarkets-0.1.0.dev119}/src/openmarkets/tools/crypto.py +3 -4
- {openmarkets-0.1.0.dev118 → openmarkets-0.1.0.dev119}/src/openmarkets/tools/extended_market.py +5 -6
- {openmarkets-0.1.0.dev118 → openmarkets-0.1.0.dev119}/src/openmarkets/tools/financial_statements.py +2 -2
- {openmarkets-0.1.0.dev118 → openmarkets-0.1.0.dev119}/src/openmarkets/tools/funds.py +12 -5
- {openmarkets-0.1.0.dev118 → openmarkets-0.1.0.dev119}/src/openmarkets/tools/historical_data.py +2 -2
- {openmarkets-0.1.0.dev118 → openmarkets-0.1.0.dev119}/src/openmarkets/tools/market_data.py +3 -4
- {openmarkets-0.1.0.dev118 → openmarkets-0.1.0.dev119}/src/openmarkets/tools/news.py +24 -5
- {openmarkets-0.1.0.dev118 → openmarkets-0.1.0.dev119}/src/openmarkets/tools/options.py +6 -7
- {openmarkets-0.1.0.dev118 → openmarkets-0.1.0.dev119}/src/openmarkets/tools/screener.py +10 -11
- openmarkets-0.1.0.dev119/src/openmarkets/tools/stock_info.py +273 -0
- {openmarkets-0.1.0.dev118 → openmarkets-0.1.0.dev119}/src/openmarkets/tools/technical_analysis.py +2 -2
- openmarkets-0.1.0.dev118/.editorconfig +0 -36
- openmarkets-0.1.0.dev118/.gemini/config.yaml +0 -10
- openmarkets-0.1.0.dev118/.git-blame-ignore-revs +0 -0
- openmarkets-0.1.0.dev118/.gitattributes +0 -1
- openmarkets-0.1.0.dev118/.github/CODEOWNERS +0 -1
- openmarkets-0.1.0.dev118/.github/workflows/mirror.yaml +0 -14
- openmarkets-0.1.0.dev118/.gitignore +0 -309
- openmarkets-0.1.0.dev118/.pre-commit-config.yaml +0 -44
- openmarkets-0.1.0.dev118/.python-version +0 -1
- openmarkets-0.1.0.dev118/.vscode/mcp.json +0 -13
- openmarkets-0.1.0.dev118/CITATION.cff +0 -14
- openmarkets-0.1.0.dev118/LICENSE +0 -661
- openmarkets-0.1.0.dev118/docs/CNAME +0 -1
- openmarkets-0.1.0.dev118/docs/index.md +0 -185
- openmarkets-0.1.0.dev118/mkdocs.yml +0 -118
- openmarkets-0.1.0.dev118/other/mcp-server-yfinance/README.md +0 -215
- openmarkets-0.1.0.dev118/other/mcp-server-yfinance/mcp_server_yfinance/__main__.py +0 -3
- openmarkets-0.1.0.dev118/other/mcp-server-yfinance/pyproject.toml +0 -57
- openmarkets-0.1.0.dev118/other/mkt/README.md +0 -215
- openmarkets-0.1.0.dev118/other/mkt/mkt/__main__.py +0 -3
- openmarkets-0.1.0.dev118/other/mkt/pyproject.toml +0 -57
- openmarkets-0.1.0.dev118/pyrightconfig.json +0 -15
- openmarkets-0.1.0.dev118/src/openmarkets/__init__.py +0 -5
- openmarkets-0.1.0.dev118/src/openmarkets/__main__.py +0 -26
- openmarkets-0.1.0.dev118/src/openmarkets/_version.py +0 -21
- openmarkets-0.1.0.dev118/src/openmarkets/core/__init__.py +0 -5
- openmarkets-0.1.0.dev118/src/openmarkets/core/exceptions.py +0 -16
- openmarkets-0.1.0.dev118/src/openmarkets/core/models.py +0 -17
- openmarkets-0.1.0.dev118/src/openmarkets/core/registry.py +0 -72
- openmarkets-0.1.0.dev118/src/openmarkets/core/serializers.py +0 -34
- openmarkets-0.1.0.dev118/src/openmarkets/core/server.py +0 -39
- openmarkets-0.1.0.dev118/src/openmarkets/core/utils.py +0 -38
- openmarkets-0.1.0.dev118/src/openmarkets/services/__init__.py +0 -1
- openmarkets-0.1.0.dev118/src/openmarkets/tools/stock_info.py +0 -138
- openmarkets-0.1.0.dev118/tests/core/test_exceptions.py +0 -44
- openmarkets-0.1.0.dev118/tests/core/test_models.py +0 -118
- openmarkets-0.1.0.dev118/tests/core/test_registry.py +0 -285
- openmarkets-0.1.0.dev118/tests/core/test_serializers.py +0 -99
- openmarkets-0.1.0.dev118/tests/core/test_server.py +0 -129
- openmarkets-0.1.0.dev118/tests/core/test_utils.py +0 -55
- openmarkets-0.1.0.dev118/tests/tools/test_analyst_data.py +0 -85
- openmarkets-0.1.0.dev118/tests/tools/test_calendar.py +0 -104
- openmarkets-0.1.0.dev118/tests/tools/test_corporate_actions.py +0 -309
- openmarkets-0.1.0.dev118/tests/tools/test_crypto.py +0 -319
- openmarkets-0.1.0.dev118/tests/tools/test_extended_market.py +0 -285
- openmarkets-0.1.0.dev118/tests/tools/test_financial_statements.py +0 -448
- openmarkets-0.1.0.dev118/tests/tools/test_funds.py +0 -291
- openmarkets-0.1.0.dev118/tests/tools/test_funds_2.py +0 -148
- openmarkets-0.1.0.dev118/tests/tools/test_historical_data.py +0 -283
- openmarkets-0.1.0.dev118/tests/tools/test_market_data.py +0 -96
- openmarkets-0.1.0.dev118/tests/tools/test_options.py +0 -363
- openmarkets-0.1.0.dev118/tests/tools/test_stock_info.py +0 -186
- openmarkets-0.1.0.dev118/typings/yfinance/__init__.pyi +0 -38
- openmarkets-0.1.0.dev118/typings/yfinance/base.pyi +0 -69
- openmarkets-0.1.0.dev118/typings/yfinance/cache.pyi +0 -141
- openmarkets-0.1.0.dev118/typings/yfinance/const.pyi +0 -15
- openmarkets-0.1.0.dev118/typings/yfinance/data.pyi +0 -23
- openmarkets-0.1.0.dev118/typings/yfinance/domain/__init__.pyi +0 -4
- openmarkets-0.1.0.dev118/typings/yfinance/domain/domain.pyi +0 -26
- openmarkets-0.1.0.dev118/typings/yfinance/domain/industry.pyi +0 -17
- openmarkets-0.1.0.dev118/typings/yfinance/domain/market.pyi +0 -14
- openmarkets-0.1.0.dev118/typings/yfinance/domain/sector.pyi +0 -24
- openmarkets-0.1.0.dev118/typings/yfinance/exceptions.pyi +0 -33
- openmarkets-0.1.0.dev118/typings/yfinance/live.pyi +0 -35
- openmarkets-0.1.0.dev118/typings/yfinance/lookup.pyi +0 -41
- openmarkets-0.1.0.dev118/typings/yfinance/multi.pyi +0 -31
- openmarkets-0.1.0.dev118/typings/yfinance/pricing_pb2.pyi +0 -4
- openmarkets-0.1.0.dev118/typings/yfinance/scrapers/__init__.pyi +0 -0
- openmarkets-0.1.0.dev118/typings/yfinance/scrapers/analysis.pyi +0 -22
- openmarkets-0.1.0.dev118/typings/yfinance/scrapers/fundamentals.pyi +0 -21
- openmarkets-0.1.0.dev118/typings/yfinance/scrapers/funds.pyi +0 -26
- openmarkets-0.1.0.dev118/typings/yfinance/scrapers/history.pyi +0 -45
- openmarkets-0.1.0.dev118/typings/yfinance/scrapers/holders.pyi +0 -19
- openmarkets-0.1.0.dev118/typings/yfinance/scrapers/quote.pyi +0 -83
- openmarkets-0.1.0.dev118/typings/yfinance/screener/__init__.pyi +0 -8
- openmarkets-0.1.0.dev118/typings/yfinance/screener/query.pyi +0 -54
- openmarkets-0.1.0.dev118/typings/yfinance/screener/screener.pyi +0 -28
- openmarkets-0.1.0.dev118/typings/yfinance/search.pyi +0 -51
- openmarkets-0.1.0.dev118/typings/yfinance/shared.pyi +0 -0
- openmarkets-0.1.0.dev118/typings/yfinance/ticker.pyi +0 -115
- openmarkets-0.1.0.dev118/typings/yfinance/tickers.pyi +0 -48
- openmarkets-0.1.0.dev118/typings/yfinance/utils.pyi +0 -82
- openmarkets-0.1.0.dev118/typings/yfinance/version.pyi +0 -1
- {openmarkets-0.1.0.dev118 → openmarkets-0.1.0.dev119}/src/openmarkets/py.typed +0 -0
- {openmarkets-0.1.0.dev118 → openmarkets-0.1.0.dev119}/src/openmarkets/schemas/__init__.py +0 -0
|
@@ -1,28 +1,15 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
2
|
Name: openmarkets
|
|
3
|
-
Version: 0.1.0.
|
|
4
|
-
Summary:
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Project-URL: Documentation, https://danchev.github.io/openmarkets/
|
|
8
|
-
Project-URL: Issues, https://github.com/danchev/openmarkets/issues
|
|
9
|
-
Author-email: Dobri Danchev <python-dist@danchev.net>
|
|
3
|
+
Version: 0.1.0.dev119
|
|
4
|
+
Summary: OpenMarkets is a modular Model Context Protocol (MCP) server that unifies access to financial market data for AI, research, and quantitative finance. It offers robust APIs for historical prices, corporate actions, fundamentals, and more, enabling advanced agentic retrieval, RAG, and LLM-powered workflows.
|
|
5
|
+
Keywords: machinelearning,finance,investment,mcp,modelcontextprotocol,yahoo finance,financial data retrieval
|
|
6
|
+
Author: Dobri Danchev
|
|
10
7
|
License: AGPL-3.0-or-later
|
|
11
|
-
|
|
12
|
-
Keywords: finance,financial data retrieval,investment,machinelearning,mcp,modelcontextprotocol,yahoo finance
|
|
8
|
+
Classifier: License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
|
|
13
9
|
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
14
11
|
Classifier: Intended Audience :: Developers
|
|
15
12
|
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
16
|
-
Classifier: License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)
|
|
17
|
-
Classifier: Operating System :: OS Independent
|
|
18
|
-
Classifier: Programming Language :: Python
|
|
19
|
-
Classifier: Programming Language :: Python :: 3
|
|
20
|
-
Classifier: Programming Language :: Python :: 3 :: Only
|
|
21
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
25
|
-
Classifier: Programming Language :: Python :: 3.14
|
|
26
13
|
Classifier: Topic :: Office/Business :: Financial
|
|
27
14
|
Classifier: Topic :: Office/Business :: Financial :: Investment
|
|
28
15
|
Classifier: Topic :: Scientific/Engineering
|
|
@@ -30,14 +17,30 @@ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
|
30
17
|
Classifier: Topic :: Scientific/Engineering :: Interface Engine/Protocol Translator
|
|
31
18
|
Classifier: Topic :: Software Development :: Libraries
|
|
32
19
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Classifier: Programming Language :: Python
|
|
21
|
+
Classifier: Programming Language :: Python :: 3
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
27
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
28
|
+
Requires-Dist: mcp[cli]>=1.21.0
|
|
29
|
+
Requires-Dist: yfinance>=0.2.66
|
|
30
|
+
Requires-Dist: fastmcp>=2.13.0 ; extra == 'fastmcp'
|
|
31
|
+
Requires-Dist: lxml>=6.0.2 ; extra == 'lxml'
|
|
33
32
|
Requires-Python: >=3.10
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
Project-URL: Documentation, https://danchev.github.io/openmarkets/
|
|
34
|
+
Project-URL: Homepage, https://openmarkets.dev
|
|
35
|
+
Project-URL: Issues, https://github.com/danchev/openmarkets/issues
|
|
36
|
+
Project-URL: Source, https://github.com/danchev/openmarkets
|
|
37
|
+
Provides-Extra: fastmcp
|
|
38
|
+
Provides-Extra: lxml
|
|
36
39
|
Description-Content-Type: text/markdown
|
|
37
40
|
|
|
38
41
|

|
|
39
|
-
[](https://
|
|
40
|
-

|
|
42
|
+
[](https://pypi.org/project/openmarkets)
|
|
43
|
+
[](https://pypi.org/project/openmarkets)
|
|
41
44
|
|
|
42
45
|
# Open Markets
|
|
43
46
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|

|
|
2
|
-
[](https://
|
|
3
|
-

|
|
2
|
+
[](https://pypi.org/project/openmarkets)
|
|
3
|
+
[](https://pypi.org/project/openmarkets)
|
|
4
4
|
|
|
5
5
|
# Open Markets
|
|
6
6
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "openmarkets"
|
|
3
|
-
|
|
4
|
-
description = "
|
|
5
|
-
authors = [{ name = "Dobri Danchev"
|
|
3
|
+
version = "0.1.0.dev119"
|
|
4
|
+
description = "OpenMarkets is a modular Model Context Protocol (MCP) server that unifies access to financial market data for AI, research, and quantitative finance. It offers robust APIs for historical prices, corporate actions, fundamentals, and more, enabling advanced agentic retrieval, RAG, and LLM-powered workflows."
|
|
5
|
+
authors = [{ name = "Dobri Danchev" }]
|
|
6
6
|
classifiers = [
|
|
7
7
|
"License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)",
|
|
8
8
|
"Development Status :: 3 - Alpha",
|
|
@@ -38,9 +38,10 @@ readme = "README.md"
|
|
|
38
38
|
license = { text = "AGPL-3.0-or-later" }
|
|
39
39
|
requires-python = ">=3.10"
|
|
40
40
|
dependencies = [
|
|
41
|
-
"mcp[cli]>=1.
|
|
42
|
-
"yfinance>=0.2.
|
|
41
|
+
"mcp[cli]>=1.21.0",
|
|
42
|
+
"yfinance>=0.2.66",
|
|
43
43
|
]
|
|
44
|
+
optional-dependencies = {"fastmcp" = ["fastmcp>=2.13.0",], "lxml" = ["lxml>=6.0.2",]}
|
|
44
45
|
|
|
45
46
|
[project.urls]
|
|
46
47
|
Homepage = "https://openmarkets.dev"
|
|
@@ -53,48 +54,34 @@ openmarkets = "openmarkets.core.server:main"
|
|
|
53
54
|
mcp-server-yfinance = "openmarkets.core.server:main"
|
|
54
55
|
|
|
55
56
|
[build-system]
|
|
56
|
-
requires = ["
|
|
57
|
-
build-backend = "
|
|
58
|
-
|
|
59
|
-
[tool.hatch.build.targets.wheel]
|
|
60
|
-
packages = ["src/openmarkets"]
|
|
61
|
-
|
|
62
|
-
[tool.hatch.build.hooks.vcs]
|
|
63
|
-
version-file = "src/openmarkets/_version.py"
|
|
64
|
-
|
|
65
|
-
[tool.hatch.envs.default]
|
|
66
|
-
installer = "uv"
|
|
67
|
-
|
|
68
|
-
[tool.hatch.version]
|
|
69
|
-
source = "vcs"
|
|
70
|
-
raw-options.version_scheme = "release-branch-semver" # "calver-by-date"
|
|
71
|
-
raw-options.local_scheme = "no-local-version"
|
|
72
|
-
raw-options.fallback_version = "0.0.0"
|
|
57
|
+
requires = ["uv_build>=0.9.9,<0.10.0"]
|
|
58
|
+
build-backend = "uv_build"
|
|
73
59
|
|
|
74
60
|
[dependency-groups]
|
|
75
61
|
dev = [
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
62
|
+
"debugpy>=1.8.17",
|
|
63
|
+
"pyright>=1.1.407",
|
|
64
|
+
"refurb>=2.2.0",
|
|
65
|
+
"ruff>=0.14.4",
|
|
66
|
+
"ty>=0.0.1a26",
|
|
80
67
|
{include-group = "test"},
|
|
81
68
|
{include-group = "commit"},
|
|
82
69
|
]
|
|
83
70
|
test = [
|
|
84
|
-
"pytest>=
|
|
85
|
-
"pytest-cov>=
|
|
86
|
-
"pytest-xdist>=3.
|
|
87
|
-
"pytest-asyncio>=
|
|
71
|
+
"pytest>=9.0.1",
|
|
72
|
+
"pytest-cov>=7.0.0",
|
|
73
|
+
"pytest-xdist>=3.8.0",
|
|
74
|
+
"pytest-asyncio>=1.3.0",
|
|
88
75
|
]
|
|
89
76
|
docs = [
|
|
90
77
|
"mkdocs>=1.6.1",
|
|
91
|
-
"mkdocs-glightbox>=0.
|
|
92
|
-
"mkdocs-material[imaging]>=9.6.
|
|
93
|
-
"mkdocstrings-python>=1.
|
|
78
|
+
"mkdocs-glightbox>=0.5.1",
|
|
79
|
+
"mkdocs-material[imaging]>=9.6.22",
|
|
80
|
+
"mkdocstrings-python>=1.18.2",
|
|
94
81
|
]
|
|
95
82
|
commit = [
|
|
96
|
-
"commitizen>=4.
|
|
97
|
-
"pre-commit>=4.
|
|
83
|
+
"commitizen>=4.10.0",
|
|
84
|
+
"pre-commit>=4.4.0",
|
|
98
85
|
]
|
|
99
86
|
|
|
100
87
|
[tool.ruff]
|
|
@@ -125,3 +112,12 @@ python_functions = "test_*"
|
|
|
125
112
|
[tool.mypy]
|
|
126
113
|
custom_typeshed_dir = "typings"
|
|
127
114
|
plugins = ["mypy_ruff"]
|
|
115
|
+
|
|
116
|
+
[tool.commitizen]
|
|
117
|
+
name = "cz_conventional_commits"
|
|
118
|
+
version = "0.1.0.alpha"
|
|
119
|
+
tag_format = "$version"
|
|
120
|
+
version_files = [
|
|
121
|
+
"pyproject.toml:version"
|
|
122
|
+
]
|
|
123
|
+
update_changelog_on_bump = true
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Application entry point (starts the server)
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
from openmarkets.core.server import main
|
|
7
|
+
|
|
8
|
+
logging.basicConfig(
|
|
9
|
+
level=logging.INFO, stream=sys.stdout, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
if __name__ == "__main__":
|
|
13
|
+
main()
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
from functools import lru_cache
|
|
2
|
+
|
|
3
|
+
from pydantic import Field
|
|
4
|
+
from pydantic_settings import BaseSettings, CliSettingsSource, PydanticBaseSettingsSource, SettingsConfigDict
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Settings(BaseSettings):
|
|
8
|
+
"""Application configuration settings.
|
|
9
|
+
|
|
10
|
+
This class defines the configuration options for the Open Markets Server.
|
|
11
|
+
Settings can be loaded from environment variables, .env files, or CLI arguments.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
name: str = Field(
|
|
15
|
+
"Open Markets Server",
|
|
16
|
+
description="The name of the application/server.",
|
|
17
|
+
)
|
|
18
|
+
environment: str = Field(
|
|
19
|
+
"development",
|
|
20
|
+
description="The environment in which the server is running (e.g., development, production).",
|
|
21
|
+
)
|
|
22
|
+
transport: str = Field(
|
|
23
|
+
"stdio",
|
|
24
|
+
description="The transport protocol to use (e.g., stdio, http, etc.).",
|
|
25
|
+
)
|
|
26
|
+
host: str = Field(
|
|
27
|
+
"127.0.0.1",
|
|
28
|
+
description="The host address for the server.",
|
|
29
|
+
)
|
|
30
|
+
port: int = Field(
|
|
31
|
+
8000,
|
|
32
|
+
description="The port number for the server.",
|
|
33
|
+
)
|
|
34
|
+
debug: bool = Field(
|
|
35
|
+
False,
|
|
36
|
+
description="Enable or disable debug mode.",
|
|
37
|
+
)
|
|
38
|
+
timeout: float = Field(
|
|
39
|
+
5.0,
|
|
40
|
+
description="Default timeout (in seconds) for server operations.",
|
|
41
|
+
)
|
|
42
|
+
cors_allow_origins: str = Field(
|
|
43
|
+
"*",
|
|
44
|
+
description="Allowed origins for CORS (Cross-Origin Resource Sharing).",
|
|
45
|
+
)
|
|
46
|
+
toolset: str = Field(
|
|
47
|
+
"openmarkets.tools",
|
|
48
|
+
description="The Python module path for the toolset to use.",
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
model_config = SettingsConfigDict(env_file=".env")
|
|
52
|
+
|
|
53
|
+
@classmethod
|
|
54
|
+
def settings_customise_sources(
|
|
55
|
+
cls,
|
|
56
|
+
settings_cls: type[BaseSettings],
|
|
57
|
+
init_settings: PydanticBaseSettingsSource,
|
|
58
|
+
env_settings: PydanticBaseSettingsSource,
|
|
59
|
+
dotenv_settings: PydanticBaseSettingsSource,
|
|
60
|
+
file_secret_settings: PydanticBaseSettingsSource,
|
|
61
|
+
) -> tuple[PydanticBaseSettingsSource, ...]:
|
|
62
|
+
"""Customize the order of settings sources.
|
|
63
|
+
|
|
64
|
+
Args:
|
|
65
|
+
settings_cls: The settings class.
|
|
66
|
+
init_settings: Settings from __init__ arguments.
|
|
67
|
+
env_settings: Settings from environment variables.
|
|
68
|
+
dotenv_settings: Settings from .env files.
|
|
69
|
+
file_secret_settings: Settings from secret files.
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
A tuple of settings sources in the desired order.
|
|
73
|
+
"""
|
|
74
|
+
return (
|
|
75
|
+
init_settings,
|
|
76
|
+
CliSettingsSource(settings_cls, cli_parse_args=True, cli_ignore_unknown_args=True),
|
|
77
|
+
env_settings,
|
|
78
|
+
dotenv_settings,
|
|
79
|
+
file_secret_settings,
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@lru_cache
|
|
84
|
+
def get_settings() -> Settings:
|
|
85
|
+
"""Get a cached instance of the application settings.
|
|
86
|
+
|
|
87
|
+
Returns:
|
|
88
|
+
Settings: The application settings instance.
|
|
89
|
+
"""
|
|
90
|
+
return Settings() # type: ignore
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
class OpenMarketsException(Exception):
|
|
2
|
+
"""
|
|
3
|
+
Base class for all custom exceptions in OpenMarkets.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
pass
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class APIError(OpenMarketsException):
|
|
10
|
+
"""
|
|
11
|
+
Exception raised for API related errors.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
pass
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class InvalidSymbolError(OpenMarketsException):
|
|
18
|
+
"""
|
|
19
|
+
Exception raised for invalid symbols.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
pass
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
try:
|
|
4
|
+
from fastmcp import FastMCP
|
|
5
|
+
except ImportError:
|
|
6
|
+
from mcp.server.fastmcp import FastMCP
|
|
7
|
+
|
|
8
|
+
from starlette.applications import Starlette
|
|
9
|
+
from starlette.middleware.cors import CORSMiddleware
|
|
10
|
+
|
|
11
|
+
from openmarkets.core.config import Settings
|
|
12
|
+
from openmarkets.core.toolset import register_toolset
|
|
13
|
+
|
|
14
|
+
logger = logging.getLogger(__name__)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class FastMCPWithCORS(FastMCP):
|
|
18
|
+
def streamable_http_app(self) -> Starlette:
|
|
19
|
+
"""Return StreamableHTTP server app with CORS middleware"""
|
|
20
|
+
# Get the original Starlette app
|
|
21
|
+
app = super().streamable_http_app()
|
|
22
|
+
|
|
23
|
+
# Add CORS middleware
|
|
24
|
+
app.add_middleware(
|
|
25
|
+
CORSMiddleware,
|
|
26
|
+
allow_origins=["*"], # In production, should set specific domains
|
|
27
|
+
allow_credentials=True,
|
|
28
|
+
allow_methods=["*"],
|
|
29
|
+
allow_headers=["*"],
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
return app
|
|
33
|
+
|
|
34
|
+
def sse_app(self, mount_path: str | None = None) -> Starlette:
|
|
35
|
+
"""Return SSE server app with CORS middleware"""
|
|
36
|
+
# Get the original Starlette app
|
|
37
|
+
app = super().sse_app(mount_path)
|
|
38
|
+
|
|
39
|
+
# Add CORS middleware
|
|
40
|
+
app.add_middleware(
|
|
41
|
+
CORSMiddleware,
|
|
42
|
+
allow_origins=["*"], # In production, should set specific domains
|
|
43
|
+
allow_credentials=True,
|
|
44
|
+
allow_methods=["*"],
|
|
45
|
+
allow_headers=["*"],
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
return app
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def create_mcp(config: Settings) -> FastMCP:
|
|
52
|
+
"""
|
|
53
|
+
Create and configure the MCP server instance.
|
|
54
|
+
|
|
55
|
+
Initializes the MCP server and registers all available tools
|
|
56
|
+
using the ToolRegistry. Logs any errors during tool registration.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
config (Settings): Configuration object containing tool module reference.
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
FastMCP: Configured MCP server instance.
|
|
63
|
+
|
|
64
|
+
Raises:
|
|
65
|
+
RuntimeError: If tool registration fails.
|
|
66
|
+
"""
|
|
67
|
+
mcp = FastMCP(
|
|
68
|
+
name="Open Markets Server",
|
|
69
|
+
instructions=("This server allows for the integration of various market data tools."),
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
try:
|
|
73
|
+
register_toolset(mcp, config.toolset)
|
|
74
|
+
logger.info("Tool registration completed successfully.")
|
|
75
|
+
except Exception as exc:
|
|
76
|
+
logger.exception("Failed to initialize ToolRegistry or register tools.")
|
|
77
|
+
raise RuntimeError("Tool registration failed. See logs for details.") from exc
|
|
78
|
+
|
|
79
|
+
return mcp
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
import pandas as pd
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class JSONSerializer(json.JSONEncoder):
|
|
8
|
+
"""
|
|
9
|
+
Custom JSON encoder for pandas and numpy objects.
|
|
10
|
+
|
|
11
|
+
Handles:
|
|
12
|
+
- pandas.Timestamp (as ISO string)
|
|
13
|
+
- numpy integer/floating types
|
|
14
|
+
- numpy.ndarray, pandas.Series, pandas.DataFrame
|
|
15
|
+
- NaN and None values
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def default(self, o: object) -> object:
|
|
19
|
+
if isinstance(o, pd.Timestamp):
|
|
20
|
+
return o.isoformat()
|
|
21
|
+
if isinstance(o, np.integer):
|
|
22
|
+
return int(o)
|
|
23
|
+
if isinstance(o, np.floating):
|
|
24
|
+
return float(o)
|
|
25
|
+
if isinstance(o, (np.ndarray, pd.Series)):
|
|
26
|
+
return o.tolist()
|
|
27
|
+
if isinstance(o, pd.DataFrame):
|
|
28
|
+
return o.to_dict(orient="records")
|
|
29
|
+
if o is None or (isinstance(o, float) and np.isnan(o)):
|
|
30
|
+
return None
|
|
31
|
+
return super().default(o)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def safe_json_dumps(data: object, indent: int | None = None) -> str:
|
|
35
|
+
"""
|
|
36
|
+
Serialize data to a JSON string, converting pandas/numpy objects to JSON serializable types.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
data (object): The data to serialize.
|
|
40
|
+
indent (Optional[int], optional): If not None, pretty-print with this indent level.
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
str: JSON string.
|
|
44
|
+
|
|
45
|
+
Raises:
|
|
46
|
+
TypeError: If the data cannot be serialized.
|
|
47
|
+
"""
|
|
48
|
+
try:
|
|
49
|
+
return json.dumps(data, cls=JSONSerializer, indent=indent)
|
|
50
|
+
except TypeError as exc:
|
|
51
|
+
# Log or handle serialization errors as needed
|
|
52
|
+
raise TypeError(f"Failed to serialize data: {exc}") from exc
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Open Markets Server
|
|
3
|
+
|
|
4
|
+
Initializes and runs the Open Markets MCP server, handling tool registration
|
|
5
|
+
and server lifecycle management.
|
|
6
|
+
Follows Google Python Style Guide for documentation and formatting.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import logging
|
|
10
|
+
import sys
|
|
11
|
+
|
|
12
|
+
import uvicorn
|
|
13
|
+
from starlette.middleware.cors import CORSMiddleware
|
|
14
|
+
|
|
15
|
+
from openmarkets.core.config import Settings, get_settings
|
|
16
|
+
from openmarkets.core.fastmcp import FastMCP, create_mcp
|
|
17
|
+
|
|
18
|
+
logger = logging.getLogger(__name__)
|
|
19
|
+
|
|
20
|
+
settings = get_settings()
|
|
21
|
+
mcp: FastMCP = create_mcp(settings)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def run_stdio_server(mcp: FastMCP) -> None:
|
|
25
|
+
"""
|
|
26
|
+
Runs the MCP server using stdio transport.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
mcp: FastMCP server instance.
|
|
30
|
+
|
|
31
|
+
Raises:
|
|
32
|
+
Exception: If the server encounters an error during runtime.
|
|
33
|
+
"""
|
|
34
|
+
try:
|
|
35
|
+
mcp.run()
|
|
36
|
+
except Exception as exc:
|
|
37
|
+
logger.exception("Server encountered an error during stdio runtime.")
|
|
38
|
+
raise exc
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def run_http_server(mcp: FastMCP, settings: Settings) -> None:
|
|
42
|
+
"""
|
|
43
|
+
Runs the MCP server using HTTP transport.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
mcp: FastMCP server instance.
|
|
47
|
+
settings: Server settings/configuration.
|
|
48
|
+
|
|
49
|
+
Raises:
|
|
50
|
+
Exception: If the server encounters an error during runtime.
|
|
51
|
+
"""
|
|
52
|
+
try:
|
|
53
|
+
app = mcp.streamable_http_app()
|
|
54
|
+
app.add_middleware(
|
|
55
|
+
CORSMiddleware,
|
|
56
|
+
allow_origins=settings.cors_allow_origins.split(","),
|
|
57
|
+
allow_credentials=True,
|
|
58
|
+
allow_methods=["*"],
|
|
59
|
+
allow_headers=["*"],
|
|
60
|
+
)
|
|
61
|
+
uvicorn.run(app, host=settings.host, port=settings.port)
|
|
62
|
+
except KeyboardInterrupt:
|
|
63
|
+
logger.info(msg="Server shutdown requested by user.")
|
|
64
|
+
sys.exit(0)
|
|
65
|
+
except Exception:
|
|
66
|
+
logger.exception("Server encountered an error during HTTP runtime.")
|
|
67
|
+
sys.exit(1)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def main() -> None:
|
|
71
|
+
"""
|
|
72
|
+
Orchestrates the startup of the Open Markets MCP server based on transport type.
|
|
73
|
+
|
|
74
|
+
Returns:
|
|
75
|
+
None
|
|
76
|
+
"""
|
|
77
|
+
if settings.transport == "stdio":
|
|
78
|
+
run_stdio_server(mcp)
|
|
79
|
+
elif settings.transport == "http":
|
|
80
|
+
run_http_server(mcp, settings)
|
|
81
|
+
else:
|
|
82
|
+
logger.error(f"Unsupported transport type: {settings.transport}")
|
|
83
|
+
sys.exit(2)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
if __name__ == "__main__":
|
|
87
|
+
main()
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import importlib
|
|
2
|
+
import inspect
|
|
3
|
+
import logging
|
|
4
|
+
import pkgutil
|
|
5
|
+
from collections.abc import Callable
|
|
6
|
+
from types import ModuleType
|
|
7
|
+
from typing import Any, Protocol
|
|
8
|
+
|
|
9
|
+
logger = logging.getLogger(__name__)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ToolRegistrar(Protocol):
|
|
13
|
+
"""Protocol defining the MCP-like tool registration interface."""
|
|
14
|
+
|
|
15
|
+
def tool(self) -> Callable[[Callable[..., Any]], None]: ...
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def discover_tool_modules(package_name: str) -> list[ModuleType]:
|
|
19
|
+
"""
|
|
20
|
+
Discover all importable modules in a package for tool registration.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
package_name: Package name to search modules from.
|
|
24
|
+
|
|
25
|
+
Returns:
|
|
26
|
+
List of imported Python modules.
|
|
27
|
+
"""
|
|
28
|
+
try:
|
|
29
|
+
package = importlib.import_module(package_name)
|
|
30
|
+
except ImportError as e:
|
|
31
|
+
logger.exception(f"Failed to import tools package '{package_name}': {e}")
|
|
32
|
+
return []
|
|
33
|
+
|
|
34
|
+
if not hasattr(package, "__path__"):
|
|
35
|
+
logger.error(f"Package '{package_name}' has no __path__; cannot discover modules.")
|
|
36
|
+
return []
|
|
37
|
+
|
|
38
|
+
modules = []
|
|
39
|
+
for _, mod_name, _ in pkgutil.walk_packages(package.__path__, prefix=f"{package_name}."):
|
|
40
|
+
if mod_name.endswith(".__init__"):
|
|
41
|
+
continue
|
|
42
|
+
try:
|
|
43
|
+
module = importlib.import_module(mod_name)
|
|
44
|
+
modules.append(module)
|
|
45
|
+
except Exception as e:
|
|
46
|
+
logger.warning(f"Failed to import module '{mod_name}': {e}", exc_info=True)
|
|
47
|
+
return modules
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def discover_tool_functions(module: ModuleType) -> list[Callable[..., Any]]:
|
|
51
|
+
"""
|
|
52
|
+
Discover all public callable tool functions in a module.
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
module: Python module to inspect.
|
|
56
|
+
|
|
57
|
+
Returns:
|
|
58
|
+
List of functions suitable for registration.
|
|
59
|
+
"""
|
|
60
|
+
functions = []
|
|
61
|
+
for name, func in inspect.getmembers(module, inspect.isfunction):
|
|
62
|
+
if name.startswith("_") or name.startswith("register"):
|
|
63
|
+
continue
|
|
64
|
+
functions.append(func)
|
|
65
|
+
return functions
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def register_tools_from_module(mcp: ToolRegistrar, module: ModuleType) -> None:
|
|
69
|
+
"""
|
|
70
|
+
Register all public tools from a given module.
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
mcp: MCP-like object implementing `.tool()` decorator.
|
|
74
|
+
module: Module containing tool functions.
|
|
75
|
+
"""
|
|
76
|
+
module_name = getattr(module, "__name__", repr(module))
|
|
77
|
+
for func in discover_tool_functions(module):
|
|
78
|
+
try:
|
|
79
|
+
mcp.tool()(func)
|
|
80
|
+
logger.debug(f"Registered tool '{func.__name__}' from module '{module_name}'")
|
|
81
|
+
except Exception as e:
|
|
82
|
+
logger.warning(f"Error registering tool '{func.__name__}' from '{module_name}': {e}", exc_info=True)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def register_tools_from_package(mcp: ToolRegistrar, package_name: str) -> None:
|
|
86
|
+
"""
|
|
87
|
+
Discover and register all tools from the specified package (toolset).
|
|
88
|
+
Registers all public tool functions in all modules of the package with the MCP server.
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
mcp: MCP-like object implementing `.tool()` decorator.
|
|
92
|
+
package_name: Python package (toolset) to search tools from.
|
|
93
|
+
"""
|
|
94
|
+
modules = discover_tool_modules(package_name)
|
|
95
|
+
for module in modules:
|
|
96
|
+
register_tools_from_module(mcp, module)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def register_toolset(mcp: ToolRegistrar, toolset_package: str) -> None:
|
|
100
|
+
"""
|
|
101
|
+
Alias for register_tools_from_package for clarity. Registers all tools in a toolset package.
|
|
102
|
+
|
|
103
|
+
Args:
|
|
104
|
+
mcp: MCP-like object implementing `.tool()` decorator.
|
|
105
|
+
toolset_package: Python package (toolset) to search tools from.
|
|
106
|
+
"""
|
|
107
|
+
register_tools_from_package(mcp, toolset_package)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
async def register_tools_on_startup(mcp: ToolRegistrar, toolset_package: str) -> None:
|
|
111
|
+
"""
|
|
112
|
+
Async FastAPI startup hook to register all tools in a toolset package.
|
|
113
|
+
|
|
114
|
+
Args:
|
|
115
|
+
mcp: MCP-like object implementing `.tool()` decorator.
|
|
116
|
+
toolset_package: Python package (toolset) to search tools from.
|
|
117
|
+
"""
|
|
118
|
+
logger.info(f"Starting tool registration for toolset package '{toolset_package}'...")
|
|
119
|
+
register_tools_from_package(mcp, toolset_package)
|
|
120
|
+
logger.info("Tool registration completed.")
|