How aws-samples/demo_mcp_on_amazon_bedrock works
Main Components
• Backend Service(s):
• The core backend is written in Python (files like main.py, mcp_client.py, chat_client.py, chat_client_stream.py) and uses FastAPI to expose REST APIs for chatting and MCP management.
• It handles user sessions, chat processing, and coordinates calls to Amazon Bedrock services and the MCP servers.
• MCP Client:
• This module (e.g., mcp_client.py) manages the connections with multiple external MCP servers. It enables the backend to delegate specialized tasks (e.g., file system operations, web search, browser control) in a decoupled way.
• Frontend Interfaces:
• A Streamlit-based Web UI (chatbot.py) that offers a simple interface for end users who want to interact with the chat system.
• A modern React UI (in the react_ui folder, built with Next.js, Tailwind CSS, and Shadcn UI) providing a more dynamic, multi-user experience with session management, theming, and real-time streaming responses.
• AWS/CDK Infrastructure:
• The cdk directory shows infrastructure-as-code setups for deploying parts of this system on AWS, ensuring that the environment (using services like Bedrock) is provisioned correctly.
• External Services / MCP Servers:
• The project integrates with various external MCP servers which may include Node.js or Python based implementations. The configuration (in conf/config.json) details the commands, arguments, and environment settings for each MCP server. These servers add functionality (like browser automation, external search, even remote desktop control via EC2) to the ChatBot.
Relationships and Interactions
• The Frontend (whether via Streamlit or React UI) communicates via REST APIs (hosted by the FastAPI backend service) with the backend.
• The backend receives and processes chat requests, interacting with Amazon Bedrock for primary model responses.
• When the model response requires tool calls, the MCP client initiates and manages calls to the configured MCP servers. These calls are often done dynamically based on the user’s request or the model’s “thinking” process.
• The CDK components define parts of the deployment (e.g., VPCs, server settings) for hosting this system on AWS.
• All interactions and data flows should show clear directional flows—for instance, user → Frontend → API Gateway/Backend → Amazon Bedrock, with branch-outs toward MCP Servers.
Architectural Patterns and Design Principles
• Frontend-backend separation: Clear REST API boundaries.
• Modular design: The use of distinct modules (chat client, MCP client, main service) lends itself to a microservices/micro-module approach.
• Extensibility: The project is designed so that additional MCP servers can be plugged in easily (see configuration files and UI functionality).
• Scalable infrastructure: The use of Next.js for the React UI and AWS CDK for managing cloud resources demonstrate attention to scalability and continuous deployment.
Relevant Technologies
• Backend: Python, FastAPI, uv (Python package manager), and command-line based MCP launching.
• Frontend: Streamlit for a simple UI; React with Next.js, Tailwind CSS, and Shadcn UI components for a modern, responsive UI.
• Cloud Deployment: AWS services along with CDK (in the cdk folder) for provisioning.
• External Integration: Amazon Bedrock (Nova/Claude models), various MCP servers written in Node.js or Python, and additional external tools/libraries.
Elements
• From user → Frontend → Backend → Amazon Bedrock
• From backend → MCP Client → External MCP Servers and back.
• UI components (perhaps rounded rectangles)
• Backend services (standard rectangles)