How moritalous/bedrock-mcp-streamlit works
Project Overview
• This project is a chat application built with Streamlit. Its key features are integration with Langchain (for handling LLM chat models) and with an external MCP (Model Context Protocol) server.
• The application's behavior is configured via two JSON files – one for LLM settings (config.json) and another for MCP server settings (mcp_config.json). Chat history is persisted in YAML files under the “chat_history” directory.
Identifying the Main Components
• Frontend (Chat Interface): Constructed using Streamlit and rendered in the UI provided by src/main.py. In the sidebar, users can select LLM models, adjust settings, and load past chat history.
• Chat Engine / Business Logic: Found in the “src” directory — mainly in files like main.py, prompts.py, trace.py, and util.py. This area handles:
– Invoking the Langchain chat model (configured in config.json).
– Processing and formatting messages (via modules like util.py’s MessageProcessor and its subclasses).
– Managing flow control (the orchestration between receiving user input and invoking external services).
• External Services & Protocol Integration:
– LLM Providers: Specific models (e.g., “Claude 3.7 Sonnet” and “Amazon Nova Pro”) are configured in config.json and used via the Langchain integration.
– MCP Server: Configuration in mcp_config.json defines how to interact with the MCP tool, including required transport details and environment settings.
• Persistence / Storage: Chat history is stored in YAML files (in the “chat_history” directory).
Relationships and Interactions
• The user interacts with the chat interface (Streamlit UI) which sends messages into the chat engine.
• The chat engine uses Langchain to initialize and interact with an LLM (as configured in config.json).
• After processing user input and responses, the application might contact or utilize MCP tools as specified in mcp_config.json to add context or trigger specialized operations.
• Each conversation is archived in a YAML file under chat_history for later retrieval, which can be selected via the sidebar.
• Configurations (from config.json and mcp_config.json) are loaded at the start and flow throughout the application to configure runtime behavior.
Architectural Patterns and Important Design Notes
• Modularity: The code is split into multiple modules (for prompts, trace, and utility functions) that abstract away specific concerns.
• Configuration Driven: Behavior and integrations are determined by external JSON configuration files.
• Separation of Concerns: The UI (streamlit) is separated from the business logic (LLM and MCP integrations) and the persistence layer.
• External Integrations: Uses third-party libraries like Langchain and Bedrock to encapsulate chat model functionalities.
Final Review – Ensure
• Each component is clearly labeled.
• Use annotations (or legends) if needed to explain configuration files and communication protocols.