Skip to content

Commit 7cdb2b4

Browse files
committed
mcp server
1 parent 29acf97 commit 7cdb2b4

File tree

8 files changed

+512
-6
lines changed

8 files changed

+512
-6
lines changed

1_phidata_finance_agent/1_simple_groq_agent.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
model=Groq(id="llama-3.3-70b-versatile")
99
)
1010

11+
1112
agent.print_response("Share a 2 sentence love story between dosa and samosa")

1_phidata_finance_agent/2_finance_agent_llama.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ def get_company_symbol(company: str) -> str:
4242
)
4343

4444
agent.print_response(
45-
"Summarize and compare analyst recommendations and fundamentals for TSLA and Phidata. Show in tables.", stream=True
45+
"Summarize and compare analyst recommendations and fundamentals for TSLA and MSFT. Show in tables.", stream=True
4646
)

1_phidata_finance_agent/3_agent_teams_openai.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
web_agent = Agent(
1111
name="Web Agent",
12-
model=Groq(id="llama-3.3-70b-versatile"),
13-
# model=OpenAIChat(id="gpt-4o"),
12+
# model=Groq(id="llama-3.3-70b-versatile"),
13+
model=OpenAIChat(id="gpt-4o"),
1414
tools=[DuckDuckGo()],
1515
instructions=["Always include sources"],
1616
show_tool_calls=True,
@@ -20,16 +20,17 @@
2020
finance_agent = Agent(
2121
name="Finance Agent",
2222
role="Get financial data",
23-
model=Groq(id="llama-3.3-70b-versatile"),
24-
# model=OpenAIChat(id="gpt-4o"),
23+
# model=Groq(id="llama-3.3-70b-versatile"),
24+
model=OpenAIChat(id="gpt-4o"),
2525
tools=[YFinanceTools(stock_price=True, analyst_recommendations=True, company_info=True)],
2626
instructions=["Use tables to display data"],
2727
show_tool_calls=True,
2828
markdown=True,
2929
)
3030

3131
agent_team = Agent(
32-
model=Groq(id="llama-3.3-70b-versatile"),
32+
# model=Groq(id="llama-3.3-70b-versatile"),
33+
model=OpenAIChat(id="gpt-4o"),
3334
team=[web_agent, finance_agent],
3435
instructions=["Always include sources", "Use tables to display data"],
3536
show_tool_calls=True,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.10

2_mcp_leave_management/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Build Your First MCP Server: Leave Management
2+
This AI tool helps an HR with leave management related tasks. The codebase here
3+
is for MCP server that interacts with mock leave database and responds to MCP client queries
4+
5+
# Setup steps
6+
1. Install Claude Desktop
7+
2. Install uv by running `pip install uv`
8+
3. Run `uv init my-first-mcp-server` to create a project directory
9+
4. Few folks may get type errors for which you can run `pip install --upgrade typer` to upgrade typer library to its latest version
10+
5. Write code in main.py for leave management server
11+
6. Install this server inside Claude desktop by running `uv run mcp install main.py` in the project directory
12+
7. Kill any running instance of Claude from Task Manager. Restart Claude Desktop
13+
8. In Claude desktop, now you will see tools from this server
14+
15+
@All rights reserved. Codebasics Inc. LearnerX Pvt Ltd.

2_mcp_leave_management/main.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from mcp.server.fastmcp import FastMCP
2+
from typing import List
3+
4+
# In-memory mock database with 20 leave days to start
5+
employee_leaves = {
6+
"E001": {"balance": 18, "history": ["2024-12-25", "2025-01-01"]},
7+
"E002": {"balance": 20, "history": []}
8+
}
9+
10+
# Create MCP server
11+
mcp = FastMCP("LeaveManager")
12+
13+
# Tool: Check Leave Balance
14+
@mcp.tool()
15+
def get_leave_balance(employee_id: str) -> str:
16+
"""Check how many leave days are left for the employee"""
17+
data = employee_leaves.get(employee_id)
18+
if data:
19+
return f"{employee_id} has {data['balance']} leave days remaining."
20+
return "Employee ID not found."
21+
22+
# Tool: Apply for Leave with specific dates
23+
@mcp.tool()
24+
def apply_leave(employee_id: str, leave_dates: List[str]) -> str:
25+
"""
26+
Apply leave for specific dates (e.g., ["2025-04-17", "2025-05-01"])
27+
"""
28+
if employee_id not in employee_leaves:
29+
return "Employee ID not found."
30+
31+
requested_days = len(leave_dates)
32+
available_balance = employee_leaves[employee_id]["balance"]
33+
34+
if available_balance < requested_days:
35+
return f"Insufficient leave balance. You requested {requested_days} day(s) but have only {available_balance}."
36+
37+
# Deduct balance and add to history
38+
employee_leaves[employee_id]["balance"] -= requested_days
39+
employee_leaves[employee_id]["history"].extend(leave_dates)
40+
41+
return f"Leave applied for {requested_days} day(s). Remaining balance: {employee_leaves[employee_id]['balance']}."
42+
43+
44+
# Resource: Leave history
45+
@mcp.tool()
46+
def get_leave_history(employee_id: str) -> str:
47+
"""Get leave history for the employee"""
48+
data = employee_leaves.get(employee_id)
49+
if data:
50+
history = ', '.join(data['history']) if data['history'] else "No leaves taken."
51+
return f"Leave history for {employee_id}: {history}"
52+
return "Employee ID not found."
53+
54+
# Resource: Greeting
55+
@mcp.resource("greeting://{name}")
56+
def get_greeting(name: str) -> str:
57+
"""Get a personalized greeting"""
58+
return f"Hello, {name}! How can I assist you with leave management today?"
59+
60+
if __name__ == "__main__":
61+
mcp.run()

2_mcp_leave_management/pyproject.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[project]
2+
name = "4-mcp-atliq"
3+
version = "0.1.0"
4+
description = "Add your description here"
5+
readme = "README.md"
6+
requires-python = ">=3.10"
7+
dependencies = [
8+
"mcp[cli]>=1.6.0",
9+
]

0 commit comments

Comments
 (0)