这是一个使用FastMCP处理与macOS应用程序(如联系人、笔记、邮件、信息、提醒事项、日历和地图)交互的Python实现。
git clone https://github.com/jxnl/python-apple-mcp.git
cd python-apple-mcp
python -m venv venv
source venv/bin/activate # 在Windows上:venv\Scripts\activate
pip install -r requirements.txt
pip install -r requirements-test.txt
from apple_mcp import FastMCP, Context
# 初始化FastMCP服务器
mcp = FastMCP("Apple MCP")
# 使用工具
@mcp.tool()
def find_contact(name: str) -> List[Contact]:
"""按姓名搜索联系人"""
# 实现细节
pass
# 运行服务器
if __name__ == "__main__":
mcp.run()
from utils.contacts import ContactsModule
from utils.notes import NotesModule
# 初始化模块
contacts = ContactsModule()
notes = NotesModule()
# 使用模块
async def main():
# 查找联系人
contact = await contacts.find_contact("John")
# 创建笔记
await notes.create_note(
title="会议记录",
body="讨论要点...",
folder_name="工作"
)
# 运行异步代码
import asyncio
asyncio.run(main())
运行测试套件:
pytest
带有覆盖率的测试:
pytest --cov=utils tests/
运行特定测试文件:
pytest tests/test_contacts.py
find_contact(name: str) -> List[Contact]:按姓名搜索联系人get_all_contacts() -> List[Contact]:获取所有联系人create_contact(name: str, phones: List[str]) -> Contact:创建新的联系人find_note(query: str) -> List[Note]:搜索笔记create_note(title: str, body: str, folder_name: str) -> Note:创建新的笔记get_all_notes() -> List[Note]:获取所有笔记send_email(to: str, subject: str, body: str) -> str:发送邮件search_emails(query: str) -> List[Email]:搜索邮件get_unread_mails() -> List[Email]:获取未读邮件send_message(to: str, content: str) -> bool:发送iMessageread_messages(phone_number: str) -> List[Message]:阅读消息schedule_message(to: str, content: str, scheduled_time: str) -> Dict:安排消息create_reminder(name: str, list_name: str, notes: str, due_date: str) -> Dict:创建提醒事项search_reminders(query: str) -> List[Dict]:搜索提醒事项get_all_reminders() -> List[Dict]:获取所有提醒事项create_event(title: str, start_date: str, end_date: str, location: str, notes: str) -> Dict:创建事件search_events(query: str) -> List[Dict]:搜索事件get_events() -> List[Dict]:获取所有事件search_locations(query: str) -> List[Location]:搜索地点get_directions(from_address: str, to_address: str, transport_type: str) -> str:获取路线save_location(name: str, address: str) -> Dict:保存地点到收藏夹该项目采用MIT许可证 - 详情见LICENSE文件。