Skip to content

feat: Add API discovery tool for endpoint guidance#52

Merged
nydamon merged 8 commits intomainfrom
feat/api-discovery-tool
Mar 10, 2026
Merged

feat: Add API discovery tool for endpoint guidance#52
nydamon merged 8 commits intomainfrom
feat/api-discovery-tool

Conversation

@nydamon
Copy link
Owner

@nydamon nydamon commented Mar 10, 2026

Summary

Implements get_api_discovery() tool to help agents verify correct API endpoints and avoid repeated 404 errors from using wrong endpoints.

What's New

  • get_api_discovery tool: Dynamic API information lookup (service_name → endpoints, rate limits, auth, notes)
  • API Registry: Comprehensive database with Polymarket (CLOB vs Gamma), GitHub REST API, x402 Payment Protocol
  • Implementation notes: Guidance on common pitfalls (e.g., using CLOB endpoint for market data instead of Gamma API)

Key Features

  • Polymarket: Dual API architecture documented with critical 404-avoidance note
  • GitHub: REST endpoints with rate limit guidance and 404 handling
  • Dynamic queries: Agents call tool when research fails, not just at startup
  • Rich responses: Each endpoint includes URL, method, description, example curl command

Design Rationale

This tool uses a dynamic approach (Option C from the discovery tool evaluation) rather than a static file:

  • Agents can query API information at any time during execution
  • Easier to update without restarts
  • More extensible (can add multiple discovery tools)
  • Natural fit with agent tool-calling workflow

Testing

✅ All 1806 tests passing (0 failures, 6 skipped)
✅ TypeScript compilation successful
✅ Tool registered in agent tools system
✅ Follows existing tool patterns (web_search, github_search)

Example Usage

🤖 Generated with Claude Code

nydamon and others added 6 commits March 10, 2026 09:39
Turn 10+ inference requests hang due to accumulated message context
exceeding the 60-second timeout. MiniMax API needs >60s for responses
with large conversation history.

The 60s timeout triggered expensive retry loops (60s + backoff × 3 attempts),
accumulating to ~4 minutes total wait time before final abort.

Increased timeout to 120s (2 minutes) to allow complex inference requests
to complete without retrying. This matches typical LLM response times for
large contexts and reduces wasted retry latency.

Testing: Deployed to Connie VPS, service restarted.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
…loudflare

When expose_port detects BYOK mode (returning localhost URLs) and Cloudflare
credentials are configured, it now automatically:
1. Generates a subdomain (api-{port}-{timestamp}.compintel.co)
2. Creates a DNS A record pointing to the origin IP
3. Configures Caddy reverse proxy for public HTTPS access
4. Returns the public HTTPS URL instead of localhost

This unblocks agents like Connie from publishing services publicly when running
in BYOK mode. The agent can now distribute APIs and services without needing to
learn publish_service as a separate tool.

Graceful fallback: If any step of the auto-publish process fails, expose_port
returns the localhost URL with an error message, preventing tool failures.

Added tests:
- expose_port returns localhost when no Cloudflare creds
- expose_port auto-publishes when in BYOK + Cloudflare config
- expose_port falls back to localhost if auto-publish fails

All tests passing (5/5 in publish-service.test.ts).

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Implements get_api_discovery() tool to help agents verify correct API endpoints
and avoid repeated 404 errors due to using wrong endpoints.

Includes comprehensive API registry with:
- Polymarket: Dual API architecture (CLOB for trading vs Gamma for market data)
- GitHub: REST API endpoints with rate limits and authentication
- x402 Payment Protocol: Protocol specification and reference implementations

Tool provides:
- Service name lookup to detailed endpoint information
- Rate limiting and authentication requirements
- Implementation notes to avoid common pitfalls (e.g., CLOB vs Gamma)
- Example curl commands for each endpoint

This is a dynamic alternative to static discovery files, allowing agents to query
API information at any time during execution rather than just at startup.

Registered in agent tools system alongside web_search and github_search.
All 1806 tests passing.
@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

nydamon added 2 commits March 10, 2026 10:22
Addresses all 4 important items from code review:

1. Response structure consistency:
   - Added executedAt (ISO timestamp) to all responses
   - Added cacheHit boolean to track cache hits
   - Added service_name to identify queried service
   - Now consistent with web_search and github_search tools

2. Caching layer:
   - Added 24-hour TTL in-memory cache (copy of web_search pattern)
   - Reduces redundant lookups for same service
   - Marked cache hits in response metadata

3. Parameter validation:
   - Added explicit validation for missing/empty service_name
   - Proper error message with available services listed
   - Handles undefined gracefully instead of returning 'undefined' string

4. GitHub API documentation:
   - Enhanced rate limits section: specify per-search limits and per_page guidance
   - Added authentication guidance: personal access tokens recommended for production
   - Clarified pagination: default 30, max 100 per page
   - Added search filter examples to reduce result sets
   - Emphasized: always list_directory before get_file to avoid 404s

All 1806 tests passing.
@nydamon
Copy link
Owner Author

nydamon commented Mar 10, 2026

Code Review Fixes Applied ✅

All 4 important issues from code review have been addressed:

1. Response Structure Consistency

Added fields to match and pattern:

  • executedAt: ISO timestamp of when discovery was performed
  • cacheHit: Boolean tracking whether result came from cache
  • service_name: The service that was queried (for agent tracking)

2. Caching Layer Added

Implemented 24-hour TTL in-memory cache (consistent with other discovery tools):

  • Reduces redundant lookups for same service
  • Cache hits are marked in response metadata
  • Uses same pattern as web_search tool

3. Parameter Validation Enhanced

  • Added explicit validation for missing/empty service_name
  • Proper error message listing available services
  • Handles undefined gracefully (no more 'undefined' string responses)

4. GitHub API Documentation Improved

Enhanced with production-ready guidance:

  • Rate limits: Clarified per-search limits and per_page parameter usage
  • Authentication: Recommended personal access tokens for production agents
  • Pagination: Default 30, max 100 per page with example syntax
  • Search filters: Examples to reduce result sets and save quota
  • 404 Prevention: Emphasized always calling list_directory before get_file

Test Results

✅ All 1806 tests passing (0 failures, 6 skipped)
✅ TypeScript compilation clean
✅ Code consistent with existing tool patterns

Status: Ready for merge ✨

@nydamon nydamon merged commit 77856bf into main Mar 10, 2026
2 of 4 checks passed
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