-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathserver.py
More file actions
417 lines (310 loc) · 9.75 KB
/
server.py
File metadata and controls
417 lines (310 loc) · 9.75 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
from decimal import DefaultContext
from fastmcp import FastMCP
from pydantic import Field
from tools import (
app,
calendar,
contacts,
display,
messages,
notes,
reminders,
safari,
system,
)
mcp = FastMCP("Altic-MCP")
@mcp.tool()
def open_app(name: str) -> str:
"""
Open any mac application by specifying its name. Use this tool
if you encounter any error or issue mentioning that the app is not
open
Args:
name: Name of the mac app. e.g. "Mail", "Contacts", "Messages" etc.
Returns:
A success or failure message
"""
return app.open_app(name)
@mcp.tool()
def send_imessage(phone_number: str, message: str) -> str:
"""
Send an imessage to someone in your contacts
Args:
phone_number: The phone number of the recipient
message: The message text to send
Returns:
Success or error message
"""
return messages.send_message(phone_number=phone_number, message=message)
@mcp.tool()
async def search_contacts(name: str) -> str:
"""
Search for a phone number from contacts by name. Returns multiple
options if more than one contact is found or more than one number is found.
Ask clarifying questions on which number if any following actions are required
Args:
name: The name of contact to search for
ctx: FastMCP context for logging
Returns:
A list of matching contacts
"""
return contacts.search_contacts(name)
@mcp.tool()
async def read_recent_messages(
phone_number: str, recent_message_count: int = Field(default=25, ge=1, le=200)
) -> str:
"""
Read the recent X messages from the iMessage app between the user and the
person with the phone number. X is defined based on the value of recent_message_count
Args:
phone_number: The phone number of the person you want to retrieve the chat from
recent_message_count: The recent messages to retrieve, can be a maximum of 200
Returns:
A list of recent messages in the chat
"""
return messages.read_recent_messages(phone_number, recent_message_count)
@mcp.tool()
async def set_reminder(name: str, datetime: str, list_name: str = "Reminders") -> str:
"""
Set a reminder
Args:
name: The reminder text
datetime: The time to set the reminder for, must in the following format "YYYY-MM-DD HH:MM"
list_name: Reminder list, e.g. Work, Personal etc. Defaults to "Reminders"
Returns:
A success or error message
"""
return reminders.set_reminder(name, datetime, list_name)
@mcp.tool()
async def create_note(name: str, body: str, folder: str = Field(default="")) -> str:
"""
Create a note
Args:
name: Title of the note
body: Content of the note
folder: Use this if the note has to be created in a specific folder. Uses
default folder if none is specified
Returns:
A success or error message
"""
return notes.create_note(name, body, folder)
@mcp.tool()
async def search_notes(
query: str, max_results: int = Field(default=10, ge=1, le=20)
) -> str:
"""
Search Apple notes based on a query
Args:
query: The query string
max_results: The maximum number of results returned from the tool, defaults to 10
Returns:
A list of notes based on search
"""
return notes.search_notes(query, max_results)
@mcp.tool()
async def decrease_brightness(
amount: float = Field(default=0.0625, ge=0.0, le=1.0),
) -> str:
"""
Decrease screen brightness
Args:
amount: Amount to decrease brightness by (0.0 to 1.0 scale). Default is 0.0625 (6.25%)
Returns:
Success or error message
"""
return system.decrease_brightness(amount)
@mcp.tool()
async def increase_brightness(
amount: float = Field(default=0.0625, ge=0.0, le=1.0),
) -> str:
"""
Increase screen brightness
Args:
amount: Amount to increase brightness by (0.0 to 1.0 scale). Default is 0.0625 (6.25%)
Returns:
Success or error message
"""
return system.increase_brightness(amount)
@mcp.tool()
async def turn_up_volume(amount: float = Field(default=6.25, ge=0.0, le=100.0)) -> str:
"""
Turn up system volume
Args:
amount: Amount to increase volume by (0-100 scale). Default is 6.25 (6.25%)
Returns:
Success or error message
"""
return system.turn_up_volume(amount)
@mcp.tool()
async def turn_down_volume(
amount: float = Field(default=6.25, ge=0.0, le=100.0),
) -> str:
"""
Turn down system volume
Args:
amount: Amount to decrease volume by (0-100 scale). Default is 6.25 (6.25%)
Returns:
Success or error message
"""
return system.turn_down_volume(amount)
@mcp.tool()
async def create_calendar_event(
title: str,
start_datetime: str,
duration_minutes: int,
calendar_name: str = Field(default=""),
) -> str:
"""
Create a calendar event in the macOS Calendar app
Args:
title: The event title
start_datetime: Start date and time in format 'YYYY-MM-DD HH:MM' (e.g., '2025-10-30 14:30')
duration_minutes: Duration of the event in minutes
calendar_name: Optional calendar name (uses default calendar if not specified)
Returns:
Success or error message
"""
return calendar.create_calendar_event(
title, start_datetime, duration_minutes, calendar_name
)
@mcp.tool()
async def list_calendar_events_for_day(date: str) -> str:
"""
List all calendar events for a specific day
Args:
date: Date in format 'YYYY-MM-DD' (e.g., '2025-10-30')
Returns:
List of events for the specified day or error message
"""
return calendar.list_calendar_events_for_day(date)
@mcp.tool()
async def open_safari_tab(url: str = Field(default="")) -> str:
"""
Open a new tab in Safari with optional URL
Args:
url: Optional URL to open in the new tab
Returns:
Success or error message
"""
return safari.open_safari_tab(url)
@mcp.tool()
async def close_safari_tab(tab_index: int = Field(default=-1)) -> str:
"""
Close a Safari tab. Use -1 for current tab or specify tab index (1-based)
Args:
tab_index: Tab index to close (-1 for current tab, or 1-based index)
Returns:
Success or error message
"""
return safari.close_safari_tab(tab_index)
@mcp.tool()
async def get_safari_tabs() -> str:
"""
Get a list of all open Safari tabs with their URLs and titles
Returns:
List of tabs with URLs and titles or error message
"""
return safari.get_safari_tabs()
@mcp.tool()
async def switch_safari_tab(tab_index: int) -> str:
"""
Switch to a specific Safari tab by index (1-based)
Args:
tab_index: Tab index to switch to (must be greater than 0)
Returns:
Success or error message
"""
return safari.switch_safari_tab(tab_index)
@mcp.tool()
async def run_safari_javascript(javascript_code: str) -> str:
"""
Execute JavaScript code in the current Safari tab and return the result
Args:
javascript_code: JavaScript code to execute
Returns:
JavaScript execution result or error message
"""
return safari.run_safari_javascript(javascript_code)
@mcp.tool()
async def navigate_safari(url: str) -> str:
"""
Navigate to a URL in the current Safari tab
Args:
url: URL to navigate to
Returns:
Success or error message
"""
return safari.navigate_safari(url)
@mcp.tool()
async def reload_safari_page() -> str:
"""
Reload the current Safari page
Returns:
Success or error message
"""
return safari.reload_safari_page()
@mcp.tool()
async def safari_go_back() -> str:
"""
Navigate back in Safari history
Returns:
Success or error message
"""
return safari.safari_go_back()
@mcp.tool()
async def safari_go_forward() -> str:
"""
Navigate forward in Safari history
Returns:
Success or error message
"""
return safari.safari_go_forward()
@mcp.tool()
async def open_safari_window(url: str = Field(default="")) -> str:
"""
Open a new Safari window with optional URL
Args:
url: Optional URL to open in the new window
Returns:
Success or error message
"""
return safari.open_safari_window(url)
@mcp.tool()
async def close_safari_window() -> str:
"""
Close the current Safari window
Returns:
Success or error message
"""
return safari.close_safari_window()
@mcp.tool()
async def get_safari_page_info() -> str:
"""
Get information about the current Safari page including URL, title, text content, and HTML source
Returns:
Page information including URL, title, text, and source or error message
"""
return safari.get_safari_page_info()
@mcp.tool()
async def add_screen_glow() -> str:
"""
Add a visual feedback indicator (orange glow around screen edges) to show that automated actions are in progress.
IMPORTANT: Call this FIRST before performing any automated actions to provide visual feedback
to the user that the tool is actively working. This serves as a clear indicator that
operations are being executed.
Returns:
Success or error message
"""
return display.add_screen_glow()
@mcp.tool()
async def remove_screen_glow() -> str:
"""
Remove the visual feedback indicator (screen glow) when automated actions are complete.
IMPORTANT: Call this when all automated actions are complete to stop the visual feedback
indicator and signal to the user that operations have finished.
Returns:
Success or error message
"""
return display.remove_screen_glow()
if __name__ == "__main__":
mcp.run()