feat(mcp): implement public API for package information#16
Merged
Conversation
- Implement check_rate_limit/2 in transport.ex with Mnesia-based IP tracking - Add MCP-specific rate limit key prefix "mcp:ip:" for per-IP limits - Configure rate limit window and track requests per IP per minute - Return JSON-RPC error code -32002 with retry-after header when rate limited - Add telemetry event [:hex_hub, :mcp, :rate_limited] for monitoring - Implement rate_limit_mcp_request/2 plug in controller with 429 response - Rate limiting blocks public deployment until complete (as per spec)
- Fix package.repository -> package.repository_name field reference - Fix release.metadata -> release.meta with proper map/JSON string handling - Fix release.retirement -> release.retired (boolean to retirement info map) - Add normalize_meta/1 helper to handle both map and JSON string meta formats - Add format_retirement_info/1 to convert boolean retired status to info map - Update format_release/1 to use format_retirement_info(release.retired) - Update get_meta_field/3 to handle both map and JSON string meta types - Remove unused get_retirement_info/1 function
- Add 15 tests covering all user stories in mcp_public_test.exs - User Story 1: Package queries without authentication (6 tests) - search_packages, get_package, list_packages returns data without auth - invalid JSON-RPC request handling - non-existent package error handling - User Story 2: Tool discovery (3 tests) - GET /mcp/tools returns tools without authentication - GET /mcp/server-info returns capabilities with auth status - All tools include inputSchema for client discovery - User Story 3: Dependencies (3 tests) - get_package_metadata returns dependencies without auth - get_dependency_tree returns structure without auth - check_compatibility works without authentication - User Story 4: Documentation (2 tests) - Package info includes external links without auth - get_documentation tool accessible without authentication - Cross-cutting concerns (2 tests) - Rate limiting test with IP-based tracking - MCP disabled returns error -32001 with 503 status
- Add MCP public API section to CLAUDE.md with configuration examples - Document MCP_ENABLED, MCP_REQUIRE_AUTH, MCP_RATE_LIMIT settings - Add public deployment example with environment variables - Add rate limiting protection notes for public access deployments - Add MCP endpoints list (/mcp/health, /mcp/tools, /mcp/server-info, /mcp) - Update config/config.exs with enhanced MCP configuration comments - Document public deployment example with recommended rate limit (100 req/hr) - Add rate limiting rationale for abuse protection without authentication - Add complete tasks.md with all 41 tasks marked complete across 7 phases
- Fix code formatting in mcp_public_test.exs, runtime.exs, users.ex - Fix HEEx formatting in admin app layout (Phoenix 1.8 syntax) - Update Dialyzer workflow to include OTP/Elixir version in cache key - Add PLT build step when cache miss occurs
- Fix additional code formatting in mcp_public_test.exs (line breaking) - Add dialyzer ignore for pattern_match_cov warning in packages.ex (defensive normalize_meta/1 clause for runtime safety)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Key Changes
Rate Limiting (
lib/hex_hub/mcp/transport.ex)check_rate_limit/2with Mnesia-based IP trackingmcp:ip:key prefix for MCP-specific rate limits[:hex_hub, :mcp, :rate_limited]for monitoringAuthentication Bypass (
lib/hex_hub_web/controllers/mcp_controller.ex)require_auth: falseData Mapping Fixes (
lib/hex_hub/mcp/tools/packages.ex)package.repository→package.repository_namerelease.metadata→release.metawith map/JSON string handlingrelease.retirement→release.retiredwith format conversionnormalize_meta/1,format_retirement_info/1Configuration (
config/config.exs)MCP_ENABLED,MCP_REQUIRE_AUTH,MCP_RATE_LIMITenvironment variablesUser Stories Implemented
Test plan
mix test test/hex_hub_web/controllers/mcp_public_test.exs- 15 tests passmix test- 406 tests passrequire_auth: false