Skip to content

Fix/contacts search fix #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

pawel-mazurkiewicz
Copy link

@pawel-mazurkiewicz pawel-mazurkiewicz commented May 24, 2025

This pull request introduces significant enhancements to the contacts module, including improved error handling, a new caching system, and input validation utilities. These changes aim to improve performance, user experience, and data integrity.

Error Handling Improvements

  • Enhanced error messages in initServer() to provide detailed troubleshooting steps for contacts access issues and error scenarios. [1] [2]

Performance Optimization

  • Introduced a ContactCache class in utils/ContactCache.ts to cache contact data with a configurable TTL, memory limits, and automatic cleanup, significantly improving performance by reducing redundant data loading.

Input Validation

  • Added ValidationUtils in utils/ValidationUtils.ts to validate and sanitize contact names and phone numbers, ensuring input integrity and preventing potential issues like log injection or invalid data.

Solves #47 and #35

…mization

- Add ContactCache class with TTL expiration and memory management
- Implement cache-first phone search with direct JXA fallback
- Add phone number normalization utility for better format handling
- Auto-cache individual phone search results for future lookups
- Performance improvements: 99.7% faster cached contact access, 10.6x faster phone search

Features:
* Configurable cache with TTL (10min default), memory limits (50MB), and cleanup
* Cache-first strategy: instant cache hits, fallback to direct JXA search
* Phone number normalization supports multiple formats (+1, international, local)
* Automatic caching of successful phone searches for future instant lookups
* Memory-efficient with LRU eviction and automatic cleanup
@pawel-mazurkiewicz
Copy link
Author

Made this one, because while promising tool, this MCP server fails to fulfill most of its purported tasks. Started out with fixing contacts - they are correctly retrieved now and there's a cache mechanism implemented.

@CupOfGeo
Copy link

CupOfGeo commented Jun 3, 2025

I have pulled your branch and it runs standalone in the terminal but when i put it in my client config I get an error

Server connected successfully!
2025-06-03T02:19:06.232Z [apple-mcp] [info] Message from server: {"jsonrpc":"2.0","id":0,"result":{"protocolVersion":"2024-11-05","capabilities":{"tools":{}},"serverInfo":{"name":"Apple MCP tools","version":"1.0.0"}}}
2025-06-03T02:19:06.233Z [apple-mcp] [info] Message from client: {"method":"notifications/initialized","jsonrpc":"2.0"}
2025-06-03T02:19:06.233Z [apple-mcp] [info] Message from client: {"method":"tools/list","params":{},"jsonrpc":"2.0","id":1}
2025-06-03T02:19:06.234Z [apple-mcp] [info] Message from client: {"method":"tools/list","params":{},"jsonrpc":"2.0","id":2}
2025-06-03T02:19:06.234Z [apple-mcp] [info] Message from client: {"method":"resources/list","params":{},"jsonrpc":"2.0","id":3}
2025-06-03T02:19:06.234Z [apple-mcp] [info] Message from server: {"jsonrpc":"2.0","id":3,"error":{"code":-32601,"message":"Method not found"}}
2025-06-03T02:19:06.235Z [apple-mcp] [info] Message from server: {"jsonrpc":"2.0","id":1,"result":{"tools":[{"name":"contacts","description":"Search and retrieve contacts from Apple Contacts app","inputSchema":{"type":"object","properties":{"name":{"type":"string","description":"Name to search for (optional - if not provided, returns all contacts). Can be partial name to search."}}}},{"name":"notes","description":"Search, retrieve and create notes in Apple Notes app","inputSchema":{"type":"object","properties":{"operation":{"type":"string","description":"Operation to perform: 'search', 'list', or 'create'","enum":["search","list","create"]},

i found this about the error
modelcontextprotocol/servers#803 (comment) first time looking at typescript mcp so not exsactly sure of the fix yet but can look more later
cheers

@pawel-mazurkiewicz
Copy link
Author

@CupOfGeo - thanks for the comment. What's your client? I did try running it in Cursor before pushing this branch and it worked, so I'm curious (should have probably checked in Claude Desktop as well tbh).

Anyway, I'll look into it :)

@CupOfGeo
Copy link

CupOfGeo commented Jun 3, 2025

yes I'm using claud hmmmm i just tried it again and now it works ... idk might just need to be a restart on my side

"apple-mcp": {
      "command": "bun",
      "args": [
        "run",
        "/Users/georgemazzeo/tmp/apple-mcp/index.ts"
      ]
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants