-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
199 lines (167 loc) · 5.97 KB
/
server.py
File metadata and controls
199 lines (167 loc) · 5.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import os
from fastmcp import FastMCP
from hrms import *
from utils import seed_services
from emails import EmailSender
from dotenv import load_dotenv
from typing import List, Dict, Optional
from datetime import datetime
load_dotenv()
email_sender = EmailSender(
smtp_server="smtp.gmail.com",
port=587,
username=os.getenv("email"),
password=os.getenv("password"),
use_tls=True
)
mcp= FastMCP("Atliq-HR-assist")
employee_manager= EmployeeManager()
leave_manager= LeaveManager()
meeting_manager= MeetingManager()
ticket_manager= TicketManager()
seed_services(employee_manager,leave_manager,meeting_manager,ticket_manager)
#tools
@mcp.tool()
def add_employee(emp_name:str, manager_id:str, email:str) -> str:
"""
Add a new employee to the HRMS system.
:param emp_name: Employee name
:param manager_id: Manager ID (optional)
:return: Confirmation message
"""
emp = EmployeeCreate(
emp_id=employee_manager.get_next_emp_id(),
name=emp_name,
manager_id=manager_id,
email=email
)
employee_manager.add_employee(emp)
return f"Employee {emp_name} added successfully."
@mcp.tool()
def get_employee_details(name: str) -> Dict[str, Optional[str]]:
"""
Get employee details by name.
:param name: Name of the employee
:return: Employee ID and manager ID
"""
matches = employee_manager.search_employee_by_name(name)
if len(matches) == 0:
raise ValueError(f"No employees found with name {name}.")
emp_id = matches[0]
emp_details = employee_manager.get_employee_details(emp_id)
return emp_details
@mcp.tool()
def send_email(to_emails: List[str], subject: str, body: str, html: bool = False) -> None:
email_sender.send_email(subject, body, to_emails, from_email=email_sender.username, html=html)
return "Email sent successfully."
@mcp.tool()
def create_ticket(emp_id: str, item: str, reason:str) -> str:
"""
Create a ticket for buying required items for an employee.
:param emp_id: Employee ID
:param item: Item requested (Laptop, ID Card, etc.)
:param reason: Reason for the request
:return: Confirmation message
"""
ticket_req = TicketCreate(emp_id=emp_id, item=item, reason=reason)
return ticket_manager.create_ticket(ticket_req)
@mcp.tool()
def update_ticket_status(ticket_id: str, status: str) -> str:
"""
Update the status of a ticket.
:param ticket_id: Ticket ID
:param status: New status of the ticket
:return: Confirmation message
"""
ticket_status_update = TicketStatusUpdate(status=status)
return ticket_manager.update_ticket_status(ticket_status_update, ticket_id)
@mcp.tool()
def list_tickets(employee_id: str, status: str) -> str:
"""
List tickets for an employee with optional status filter.
:param employee_id: Employee ID
:param status: Ticket status (optional)
:return: List of tickets
"""
return ticket_manager.list_tickets(employee_id=employee_id, status=status)
@mcp.tool()
def schedule_meeting(employee_id: str, meeting_datetime: datetime, topic: str) -> str:
"""
Schedule a meeting for an employee.
:param employee_id: Employee ID
:param meeting_datetime: Date and time of the meeting in python datetime format
:param topic: Topic of the meeting
:return: Confirmation message
"""
meeting_req = MeetingCreate(
emp_id=employee_id,
meeting_dt=meeting_datetime,
topic=topic
)
return meeting_manager.schedule_meeting(meeting_req)
@mcp.tool()
def get_meetings(employee_id: str) -> str:
"""
Get the list of meetings scheduled for an employee.
:param employee_id: Employee ID
:return: List of meetings
"""
return meeting_manager.get_meetings(employee_id)
@mcp.tool()
def cancel_meeting(employee_id: str, meeting_datetime: datetime, topic: str) -> str:
"""
Cancel a scheduled meeting for an employee.
:param employee_id: Employee ID
:param meeting_datetime: Date and time of the meeting in python datetime format
:param topic: Topic of the meeting (optional)
:return: Confirmation message
"""
meeting_req = MeetingCancelRequest(
emp_id=employee_id,
meeting_dt=meeting_datetime,
topic=topic
)
return meeting_manager.cancel_meeting(meeting_req)
@mcp.tool()
def get_employee_leave_balance(emp_id: str) -> str:
"""
Get the leave balance of an employee.
:param emp_id: Employee ID
:return: Leave balance message
"""
return leave_manager.get_leave_balance(emp_id)
@mcp.tool()
def apply_leave(emp_id: str, leave_dates: list) -> str:
"""
Apply for leave for an employee.
:param emp_id: Employee ID
:param leave_dates: List of leave dates
:return: Leave application status message
"""
req = LeaveApplyRequest(emp_id=emp_id, leave_dates=leave_dates)
return leave_manager.apply_leave(req)
@mcp.tool()
def get_leave_history(emp_id: str) -> str:
"""
Get the leave history of an employee.
:param emp_id: Employee ID
:return: Leave history message
"""
return leave_manager.get_leave_history(emp_id)
#resources
#prompts
@mcp.prompt("onboard_new_employee")
def onboard_new_employee(employee_name: str, manager_name: str):
return f"""Onboard a new employee with the following details:
- Name: {employee_name}
- Manager Name: {manager_name}
Steps to follow:
- First, look up the manager's employee ID by calling get_employee_details with the manager's name. Use the returned emp_id as the manager_id in the next step.
- Add the employee to the HRMS system using the manager's employee ID (not the manager's name).
- Send a welcome email to the employee with their login credentials. (Format: employee_name@puneeth.com)
- Notify the manager about the new employee's onboarding.
- Raise tickets for a new laptop, id card, and other necessary equipment.
- Schedule an introductory meeting between the employee and the manager.
"""
if __name__ == "__main__":
mcp.run(transport="stdio")