Skip to content

Rewrite MCP server to use FastMCP high-level API#3

Open
scottyallen wants to merge 3 commits intoSiddhant-K-code:mainfrom
scottyallen:fastmcp-rewrite
Open

Rewrite MCP server to use FastMCP high-level API#3
scottyallen wants to merge 3 commits intoSiddhant-K-code:mainfrom
scottyallen:fastmcp-rewrite

Conversation

@scottyallen
Copy link

Summary

  • Rewrites the MCP server from low-level Server API to FastMCP high-level API, fixing tool registration issues with Claude Code
  • Improves error handling and logging throughout
  • Fixes null pointer exception when photos have place object but place.name is None

Problem

The original implementation used the low-level Server API with @server.call_tool() decorators that had incorrect function signatures (using self parameter). This caused TaskGroup errors and prevented tools from registering properly with Claude Code.

Solution

Switched to FastMCP high-level API which:

  • Uses simple @mcp.tool() decorator
  • Accepts typed function parameters directly
  • Returns strings instead of List[TextContent]
  • Handles async internally

Test plan

  • Verified MCP server connects successfully
  • Tested location_search with various locations (Las Vegas, Berlin, Shenzhen)
  • Confirmed tools appear in Claude Code available functions

Generated with Claude Code

scottyallen and others added 3 commits January 17, 2026 12:45
Replace low-level Server API with FastMCP for proper tool registration.
The low-level API had complex async handling that caused TaskGroup errors
and prevented tools from registering with Claude Code.

- Switch from Server to FastMCP class
- Use @mcp.tool() decorator instead of @server.call_tool()
- Simplify function signatures (remove self parameter, use typed args)
- Return strings directly instead of List[TextContent]
- Replace async def with sync def (FastMCP handles async internally)
- Simplify main() to just mcp.run()

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Enhance PhotosDBLoader with better state tracking:
- Add _loading and _error state tracking
- Add is_ready property to check load status
- Provide clearer error messages for different failure states
- Log photo count on successful load

Improve logging throughout:
- Use named logger instead of root logging module
- Add filename and line numbers to log format
- Add exc_info=True to error logs for stack traces

Fix null safety in helper functions:
- Handle None photo.path in get_photo_details
- Handle None photo.date in formatting
- Return empty lists instead of None for persons/labels/keywords
- Add datetime.min fallback for sorting photos with no date

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Some photos have a place object but place.name is None, causing
AttributeError when calling .lower() on None.

Add explicit null check for photo.place.name before string comparison.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@scottyallen scottyallen marked this pull request as ready for review January 17, 2026 20:18
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.

1 participant