serverdaun commited on
Commit
65d3158
·
1 Parent(s): a2f1a08

add mcp server

Browse files
Files changed (9) hide show
  1. .gitignore +4 -0
  2. .python-version +1 -0
  3. Makefile +9 -0
  4. README.md +1 -1
  5. app.py +53 -4
  6. main.py +6 -0
  7. pyproject.toml +12 -0
  8. requirements.txt +238 -0
  9. uv.lock +0 -0
.gitignore ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ .venv/
2
+ .env
3
+ .ruff_cache/
4
+
.python-version ADDED
@@ -0,0 +1 @@
 
 
1
+ 3.12
Makefile ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ .PHONY: requirements
2
+ reqs:
3
+ uv pip compile pyproject.toml -o requirements.txt
4
+
5
+ format:
6
+ ruff format .
7
+
8
+ lint:
9
+ ruff check .
README.md CHANGED
@@ -11,4 +11,4 @@ license: mit
11
  short_description: Simple Gradio MCP server for YFinance
12
  ---
13
 
14
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
11
  short_description: Simple Gradio MCP server for YFinance
12
  ---
13
 
14
+ Simple gradio based MCP server for getting stock info using YFinance API
app.py CHANGED
@@ -1,7 +1,56 @@
 
 
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
1
+ from typing import Dict
2
+
3
  import gradio as gr
4
+ import yfinance as yf
5
+
6
+
7
+ def get_stocks_info(ticker: str) -> Dict[str, str]:
8
+ """
9
+ Fetches the current stock price and daily change for a stock ticker.
10
+
11
+ Args:
12
+ ticker: The stock ticker to get information for.
13
+
14
+ Returns:
15
+ A dictionary containing the stock price and daily change.
16
+ """
17
+ financial_data: Dict[str, str] = {}
18
+
19
+ # Filter out invalid tickers upfront
20
+ ticker = ticker.upper().strip()
21
+ if not ticker or ticker in ["N/A", "NA", ""]:
22
+ return {ticker: "No financial data"}
23
+
24
+ try:
25
+ stock = yf.Ticker(ticker)
26
+ info = stock.info
27
+ price = info.get("currentPrice") or info.get("regularMarketPrice")
28
+ change_percent = info.get("regularMarketChangePercent")
29
+
30
+ if price is not None and change_percent is not None:
31
+ change_str = f"{change_percent * 100:+.2f}%"
32
+ financial_data[ticker] = f"${price:.2f} ({change_str})"
33
+ else:
34
+ financial_data[ticker] = "Price data not available."
35
+
36
+ return financial_data
37
+ except Exception:
38
+ return {ticker: "Invalid Ticker or Data Error"}
39
+
40
+
41
+ demo = gr.Interface(
42
+ fn=get_stocks_info,
43
+ inputs=gr.Textbox(placeholder="Enter a stock ticker", label="Stock Ticker"),
44
+ outputs=gr.JSON(label="Output"),
45
+ title="YFinance MCP",
46
+ description="Get the current stock price and daily change for a stock ticker",
47
+ examples=[
48
+ ["AAPL"],
49
+ ["GOOG"],
50
+ ["MSFT"],
51
+ ],
52
+ )
53
 
 
 
54
 
