-
Notifications
You must be signed in to change notification settings - Fork 3
MCP docs: Use Hishel for transparently caching responses #12
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
Conversation
WalkthroughThe updates introduce the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant MainScript
participant CacheClient (hishel)
participant RemoteServer
User->>MainScript: Run fetch_cratedb_docs
MainScript->>CacheClient (hishel): client.get(url)
alt Cache hit and valid
CacheClient (hishel)-->>MainScript: Return cached response
else Cache miss or stale
CacheClient (hishel)->>RemoteServer: HTTP GET url
RemoteServer-->>CacheClient (hishel): Response
CacheClient (hishel)-->>MainScript: Return fresh response
end
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (6)
🚧 Files skipped from review as they are similar to previous changes (6)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
surister
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
cratedb_mcp/settings.py (2)
5-5: Consider adding error handling for non-integer environment variable values.The current implementation will raise a
ValueErrorifCRATEDB_MCP_HTTP_CLIENT_CACHE_TTLcontains a non-integer value. Consider adding a try-except block to handle this case gracefully.- HTTP_CLIENT_CACHE_TTL: int = int(os.getenv("CRATEDB_MCP_HTTP_CLIENT_CACHE_TTL", "3600")) + try: + HTTP_CLIENT_CACHE_TTL: int = int(os.getenv("CRATEDB_MCP_HTTP_CLIENT_CACHE_TTL", "3600")) + except ValueError: + # If the environment variable is not a valid integer, use the default value + HTTP_CLIENT_CACHE_TTL: int = 3600
5-5: Consider adding value validation for the TTL setting.It might be beneficial to validate that the TTL value is positive and within a reasonable range. Very short TTLs might defeat the purpose of caching, while extremely long TTLs could lead to stale data.
- HTTP_CLIENT_CACHE_TTL: int = int(os.getenv("CRATEDB_MCP_HTTP_CLIENT_CACHE_TTL", "3600")) + # Get TTL value from environment or use default of 1 hour + ttl_raw = int(os.getenv("CRATEDB_MCP_HTTP_CLIENT_CACHE_TTL", "3600")) + # Ensure TTL is at least 1 second and at most 24 hours (86400 seconds) + HTTP_CLIENT_CACHE_TTL: int = max(1, min(ttl_raw, 86400))
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
.gitignore(1 hunks)CHANGES.md(1 hunks)README.md(1 hunks)cratedb_mcp/__main__.py(2 hunks)cratedb_mcp/settings.py(1 hunks)pyproject.toml(1 hunks)
✅ Files skipped from review due to trivial changes (2)
- .gitignore
- README.md
🚧 Files skipped from review as they are similar to previous changes (3)
- cratedb_mcp/main.py
- pyproject.toml
- CHANGES.md
🔇 Additional comments (1)
cratedb_mcp/settings.py (1)
4-5: LGTM: Clean addition of HTTP client cache TTL setting.The new setting
HTTP_CLIENT_CACHE_TTLis well-named and follows the existing pattern of reading from environment variables with sensible defaults. The default value of 3600 seconds (1 hour) aligns with the PR objective of balancing resource savings with content freshness.
By default, configure cache lifetime to one hour. Use the `CRATEDB_MCP_DOCS_CACHE_TTL` environment variable to adjust (default: 3600).
kneth
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻
About
When accessing documentation resources through HTTP, they don't need to be fetched over and over again, as they will not change that often. A cache TTL of one hour keeps a good balance between saving resources, and resource freshness. wdyt?
Review
Note
That's a stacked PR. GH-9 will need to go in first.