How lugodoy/finance-agent-mcp works
Purpose and Entry Points
A Python conversational finance assistant for querying shared-expense records in natural language. The primary user entry point is the Streamlit application at app/main.py; it delegates interpretation and response generation to Gemini-backed agent code in llm/client_gemini.py. The MCP server can also run standalone via mcp_server/server.py.
Presentation Layer
app/main.py owns the Streamlit chat experience, session-facing interaction, and agent initialization/cache boundary. Styling is local to app/styles.css. The UI submits a user question and renders the agent’s final natural-language response; it does not query MySQL directly.
Agent and LLM Boundary
llm/client_gemini.py integrates Google Gemini and orchestrates tool calling. llm/prompts.py contains the system/few-shot prompt context that constrains the model to financial-query behavior and response formatting. Gemini interprets intent and selects available MCP tools; database access remains outside the model process.
MCP Tool Service
mcp_server/server.py exposes finance capabilities through Model Context Protocol, decoupling the agent from SQL implementation. Its core tool surface is:
• Expense-detail/item lookup: mcp_server/tools/expense_items.py
• Aggregate expense summaries by item and/or period: mcp_server/tools/expense_summary.py
The control path is Streamlit → Gemini agent → MCP tool invocation → data layer → tool result → Gemini-formatted response → Streamlit.
Data Access and Persistence
database/connection.py centralizes MySQL connection and parameterized-query execution for MCP tools. The operational schema is a personal_finance.transactions table containing item name, unit price, quantity, and purchase date; seed data is provisioned from scripts/seed.sql. This is the principal trust boundary: tools own query construction and return structured financial data, rather than granting direct SQL access to the LLM.
Runtime and Infrastructure
The runtime targets Python 3.13+, Streamlit, Google Gemini API, MCP SDK, MySQL Connector/Python, and MySQL 8.0. docker-compose.yml provisions the local MySQL service, schema, and sample data; environment values, including GEMINI_API_KEY and database credentials, are represented by .env.example. Shared runtime configuration/logging and date handling live in shared/config_logging.py and shared/date_config.py.
Extensibility Shape
The modular boundaries support adding MCP tools in mcp_server/tools/, changing Gemini prompts/client behavior in llm/, or replacing the LLM provider without moving database logic into the UI. The current architecture is single-database and implicitly single shared expense dataset; authentication, group scoping, and advanced analytics are not present.
Main entry points: client_gemini.py Gemini agent · server.py MCP server · connection.py MySQL query layer · main.py Streamlit chat app
Components 14
Presentation
- Streamlit chat app · Owns chat interaction and agent caching.
app/main.py - Chat styling
app/styles.css
Agent and LLM
- Gemini agent · Orchestrates Gemini and MCP tool calls.
llm/client_gemini.py - Finance prompts · Constrains financial-query behavior and response format.
llm/prompts.py - Google Gemini API
MCP service
- MCP server · Exposes finance capabilities without giving the model SQL access.
mcp_server/server.py - Expense item lookup
mcp_server/tools/expense_items.py - Expense summaries · Aggregates expenses by item and/or period.
mcp_server/tools/expense_summary.py
Data and runtime
- MySQL query layer · Centralizes parameterized query execution.
database/connection.py - Transactions table · Shared expense records: item, price, quantity, and purchase date.
- MySQL 8.0
docker-compose.yml - Sample data seed
scripts/seed.sql - Runtime config · Supplies Gemini API and database credentials.
.env.example - Shared runtime utilities · Provides configuration, logging, and date handling.
shared/config_logging.py
Connections 17
- Chat styling → Streamlit chat app: styles
- Streamlit chat app → Gemini agent: user question
- Gemini agent → Finance prompts: loads context
- Gemini agent → Google Gemini API: interprets and generates
- Gemini agent → MCP server: invokes tools
- MCP server → Expense item lookup: exposes
- MCP server → Expense summaries: exposes
- Expense item lookup → MySQL query layer: parameterized lookup
- Expense summaries → MySQL query layer: parameterized aggregation
- MySQL query layer → Transactions table: queries
- MySQL 8.0 → Transactions table: hosts
- Sample data seed → Transactions table: provisions
- Runtime config → Gemini agent: API key
- Runtime config → MySQL query layer: DB credentials
- Shared runtime utilities → MCP server: runtime support
- MCP server → Gemini agent: structured results
- Gemini agent → Streamlit chat app: formatted response