This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a Python MCP (Model Context Protocol) server that provides integration with the Reflect Notes API. The server is designed to be installed and run via uvx without cloning the repository, making it easy for users to add Reflect capabilities to their AI assistants.
reflect_mcp/- Main Python package__main__.py- Entry point for CLI executionserver.py- FastMCP server implementation with all toolsclient.py- Async HTTP client for Reflect API with OAuth2models.py- Pydantic models for API requests/responsesconfig.py- Configuration management with environment variables
-
OAuth2 Authentication Flow
- Browser-based authorization at
https://reflect.app/oauth - Token exchange using authorization code
- Automatic token refresh via authlib
- Tokens stored in memory (consider persistence for production)
- Browser-based authorization at
-
API Client Design
- Async/await throughout using httpx
- Context manager pattern for proper cleanup
- Type-safe with Pydantic models
- Centralized error handling
-
MCP Tool Organization
- Authentication tools:
authenticate,set_access_token,set_token_directly - Graph operations:
list_graphs,get_default_graph - Content tools:
create_note,append_daily_note,list_links,create_link - User tools:
get_current_user
- Authentication tools:
# Install dependencies
uv sync
# Run in development mode
uv run mcp dev reflect_mcp/server.py
# Test the server
uv run mcp inspector reflect_mcp/server.py
# Build for distribution
uv build
# Run tests (when implemented)
uv run pytest- Add model to
models.pyif needed - Implement method in
client.pyfollowing existing patterns - Create MCP tool in
server.pywith proper error handling - Update documentation
- Set environment variables for client ID/secret
- Use
authenticatetool to get auth URL - Complete browser flow
- Use
set_access_tokenwith the code from redirect
- Check
httpxresponse in client methods - Use
response.raise_for_status()for automatic error handling - Log full request/response when debugging
- Verify OAuth2 scopes match API requirements
| MCP Tool | Reflect API Endpoint | Method |
|---|---|---|
| list_graphs | /graphs | GET |
| list_books | /graphs/{id}/books | GET |
| list_links | /graphs/{id}/links | GET |
| create_link | /graphs/{id}/links | POST |
| create_note | /graphs/{id}/notes | POST |
| append_daily_note | /graphs/{id}/daily-notes | PUT |
| get_current_user | /users/me | GET |
The package is configured for PyPI distribution:
# Ensure version is updated in pyproject.toml
# Build the distribution
uv build
# Upload to PyPI (requires credentials)
uv publishUsers can then install with:
uvx reflect-mcp- Authentication Errors: Clear messages about missing credentials or expired tokens
- API Errors: Pass through Reflect API error messages with context
- Network Errors: Handled by httpx with appropriate retries
- Validation Errors: Caught by Pydantic before API calls
Consider implementing:
- Token persistence between sessions
- Batch operations for better performance
- Search functionality within notes/links
- WebSocket support for real-time updates
- Local caching of frequently accessed data