Unlocking Interactive AI Workflows: Introducing Stateful MCP Client Capabilities on Amazon Bedrock AgentCore Runtime
Transforming Agent Interactions with Elicitation, Sampling, and Progress Notifications
In this article, we delve into the newly introduced stateful capabilities of the Model Context Protocol (MCP) on Amazon Bedrock AgentCore Runtime. These enhancements empower developers to create interactive, multi-turn agent workflows, overcoming limitations associated with stateless implementations. Discover how elicitation, sampling, and progress notification capabilities can elevate user engagement and streamline complex operations by fostering bidirectional communication between clients and servers.
Transforming AI Agent Interactivity with Stateful MCP Client Capabilities on Amazon Bedrock AgentCore Runtime
In recent advancements within the realm of AI agents, the introduction of Stateful Model Context Protocol (MCP) client capabilities on Amazon Bedrock AgentCore Runtime marks a significant leap forward. This new functionality enables interactive, multi-turn workflows that were previously unattainable with stateless implementations.
The Challenge of Stateless Architectures
Builders of AI agents have often faced limitations with stateless MCP servers. In stateless implementations, each incoming HTTP request operates independently, making it impossible for servers to maintain a conversation thread, ask users for clarification mid-execution, or provide real-time updates during lengthy operations. Developers commonly struggled with scenarios where workflows had to pause mid-execution to seek user input or dynamically generate content. These challenges hampered the ability to create engaging and interactive applications.
The Solution: Stateful MCP Capabilities
With the introduction of stateful MCP mode, three pivotal client capabilities enhance interaction between MCP servers and clients:
- Elicitation: Allows servers to request structured user input during execution.
- Sampling: Enables servers to request LLM-generated content from clients.
- Progress Notifications: Provides real-time updates to users about ongoing operations.
These capabilities transform previously one-dimensional interactions into a dynamic, bidirectional conversation, vastly improving user experience.
From Stateless to Stateful MCP
Traditionally, running MCP servers on AgentCore utilized a stateless model where requests lacked shared context. However, by configuring the server with stateless_http=False, developers can enable stateful mode. This change provisions a dedicated microVM for each user session, maintaining session continuity through the Mcp-Session-Id header.
Key Differences in Modes
| Feature | Stateless Mode | Stateful Mode |
|---|---|---|
| Session Isolation | Not supported | Dedicated microVM per session |
| Client Capabilities | Not supported | Elicitation, Sampling, Progress Notifications |
| Recommended for | Simple tool serving | Interactive, multi-turn workflows |
Deep Dive into Client Capabilities
Let’s explore the three new client capabilities in detail.
Elicitation: Server-Initiated User Input
The elicitation capability allows an MCP server to pause execution and ask for specific data. This can include anything from confirming a decision to collecting user preferences:
result = await ctx.elicit('How much did you spend?', AmountInput)
Here, the server sends an elicitation request, and the client presents this as a user interface. The response can be accepted, declined, or canceled, allowing for a flexible interaction.
Sampling: Server-Initiated LLM Generation
Using sampling, the server can request a language model’s output without exposing its own API credentials. The client sends the server’s prompts to the appropriate LLM and returns the result. For example:
response = await ctx.sample(messages=prompt, max_tokens=300)
This mechanism empowers servers to leverage powerful LLMs for generating content, making it easier to create dynamic and context-aware interactions.
Progress Notifications: Real-Time Operation Feedback
Progress notifications keep users informed about the status of long-running operations, enhancing the overall user experience:
await ctx.report_progress(progress=2, total=total)
This feature allows the server to report back through a progress bar or status indicator, ensuring users don’t feel lost during lengthy processes.
Code Implementation: Building a Stateful MCP Server
To build a functional stateful MCP server, simply enable stateful mode during initialization:
mcp.run(transport="streamable-http", host="0.0.0.0", port=8000, stateless_http=False)
From here, the three capabilities become available automatically once the MPC client declares support during initialization. An example of a stateful server call might include an interactive expense entry tool:
@mcp.tool()
async def add_expense_interactive(user_alias: str, ctx: Context) -> str:
# Various elicitation steps
...
Example Implementation
To solidify understanding of these concepts, let’s look at how a tool can implement elicitation:
result = await ctx.elicit('What was it for?', DescriptionInput)
Each elicitation step collects user input iteratively, providing a structured way to gather necessary information.
Conclusion
The introduction of stateful MCP client capabilities on Amazon Bedrock AgentCore Runtime provides a powerful framework for developers to build more interactive and human-like AI agents. By overcoming the constraints of stateless implementations, these advancements empower organizations to create engaging applications that can handle real-time user interactions, generate dynamic content, and provide user feedback on long operations.
Explore the resources and documentation available to accelerate your development and take full advantage of these enhancements. As you implement these features, share your experiences and innovations to advance the capabilities of AI within your organization.
About the Authors
- Evandro Franco: Sr. Data Scientist at AWS.
- Phelipe Fabres: Sr. Solutions Architect for Generative AI at AWS.
- Zihang Huang: Solution Architect at AWS.
- Sayee Kulkarni: Software Development Engineer at AWS Bedrock AgentCore.
Together, let’s shape the future of AI interactivity!