Guide · Amazon Kinesis Video Streams · SDK Overview & Stream Management
Amazon Kinesis Video Streams for MCP Servers — SDK Overview, Stream Management, and AI Frame Extraction
Amazon Kinesis Video Streams (KVS) is AWS's fully managed service for ingesting, storing, and retrieving video streams from connected devices. For MCP server teams building multi-modal AI agents, KVS provides the bridge between physical cameras, IoT sensors, and AI models: agents can retrieve archived video frames for Claude Vision or Rekognition analysis, receive real-time video via WebRTC signaling channels, or trigger event-driven pipelines when motion is detected. The SDK is split across five packages — each handling a distinct interaction plane — and the data endpoint pattern means your media operations target stream-specific URLs, not the standard regional endpoint.
TL;DR
KVS uses five npm packages: @aws-sdk/client-kinesis-video (control plane — create/describe streams and signaling channels), @aws-sdk/client-kinesis-video-media (live GetMedia stream), @aws-sdk/client-kinesis-video-archived-media (HLS/DASH URLs and GetMediaForFragmentList for AI frame extraction), @aws-sdk/client-kinesis-video-signaling (WebRTC ICE server config), and @aws-sdk/client-kinesis-video-webrtc-storage (WebRTC video ingestion). Every media operation requires calling GetDataEndpointCommand first to get a stream-specific endpoint URL — you then instantiate a second client pointed at that URL for actual media reads/writes. Streams must have DataRetentionInHours >= 1 to retrieve archived media; retention 0 means data is not stored.
Why MCP servers need video stream access
Multi-modal AI agents increasingly need to perceive the physical world through cameras. KVS solves three distinct problems for MCP server teams:
- AI frame extraction: An MCP tool can call
GetMediaForFragmentListCommandto pull a time range of video from an IoT camera, pipe the MKV output through ffmpeg to extract JPEG frames, and pass those frames to Claude's Vision API or Rekognition for analysis. This is the foundation of "agent sees what the camera saw at time T" use cases — quality inspection, security review, incident reconstruction. - Real-time vision agents: WebRTC signaling channels let an agent receive a live video feed from a robot, drone, or factory camera without polling S3. Combined with Rekognition Stream Processors, the agent gets labeled events (PERSON detected, PACKAGE left) pushed to it via Kinesis Data Streams rather than having to poll for frames.
- Video state as tool context: MCP tools can expose a "snapshot" capability — when an LLM needs situational awareness from a camera, the tool retrieves the most recent fragment, extracts the last frame, and injects it into the conversation as an image block. This keeps the agent grounded in physical reality without requiring the LLM to process continuous video.
The five SDK packages
Unlike most AWS services that ship a single SDK package, KVS is split by interaction plane:
npm install \
@aws-sdk/client-kinesis-video \
@aws-sdk/client-kinesis-video-media \
@aws-sdk/client-kinesis-video-archived-media \
@aws-sdk/client-kinesis-video-signaling \
@aws-sdk/client-kinesis-video-webrtc-storage
Install only the packages you need. For control-plane-only work (creating streams, describing streams, managing tags), @aws-sdk/client-kinesis-video is sufficient.
Creating and describing streams
A stream is the fundamental resource: it has a name, an optional ARN-based alternative identifier, a media type hint, a shard count, and a retention window:
import {
KinesisVideoClient,
CreateStreamCommand,
DescribeStreamCommand,
ListStreamsCommand,
DeleteStreamCommand,
} from "@aws-sdk/client-kinesis-video";
const kv = new KinesisVideoClient({ region: "us-east-1" });
// Create a stream for a factory camera
await kv.send(new CreateStreamCommand({
StreamName: "factory-cam-01",
DataRetentionInHours: 168, // 7 days
MediaType: "video/h264", // hint only — not enforced by KVS
DeviceName: "factory-cam-01",
Tags: {
Environment: "production",
Location: "assembly-line-3",
},
}));
// Describe the stream to get its ARN
const { StreamInfo } = await kv.send(new DescribeStreamCommand({
StreamName: "factory-cam-01",
}));
console.log("Stream ARN:", StreamInfo.StreamARN);
console.log("Status:", StreamInfo.Status); // "CREATING" | "ACTIVE" | "UPDATING" | "DELETING"
console.log("Retention:", StreamInfo.DataRetentionInHours, "hours");
// List all streams with optional prefix filter
const { StreamInfoList } = await kv.send(new ListStreamsCommand({
StreamNameCondition: {
ComparisonOperator: "BEGINS_WITH",
ComparisonValue: "factory-",
},
}));
console.log("Factory streams:", StreamInfoList.map(s => s.StreamName));
The MediaType field is advisory — KVS accepts any media as long as it conforms to the MKV (Matroska) container format for PutMedia operations. Common values: "video/h264", "video/h265", "video/x-matroska". For GetHLSStreamingSessionURL to work, the stream must contain H.264 or H.265 encoded video.
The data endpoint pattern
This is the most important gotcha in KVS development. Media operations (GetMedia, GetHLSStreamingSessionURL, PutMedia, GetMediaForFragmentList, etc.) cannot use the standard regional endpoint. You must call GetDataEndpointCommand to get a stream-specific endpoint, then create a new client instance using that endpoint:
import { KinesisVideoClient, GetDataEndpointCommand } from "@aws-sdk/client-kinesis-video";
import { KinesisVideoArchivedMediaClient, GetHLSStreamingSessionURLCommand } from "@aws-sdk/client-kinesis-video-archived-media";
const kv = new KinesisVideoClient({ region: "us-east-1" });
// Step 1: Get the data endpoint for the specific API you want to call
const { DataEndpoint } = await kv.send(new GetDataEndpointCommand({
StreamName: "factory-cam-01",
APIName: "GET_HLS_STREAMING_SESSION_URL",
// APIName options:
// "PUT_MEDIA"
// "GET_MEDIA"
// "LIST_FRAGMENTS"
// "GET_MEDIA_FOR_FRAGMENT_LIST"
// "GET_HLS_STREAMING_SESSION_URL"
// "GET_DASH_STREAMING_SESSION_URL"
// "GET_CLIP"
}));
console.log("Data endpoint:", DataEndpoint);
// e.g. "https://b-23456789.kinesisvideo.us-east-1.amazonaws.com"
// Step 2: Create a media client pointed at the data endpoint
const kvArchived = new KinesisVideoArchivedMediaClient({
region: "us-east-1",
endpoint: DataEndpoint,
});
// Step 3: Now call media APIs using the data-endpoint-specific client
const { HLSStreamingSessionURL } = await kvArchived.send(
new GetHLSStreamingSessionURLCommand({
StreamName: "factory-cam-01",
PlaybackMode: "LIVE",
HLSFragmentSelector: {
FragmentSelectorType: "SERVER_TIMESTAMP",
},
Expires: 3600, // seconds — default 300, max 43200
})
);
console.log("HLS URL:", HLSStreamingSessionURL);
Data endpoints are durable — they don't rotate unless a stream is deleted and recreated. Caching the endpoint per (stream, API name) pair for a session is safe and reduces latency. Each API name may return a different endpoint URL, so cache per (stream + API name), not just per stream.
Stream retention and data availability
The DataRetentionInHours setting controls how long fragments are stored and therefore retrievable:
- 0 hours (no retention): Fragments are delivered to live consumers via GetMedia/WebRTC but not stored.
GET_HLS_STREAMING_SESSION_URL,LIST_FRAGMENTS, andGET_MEDIA_FOR_FRAGMENT_LISTwill fail withResourceNotFoundExceptionbecause there is nothing stored to retrieve. OnlyGET_MEDIA(live streaming) works. - 1 – 87600 hours (up to 10 years): Fragments are stored and all API names work. For AI frame extraction use cases, set at least 24 hours. For compliance video archival, set 87600 (10 years).
Changing retention on an existing stream is non-destructive for existing data — increasing retention extends the window for new fragments; decreasing it allows older fragments to be garbage-collected but doesn't immediately delete them. Use UpdateDataRetentionCommand with an Operation of "INCREASE_DATA_RETENTION" or "DECREASE_DATA_RETENTION".
import { UpdateDataRetentionCommand } from "@aws-sdk/client-kinesis-video";
await kv.send(new UpdateDataRetentionCommand({
StreamName: "factory-cam-01",
CurrentVersion: StreamInfo.Version, // must match current version — prevents conflicts
Operation: "INCREASE_DATA_RETENTION",
DataRetentionChangeInHours: 24, // add 24 hours to current retention
}));
Stream tags and discovery
Tags enable fleet-level stream discovery and cost attribution. MCP tools that manage cameras across a fleet can use tags to find streams by location, device type, or environment:
import { TagStreamCommand, ListTagsForStreamCommand, UntagStreamCommand } from "@aws-sdk/client-kinesis-video";
// Add or update tags (up to 50 per stream)
await kv.send(new TagStreamCommand({
StreamName: "factory-cam-01",
Tags: {
CameraModel: "Hikvision-DS-2CD2347",
Floor: "2",
LineId: "assembly-3",
MCPManagedBy: "factory-vision-agent",
},
}));
// List tags to filter in your MCP tool
const { Tags } = await kv.send(new ListTagsForStreamCommand({
StreamName: "factory-cam-01",
}));
console.log("Tags:", Tags);
// Remove a specific tag
await kv.send(new UntagStreamCommand({
StreamName: "factory-cam-01",
TagKeyList: ["MCPManagedBy"],
}));
IAM setup for MCP server video access
KVS uses the kinesisvideo: IAM action prefix. The minimum policy for an MCP tool that only reads archived video differs from one that also writes (ingests) video:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "KVSControlPlane",
"Effect": "Allow",
"Action": [
"kinesisvideo:DescribeStream",
"kinesisvideo:ListStreams",
"kinesisvideo:GetDataEndpoint",
"kinesisvideo:ListTagsForStream"
],
"Resource": "arn:aws:kinesisvideo:us-east-1:*:stream/factory-*/*"
},
{
"Sid": "KVSArchivedMediaRead",
"Effect": "Allow",
"Action": [
"kinesisvideo:GetHLSStreamingSessionURL",
"kinesisvideo:GetDASHStreamingSessionURL",
"kinesisvideo:GetMediaForFragmentList",
"kinesisvideo:ListFragments",
"kinesisvideo:GetMedia"
],
"Resource": "arn:aws:kinesisvideo:us-east-1:*:stream/factory-*/*"
}
]
}
For write access (PutMedia from an IoT device), add "kinesisvideo:PutMedia" to a separate statement. Keep write-only devices on a separate IAM role from read-only MCP tools — this limits blast radius if either credential is compromised.
Key gotchas at a glance
- GetDataEndpoint is not optional: Every media operation requires a stream-specific endpoint. Using the default regional endpoint for media calls returns
ResourceNotFoundExceptioneven if the stream exists. The endpoint lookup is fast (<100ms) and stable — cache it. - Fragment arrival lag: After a producer writes frames, there is a few-second delay before fragments appear in
ListFragmentsandGetMediaForFragmentList. For near-real-time retrieval, add a 5–10 second buffer when querying fragments by timestamp. TheLIVEplayback mode in HLS handles this automatically;ON_DEMANDdoes not. - GetMedia returns a continuous chunked stream: Unlike request/response APIs,
GetMediareturns aReadableStream(or Node.js stream) that keeps yielding data as long as the producer sends frames. You must explicitly close the connection or consume it in a time-limited fashion to avoid runaway resource usage. - Shard count is not adjustable post-creation: The
MediaTypeandKmsKeyIdfields can be updated, but the shard count cannot be changed without deleting and recreating the stream. Plan your shard count upfront — a single shard supports up to 50 Mbps of throughput, which is sufficient for all but very high-resolution cameras. - Server timestamp vs producer timestamp: KVS records both the timestamp your producer device sends (producer timestamp) and the time KVS actually received the fragment (server timestamp). Producer timestamps from embedded devices with clock drift can be unreliable. For AI frame extraction keyed on wall-clock time,
SERVER_TIMESTAMPis usually more reliable.
Continue in this series
- WebRTC signaling channels — CreateSignalingChannel, GetSignalingChannelEndpoint, GetIceServerConfig, amazon-kinesis-video-streams-webrtc-sdk-js integration for real-time video agents
- Archived media: HLS, DASH, and frame extraction — GetHLSStreamingSessionURLCommand, GetDASHStreamingSessionURLCommand, ListFragmentsCommand, GetMediaForFragmentListCommand for AI pipelines
- Rekognition stream processor integration — CreateStreamProcessorCommand, ConnectedHome vs FaceSearch modes, Kinesis Data Stream events for agent-triggered actions
Related AWS media and ML guides: Rekognition label detection for MCP servers · Kinesis Data Streams for MCP servers · AWS IoT Core for MCP servers · CloudWatch monitoring for MCP servers