Repository navigation
feat: add input mode validation - #456
Conversation
854297f to
c76cc90
Compare
| } | ||
|
|
||
| if inheritsDefaults { | ||
| inputModes = append(inputModes, parseMediaTypes(card.DefaultInputModes)...) |
There was a problem hiding this comment.
I'd rather be strict here and panic if media types can't be parsed. consider a case when all options are invalid and inoutModes is empty. we can:
- allow all traffic.
- reject all traffic.
- prevent the server from starting.
allowing all traffic gives a false sense of validations being on, people often miss or ignore errors printed on the start. letting a server start to only start rejecting all requests is the worst option. I'd panic if a media type can't be parsed in WithAgentCardEnforcement. that's impossible to miss and traffic will not be routed to a misconfigured server if it crashes immediately.
| return nil | ||
| } | ||
| for _, part := range req.Message.Parts { | ||
| if part.MediaType == "" { |
There was a problem hiding this comment.
I think this part makes the whole validator not very useful, because most people never set a media type on parts. if I want "text/plain" I probably don't want DataParts or RawParts to reach my agent. I'd probably add a helper:
func effectiveMediaType(p *a2a.Part) string {
if p.MediaType != "" {
return p.MediaType
}
switch p.Content.(type) {
case a2a.Text:
return "text/plain"
case a2a.Data:
return "application/json"
default:
return "application/octet-stream"
}
}and documented this behaviour in WithAgentCardEnforcement.
|
|
||
| // WithAgentCardEnforcement makes the request handler validate incoming requests against | ||
| // the provided [a2a.AgentCard] and reject the ones which do not conform to it. | ||
| func WithAgentCardEnforcement(card *a2a.AgentCard) RequestHandlerOption { |
There was a problem hiding this comment.
thinking about dynamic agent card case (eg. extended agent card or context.Context), it might be better to replace WithAgentCardEnforcement with an interceptor.
users can use CallInterceptor to implement any kind of checks but they'll need to reimplement input mode and capability validation every time. If we expose:
func NewAgentCardEnforcer(*a2a.AgentCard) (a2asrv.CallInterceptor, error) They can write their own interceptor which gets the right card, then creates an interceptor and delegates to it, then maybe performs other checks.
🤖 I have created a release *beep* *boop* --- ## [2.7.0](v2.6.0...v2.7.0) (2026-10-21) ### Features * add input mode validation ([#456](#456)) ([8c814be](8c814be)) * extension point for snapshot materialization logic ([#449](#449)) ([4899045](4899045)) * reject requests with unsupported A2A-Version ([#457](#457)) ([4226e74](4226e74)) * use application/a2a+json with Accept-based negotiation ([#465](#465)) ([a8caf47](a8caf47)) ### Bug Fixes * **a2a:** serialize task status timestamps in UTC ([#452](#452)) ([b657f33](b657f33)) * decode application/a2a+json error responses in the REST client ([#448](#448)) ([3e1aa7f](3e1aa7f)) * **errordetails:** handle nil Value in Typed.MarshalJSON ([#474](#474)) ([73c49ac](73c49ac)) * **grpc:** forward next_page_token in push config list responses ([#455](#455)) ([7210014](7210014)) * **grpc:** keep caller metadata when attaching service params ([#476](#476)) ([f01e895](f01e895)) * honor a2a+json Content Type when Accept is */* or missing ([#468](#468)) ([2169266](2169266)) * reject trailing data after the JSON body ([#453](#453)) ([e85760e](e85760e)) * **rest:** map non-A2A HTTP error responses by status code ([#471](#471)) ([4baba5f](4baba5f)) * return plain error when streaming fails before the first event ([#463](#463)) ([cf62533](cf62533)) * **taskstate:** reject unknown task state values on unmarshal and REST status param ([#404](#404)) ([534a60f](534a60f)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Adds
a2asrv.NewAgentCardEnforcer(card), a call interceptor that rejects requests which don't conform to the agent card. Register it witha2asrv.WithCallInterceptors(a2asrv.NewAgentCardEnforcer(card)).InterceptedHandlerinto the enforcer: streaming, push notification and extended card requests are rejected when the card doesn't support them, and requests that don't activate every required extension are rejected.SendMessageandSendStreamingMessagereturna2a.ErrUnsupportedContentTypeif a message part has a media type the card doesn't accept. Accepted types are each skill'sinputModes, or the card'sdefaultInputModesfor skills without their own. Nothing is validated if the card declares no input modes.text/plainfor text,application/jsonfor data,application/octet-streamfor raw bytes and URLs.NewAgentCardEnforcerpanic.WithCapabilityChecksnow registers the enforcer with the given capabilities only, so it doesn't validate media types.text/plaininstead oftext. The ITK agent registers the enforcer.BEGIN_COMMIT_OVERRIDE
feat: add input mode validation (#456)
END_COMMIT_OVERRIDE