feat(#4557): wire X402PaymentGate into the serve surfaces#228
Merged
Conversation
Follow-on to #4527. X402PaymentGate wraps a JDK HttpHandler, but the serve surfaces created their HttpServer internally with no injection point — so you couldn't put x402 in front of them. Now `NlWebServer.from`, `AgUiServer.from`, and `A2AServer.from` take an optional `payment: X402PaymentGate? = null` and wrap their invocation handler (payment?.gate(h) ?: h). An agent can now monetize its served endpoint directly: `NlWebServer.from(agent, payment = gate).start()`. - A2A: only the RPC path is gated; the /.well-known agent-card discovery stays FREE. - McpServer intentionally NOT gated here — it wants a granular paidTool() (per-tool pricing) per PRD §12.8, a separate follow-up, not a blanket endpoint gate. - 2 hermetic integration tests (NlWeb + AG-UI gated by a fake facilitator). README + CHANGELOG + internals adjunct updated. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
Follow-on to #4527 (#4557): wire
X402PaymentGateinto the serve surfaces so an agent can monetize its served endpoint directly.X402PaymentGatewraps a JDKHttpHandler, but the serve surfaces build theirHttpServerinternally with no injection point — so x402 couldn't actually front them until now.Change
payment: X402PaymentGate? = nullonNlWebServer.from/AgUiServer.from/A2AServer.from; each wraps its invocation handler (payment?.gate(h) ?: h)./.well-known/agent-card.jsondiscovery endpoint stays free (you must be able to read the terms before paying).paidTool()(per-tool pricing) per PRD §12.8, a separate follow-up, not a blanket endpoint gate.Gates
2 hermetic integration tests (NLWeb + AG-UI gated by a fake facilitator:
402withoutX-PAYMENT, served with it). Full./gradlew buildgreen. README + CHANGELOG + internals adjunct updated. Closes #4557.🤖 Generated with Claude Code