Skip to content

fix(invoke): default Accept to text/event-stream for non-MCP runtimes - #22

Closed
Hweinstock wants to merge 1 commit into
refactorfrom
fix/invoke-default-headers
Closed

fix(invoke): default Accept to text/event-stream for non-MCP runtimes#22
Hweinstock wants to merge 1 commit into
refactorfrom
fix/invoke-default-headers

Conversation

@Hweinstock

Copy link
Copy Markdown
Owner

Problem

On the refactor branch the CLI invoke path sends no Accept header on the HTTP/A2A streaming path, so invoking a TypeScript runtime returns HTTP 406 unless the user manually passes --accept text/event-stream. Content-Type already defaulted to application/json; the gap was the missing SSE Accept.

Fix

In normalizeRuntimeInvokeRequest (src/handlers/runtime/invoke/request.ts) — the single normalizer shared by runtime invoke, project invoke runtime, and the invoke TUI — default Accept to text/event-stream for non-MCP runtimes. MCP keeps its own negotiation (application/json, text/event-stream), and an explicit --accept / --content-type still overrides for every protocol.

-    accept: modeled.accept ?? (mcp ? "application/json, text/event-stream" : undefined),
+    accept: modeled.accept ?? (mcp ? "application/json, text/event-stream" : "text/event-stream"),

Headers are provider-independent — the normalizer never inspects the model provider, so Bedrock and non-Bedrock TS agents get identical defaults.

Spec

agentcore invoke / project invoke runtime default Content-Type: application/json and Accept: text/event-stream on the HTTP/A2A streaming path, chosen per protocol (MCP uses its own negotiation), and overridable by explicit flags. A TS agent invokes successfully with no header flags.

Verification

Compiled binary (bun run compile:linux-x64) against live TS runtimes in the dev account (us-east-1). Payload {"prompt":"hi"} in every case.

1. Fixed binary, no --accept / --content-type flags → succeeds (spec step 1 & 4). Two distinct TS agents (container-built):

> agentcore runtime invoke --id tsTest_bob-... --payload '{"prompt":"hi"}'
data: "Hello! "
data: "👋 How"
data: " can I help you today?"
status=200 content-type=text/event-stream complete=true bytes=67

> agentcore runtime invoke --id tsTest_strands_agent-... --payload '{"prompt":"hi"}'
data: "Hello! How can I help you today"
data: "?"
status=200 content-type=text/event-stream complete=true bytes=52

A third managed (NODE_22 / S3) TS agent also returned status=200 content-type=text/event-stream (the agent then emitted its own app-level error unrelated to headers).

2. Baseline (pre-fix, built from refactor) reproduces the bug, and --accept is the workaround:

> agentcore runtime invoke --id tsTest_bob-... --payload '{"prompt":"hi"}'
Error: Received error (406) from runtime.

> agentcore runtime invoke --id tsTest_bob-... --payload '{"prompt":"hi"}' --accept text/event-stream
data: "Hello! How"
data: " can I help you today?"
status=200 content-type=text/event-stream complete=true bytes=52

3. Explicit override still reaches the wire (spec step 2) — fixed binary forced to a non-SSE Accept 406s instead of using the default:

> agentcore runtime invoke --id tsTest_bob-... --payload '{"prompt":"hi"}' --accept application/json
Error: Received error (406) from runtime.

4. MCP unaffected (spec step 3) — the MCP branch is byte-for-byte unchanged and its negotiation is covered by normalizeRuntimeInvokeRequest unit tests (no MCP runtime exists in the dev account for a live check).

Static checks: bun test 2827 pass / 0 fail · tsc --noEmit clean · oxlint clean · prettier --check clean · secretlint clean.

How to reproduce the fix

bun install
bun run compile:linux-x64                       # or your platform target
export AWS_REGION=us-east-1
dist/bin/agentcore-<platform> runtime invoke \
  --id <ts_runtime_id> --payload '{"prompt":"hi"}'
# expect: SSE data frames + status=200 content-type=text/event-stream, no --accept needed

bun test src/handlers/runtime/invoke/request.test.ts src/handlers/runtime/invoke/invoke.test.tsx

project invoke runtime --name <ts_agent> exercises the identical normalizeRuntimeInvokeRequest path (runtime.tsx:118invokeRuntimeTarget → normalizer).

@Hweinstock
Hweinstock force-pushed the fix/invoke-default-headers branch from 4cf5429 to c972c20 Compare September 3, 2026 19:33
@Hweinstock
Hweinstock force-pushed the fix/invoke-default-headers branch from c972c20 to cf2a82b Compare September 3, 2026 19:42
@Hweinstock

Copy link
Copy Markdown
Owner Author

Superseded by upstream aws#2193 (merged into refactor). Closing this fork draft.

@Hweinstock Hweinstock closed this Sep 3, 2026
@Hweinstock
Hweinstock deleted the fix/invoke-default-headers branch September 3, 2026 20:38
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