Skip to content

feat: add input mode validation - #456

Merged
nahapetyan-serob merged 7 commits into
mainfrom
serob/add-input-mode-validation
Oct 21, 2026
Merged

nahapetyan-serob merged 7 commits into
mainfrom
serob/add-input-mode-validation

Conversation

@nahapetyan-serob

@nahapetyan-serob nahapetyan-serob commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Adds a2asrv.NewAgentCardEnforcer(card), a call interceptor that rejects requests which don't conform to the agent card. Register it with a2asrv.WithCallInterceptors(a2asrv.NewAgentCardEnforcer(card)).

  • Capability checks moved from the request handler and InterceptedHandler into 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.
  • SendMessage and SendStreamingMessage return a2a.ErrUnsupportedContentType if a message part has a media type the card doesn't accept. Accepted types are each skill's inputModes, or the card's defaultInputModes for skills without their own. Nothing is validated if the card declares no input modes.
    • Parts without a media type are checked against a type inferred from their content: text/plain for text, application/json for data, application/octet-stream for raw bytes and URLs.
    • A malformed media type in the card makes NewAgentCardEnforcer panic.
  • The deprecated WithCapabilityChecks now registers the enforcer with the given capabilities only, so it doesn't validate media types.
  • Examples, e2e servers and the ITK agent card declare text/plain instead of text. The ITK agent registers the enforcer.

BEGIN_COMMIT_OVERRIDE
feat: add input mode validation (#456)
END_COMMIT_OVERRIDE

Comment thread a2asrv/handler.go Resolved
Comment thread a2asrv/handler.go Resolved
@nahapetyan-serob
nahapetyan-serob force-pushed the serob/add-input-mode-validation branch from 854297f to c76cc90 Compare October 16, 2026 13:18
Comment thread a2asrv/handler.go Outdated
}

if inheritsDefaults {
inputModes = append(inputModes, parseMediaTypes(card.DefaultInputModes)...)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. allow all traffic.
  2. reject all traffic.
  3. 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.

Comment thread a2asrv/handler.go Outdated
return nil
}
for _, part := range req.Message.Parts {
if part.MediaType == "" {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread a2asrv/handler.go Outdated

// 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 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread a2asrv/agentcard_enforcer.go Resolved
Comment thread a2asrv/agentcard_enforcer.go Resolved
Comment thread a2asrv/handler.go Resolved
@nahapetyan-serob
nahapetyan-serob merged commit 8c814be into main Oct 21, 2026
5 checks passed
@nahapetyan-serob
nahapetyan-serob deleted the serob/add-input-mode-validation branch October 21, 2026 08:54
nahapetyan-serob pushed a commit that referenced this pull request Oct 21, 2026
🤖 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).
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.

2 participants