55
+ if __name__ == "__main__":
56
+ demo.launch(mcp_server=True)
main.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ def main():
2
+ print("Hello from yfinance-mcp!")
3
+
4
+
5
+ if __name__ == "__main__":
6
+ main()
pyproject.toml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "yfinance-mcp"
3
+ version = "0.1.0"
4
+ description = "Add your description here"
5
+ readme = "README.md"
6
+ requires-python = ">=3.12"
7
+ dependencies = [
8
+ "gradio[mcp]>=6.0.1",
9
+ "isort>=7.0.0",
10
+ "ruff>=0.14.7",
11
+ "yfinance>=0.2.66",
12
+ ]
requirements.txt ADDED
@@ -0,0 +1,238 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file was autogenerated by uv via the following command:
2
+ # uv pip compile pyproject.toml -o requirements.txt
3
+ aiofiles==24.1.0
4
+ # via gradio
5
+ annotated-doc==0.0.4
6
+ # via fastapi
7
+ annotated-types==0.7.0
8
+ # via pydantic
9
+ anyio==4.12.0
10
+ # via
11
+ # gradio
12
+ # httpx
13
+ # mcp
14
+ # sse-starlette
15
+ # starlette
16
+ attrs==25.4.0
17
+ # via
18
+ # jsonschema
19
+ # referencing
20
+ beautifulsoup4==4.14.2
21
+ # via yfinance
22
+ brotli==1.2.0
23
+ # via gradio
24
+ certifi==2025.11.12
25
+ # via
26
+ # curl-cffi
27
+ # httpcore
28
+ # httpx
29
+ # requests
30
+ cffi==2.0.0
31
+ # via
32
+ # cryptography
33
+ # curl-cffi
34
+ charset-normalizer==3.4.4
35
+ # via requests
36
+ click==8.3.1
37
+ # via
38
+ # typer
39
+ # typer-slim
40
+ # uvicorn
41
+ cryptography==46.0.3
42
+ # via pyjwt
43
+ curl-cffi==0.13.0
44
+ # via yfinance
45
+ fastapi==0.122.0
46
+ # via gradio
47
+ ffmpy==1.0.0
48
+ # via gradio
49
+ filelock==3.20.0
50
+ # via huggingface-hub
51
+ frozendict==2.4.7
52
+ # via yfinance
53
+ fsspec==2025.10.0
54
+ # via
55
+ # gradio-client
56
+ # huggingface-hub
57
+ gradio==6.0.1
58
+ # via yfinance-mcp (pyproject.toml)
59
+ gradio-client==2.0.0
60
+ # via gradio
61
+ groovy==0.1.2
62
+ # via gradio
63
+ h11==0.16.0
64
+ # via
65
+ # httpcore
66
+ # uvicorn
67
+ hf-xet==1.2.0
68
+ # via huggingface-hub
69
+ httpcore==1.0.9
70
+ # via httpx
71
+ httpx==0.28.1
72
+ # via
73
+ # gradio
74
+ # gradio-client
75
+ # huggingface-hub
76
+ # mcp
77
+ # safehttpx
78
+ httpx-sse==0.4.3
79
+ # via mcp
80
+ huggingface-hub==1.1.6
81
+ # via
82
+ # gradio
83
+ # gradio-client
84
+ idna==3.11
85
+ # via
86
+ # anyio
87
+ # httpx
88
+ # requests
89
+ jinja2==3.1.6
90
+ # via gradio
91
+ jsonschema==4.25.1
92
+ # via mcp
93
+ jsonschema-specifications==2025.9.1
94
+ # via jsonschema
95
+ markdown-it-py==4.0.0
96
+ # via rich
97
+ markupsafe==3.0.3
98
+ # via
99
+ # gradio
100
+ # jinja2
101
+ mcp==1.22.0
102
+ # via gradio
103
+ mdurl==0.1.2
104
+ # via markdown-it-py
105
+ multitasking==0.0.12
106
+ # via yfinance
107
+ numpy==2.3.5
108
+ # via
109
+ # gradio
110
+ # pandas
111
+ # yfinance
112
+ orjson==3.11.4
113
+ # via gradio
114
+ packaging==25.0
115
+ # via
116
+ # gradio
117
+ # gradio-client
118
+ # huggingface-hub
119
+ pandas==2.3.3
120
+ # via
121
+ # gradio
122
+ # yfinance
123
+ peewee==3.18.3
124
+ # via yfinance
125
+ pillow==12.0.0
126
+ # via gradio
127
+ platformdirs==4.5.0
128
+ # via yfinance
129
+ protobuf==6.33.1
130
+ # via yfinance
131
+ pycparser==2.23
132
+ # via cffi
133
+ pydantic==2.12.4
134
+ # via
135
+ # fastapi
136
+ # gradio
137
+ # mcp
138
+ # pydantic-settings
139
+ pydantic-core==2.41.5
140
+ # via pydantic
141
+ pydantic-settings==2.12.0
142
+ # via mcp
143
+ pydub==0.25.1
144
+ # via gradio
145
+ pygments==2.19.2
146
+ # via rich
147
+ pyjwt==2.10.1
148
+ # via mcp
149
+ python-dateutil==2.9.0.post0
150
+ # via pandas
151
+ python-dotenv==1.2.1
152
+ # via pydantic-settings
153
+ python-multipart==0.0.20
154
+ # via
155
+ # gradio
156
+ # mcp
157
+ pytz==2025.2
158
+ # via
159
+ # pandas
160
+ # yfinance
161
+ pyyaml==6.0.3
162
+ # via
163
+ # gradio
164
+ # huggingface-hub
165
+ referencing==0.37.0
166
+ # via
167
+ # jsonschema
168
+ # jsonschema-specifications
169
+ requests==2.32.5
170
+ # via yfinance
171
+ rich==14.2.0
172
+ # via typer
173
+ rpds-py==0.29.0
174
+ # via
175
+ # jsonschema
176
+ # referencing
177
+ ruff==0.14.7
178
+ # via yfinance-mcp (pyproject.toml)
179
+ safehttpx==0.1.7
180
+ # via gradio
181
+ semantic-version==2.10.0
182
+ # via gradio
183
+ shellingham==1.5.4
184
+ # via
185
+ # huggingface-hub
186
+ # typer
187
+ six==1.17.0
188
+ # via python-dateutil
189
+ soupsieve==2.8
190
+ # via beautifulsoup4
191
+ sse-starlette==3.0.3
192
+ # via mcp
193
+ starlette==0.50.0
194
+ # via
195
+ # fastapi
196
+ # gradio
197
+ # mcp
198
+ tomlkit==0.13.3
199
+ # via gradio
200
+ tqdm==4.67.1
201
+ # via huggingface-hub
202
+ typer==0.20.0
203
+ # via gradio
204
+ typer-slim==0.20.0
205
+ # via huggingface-hub
206
+ typing-extensions==4.15.0
207
+ # via
208
+ # anyio
209
+ # beautifulsoup4
210
+ # fastapi
211
+ # gradio
212
+ # gradio-client
213
+ # huggingface-hub
214
+ # mcp
215
+ # pydantic
216
+ # pydantic-core
217
+ # referencing
218
+ # starlette
219
+ # typer
220
+ # typer-slim
221
+ # typing-inspection
222
+ typing-inspection==0.4.2
223
+ # via
224
+ # mcp
225
+ # pydantic
226
+ # pydantic-settings
227
+ tzdata==2025.2
228
+ # via pandas
229
+ urllib3==2.5.0
230
+ # via requests
231
+ uvicorn==0.38.0
232
+ # via
233
+ # gradio
234
+ # mcp
235
+ websockets==15.0.1
236
+ # via yfinance
237
+ yfinance==0.2.66
238
+ # via yfinance-mcp (pyproject.toml)
uv.lock ADDED
The diff for this file is too large to render. See raw diff