The OpenAPI adapter supports live polling for spec changes. When your OpenAPI specification changes at its URL, the adapter automatically detects the change, rebuilds all tools, and notifies your application — no restart required.Documentation Index
Fetch the complete documentation index at: https://docs.agentfront.dev/llms.txt
Use this file to discover all available pages before exploring further.
Why Polling?
Zero Downtime
API changes propagate to MCP tools without restarting your server.
Content-Hash Detection
Uses SHA-256 hashing to detect actual content changes, not just timestamps.
Resilient
Built-in retry logic, health tracking, and graceful degradation on failures.
Race-Free
Rebuild requests are serialized via a promise chain, preventing concurrent rebuilds.
Quick Start
Polling requires the
url option. If you use spec (in-memory object), polling is not supported and the adapter will throw an error at construction time.Configuration
Polling Options
Enable or disable polling. Must be
true to activate the poller.How often to poll for changes, in milliseconds. Shorter intervals detect changes faster but increase network traffic.
Timeout for each spec fetch request. If the spec server is slow, increase this value.
Strategy for detecting spec changes:
'content-hash'— Always downloads the full spec and compares SHA-256 hashes'etag'— UsesIf-None-Match/If-Modified-Sinceheaders for efficient 304 responses'auto'— Uses ETag/Last-Modified headers when available, falls back to content-hash
Additional headers to send with each poll request. Useful if your spec URL requires authentication.
Retry Options
Maximum retry attempts per poll cycle before counting as a failure.
Delay before the first retry attempt.
Maximum delay between retries (caps exponential backoff).
Multiplier for exponential backoff between retries.
Health Monitoring
Number of consecutive poll failures before the poller is marked unhealthy. The adapter logs an error when this threshold is reached and logs recovery when polling succeeds again.
Lifecycle API
Starting and Stopping
When used with@App, polling is typically managed by the adapter lifecycle. For standalone usage, you control the lifecycle directly:
Subscribing to Updates
UseonUpdate() to receive new tool sets whenever the spec changes:
How It Works
The polling pipeline has two independent concerns:-
Change detection — The
OpenApiSpecPollerfetches raw spec text from the URL and computes a SHA-256 content hash. If the hash differs from the last known hash, it firesonChanged. -
Tool rebuild — When
onChangedfires, the adapter resets its internal generator, callsfetch()to regenerate all tools from scratch, and notifies subscribers via theupdateCallback.
Serialized Rebuilds
Tool rebuilds are serialized through a promise chain (rebuildChain). If the spec changes multiple times before a rebuild completes, each rebuild runs sequentially — never concurrently. This prevents race conditions and ensures tools are always consistent.
Health States
The poller tracks three health states:| State | Meaning |
|---|---|
unknown | Initial state before the first poll completes |
healthy | Last poll succeeded |
unhealthy | Consecutive failures reached unhealthyThreshold |
unhealthy, the adapter logs an error. When it recovers (next successful poll), the adapter logs recovery. Tools remain available during unhealthy periods — only updates are paused.
Failure Resilience
If a rebuild fails (e.g., the new spec is invalid orfromURL() throws), the adapter rolls back to the previous generator. Existing tools continue working and the poller keeps trying on the next interval. This ensures that a single bad spec deployment never leaves the adapter in a broken state.
Examples
Production Configuration
Logging Updates
Graceful Shutdown
Multi-Adapter Polling
Best Practices
Choose the right interval
Choose the right interval
- Development: 5-10 seconds for fast feedback
- Staging: 30-60 seconds for reasonable freshness
- Production: 60-300 seconds to minimize load on spec servers
Use ETag-aware spec servers
Use ETag-aware spec servers
If your spec server supports
ETag or Last-Modified headers, set changeDetection: 'auto' (the default). This enables HTTP 304 responses, reducing bandwidth when the spec hasn’t changed.Authenticate poll requests
Authenticate poll requests
If your spec endpoint requires authentication, pass credentials via
polling.headers — not via additionalHeaders (which are for API requests, not spec fetches).Handle unhealthy state
Handle unhealthy state
Monitor the adapter logs for unhealthy state messages. When the poller becomes unhealthy, existing tools continue working — only new changes won’t be detected until the poller recovers.Consider connecting the poller health to your monitoring system by subscribing to updates and tracking intervals.
Test polling in CI
Test polling in CI
Use short intervals (100ms) and real HTTP servers in integration tests to verify the full pipeline. See the Testing OpenAPI Adapter guide for patterns.
Troubleshooting
Error: Polling requires URL-based options
Error: Polling requires URL-based options
Cause: You enabled polling with a static
spec object instead of a url.Solution: Switch to URL-based configuration:Updates not firing after spec change
Updates not firing after spec change
Possible causes:
- Content hasn’t actually changed — The poller compares SHA-256 hashes of the full response body. Whitespace or formatting changes count, but serving the exact same bytes won’t trigger an update.
- Poll interval hasn’t elapsed — Wait for at least one full
intervalMscycle after the spec change. - Poller is unhealthy — Check logs for consecutive failure messages. The spec server may be down.
- No subscriber — Call
adapter.onUpdate(cb)beforestartPolling()to ensure you don’t miss the initial update.
Too many rebuilds
Too many rebuilds
Cause: The spec server returns slightly different content on each request (e.g., timestamps, random IDs in the response).Solution: Ensure your spec endpoint returns stable, deterministic content. If you can’t control the server, increase
intervalMs to reduce rebuild frequency.Poller marked unhealthy
Poller marked unhealthy
Cause: The spec URL has returned errors for
unhealthyThreshold consecutive polls.Solution:- Verify the spec URL is accessible:
curl -I <your-spec-url> - Check if authentication headers are needed in
polling.headers - Increase
fetchTimeoutMsif the server is slow - Increase
retry.maxRetriesfor transient failures
What’s Next?
OpenAPI Adapter
Full OpenAPI adapter configuration reference
Testing Guide
Test your polling setup with real HTTP servers
Deployment
Deploy your polling-enabled adapter to production