Skip to content

Commit 9c7edc3

Browse files
committed
Add mcp tools
1 parent 4c07fa5 commit 9c7edc3

File tree

1 file changed

+42
-7
lines changed

1 file changed

+42
-7
lines changed

financial-analyst-deepseek/server.py

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
@mcp.tool()
88
def analyze_stock(query: str) -> str:
99
"""
10-
Analyzes the stock market data for the given query and write executable python code to analyze/visualize the data.
11-
Finally, save the code to a file stock_analysis.py and return a message to the user.
12-
The query is a string that must contain the stock symbol (e.g., TSLA, AAPL),
10+
Analyzes stock market data based on the query and generates executable Python code for analysis and visualization.
11+
Returns a formatted Python script ready for execution.
12+
13+
The query is a string that must contain the stock symbol (e.g., TSLA, AAPL, NVDA, etc.),
1314
timeframe (e.g., 1d, 1mo, 1y), and action to perform (e.g., plot, analyze, compare).
1415
1516
Example queries:
@@ -21,17 +22,51 @@ def analyze_stock(query: str) -> str:
2122
query (str): The query to analyze the stock market data.
2223
2324
Returns:
24-
str: A message to the user about the completion of the task.
25+
str: A nicely formatted python code as a string.
2526
"""
2627
try:
2728
result = run_financial_analysis(query)
28-
# Save the generated code to local directory
29+
return result
30+
except Exception as e:
31+
return f"Error: {e}"
32+
33+
34+
@mcp.tool()
35+
def save_code(code: str) -> str:
36+
"""
37+
Expects a nicely formatted, working and executable python code as input in form of a string.
38+
Save the given code to a file stock_analysis.py, make sure the code is a valid python file, nicely formatted and ready to execute.
39+
40+
Args:
41+
code (str): The nicely formatted, working and executable python code as string.
42+
43+
Returns:
44+
str: A message indicating the code was saved successfully.
45+
"""
46+
try:
2947
with open('stock_analysis.py', 'w') as f:
30-
f.write(result)
31-
return f"Stock analysis code saved to stock_analysis.py"
48+
f.write(code)
49+
return "Code saved to stock_analysis.py"
3250
except Exception as e:
3351
return f"Error: {e}"
3452

53+
@mcp.tool()
54+
def run_code_and_show_plot() -> str:
55+
"""
56+
Run the code in stock_analysis.py and save the plot to a file plot.png
57+
58+
Args:
59+
None
60+
61+
Returns:
62+
str: A message indicating the plot was saved successfully.
63+
"""
64+
try:
65+
with open('stock_analysis.py', 'r') as f:
66+
exec(f.read())
67+
return "Plot saved successfully to plot.png"
68+
except Exception as e:
69+
return f"Error: {e}"
3570

3671
# Run the server locally
3772
if __name__ == "__main__":

0 commit comments

Comments
 (0)