How aws-samples/sample-bedrock-mcp works
To accurately capture the architecture of this “Amazon Bedrock + Chainlit + MCP” sample, follow these steps:
Project Type and Purpose
• This is a full-stack AI‐powered chat application that:
• Hosts a Chainlit web interface for user interaction
• Uses a ReAct agent (via LangGraph + LangChain) to orchestrate reasoning and tool calls
• Connects to Amazon Bedrock (Anthropic Claude) for LLM capabilities
• Runs a custom MCP server (math operations) as an external tool
Main Components
a. Frontend / Web UI
– Chainlit server process (src/ui/app.py)
– Delivers chat UI, handles user input and streaming responses
b. ReAct Agent Layer
– LangGraph agent built with create_react_agent()
– LangChain MCP adapters (load_mcp_tools())
c. LLM Service
– AWS Bedrock Anthropic Claude 3.7 Sonnet (via src/utils/bedrock.py)
d. Math MCP Server
– Python wheel built from src/mcp/server.py
– Exposes stdio protocol for add, subtract, multiply, divide
e. Utility Modules
– src/utils/models.py (data models)
– Streaming and AWS credential management
Relationships and Data Flow
1) User → Chainlit UI (HTTP/WebSocket)
2) UI → ReAct agent → decision point:
• If no tool needed → call Bedrock API → return text
• If math needed → invoke MCP tool (subprocess stdio) → tool returns result
3) Agent aggregates results → streams back to UI
4) UI renders response in the browser
Architectural Patterns
• Microservices: separate UI service and MCP tool service
• Adapter pattern: LangChain MCP adapter bridges MCP stdio to LangChain tools
• ReAct agent pattern: interleaves reasoning (LLM) and acting (tool calls)