Prompts and Resources Management
Relevant source files
The following files were used as context for generating this wiki page:
The Prompts and Resources Management system within the mbbank-mcp project serves as a bridge between the Model Context Protocol (MCP) and the MBBank banking API. This system manages the lifecycle of bank-related data (resources) and the interactive tools (prompts/tools) used to query or manipulate that data. It ensures that sensitive financial information, such as account balances, transaction histories, and card details, is retrieved securely and presented in a structured format compatible with MCP clients.
The system is built on top of the FastMCP framework, which facilitates the creation of MCP servers. It handles authentication via the mbbank-lib and provides a variety of tools for monitoring, analytics, and managed financial transfers.
Sources: mbbank_mcp/core.py:1-20, README.md:1-10, mbbank_mcp/main.py:36-45
Core Architecture and Server Initialization
The server initialization process involves setting up a FastMCP instance and authenticating with the MBBank asynchronous client. The server supports both Standard Input/Output (stdio) and Server-Sent Events (SSE) communication modes.
The diagram shows the initialization flow from authentication to server execution mode selection.
Sources: mbbank_mcp/main.py:36-74, mbbank_mcp/core.py:22-26
Server Configuration Options
| Option | Environment Variable | Default | Description |
|---|---|---|---|
--username | MBBANK_USERNAME | None | MBBank account username |
--password | MBBANK_PASSWORD | None | MBBank account password |
--host | N/A | localhost | Host for SSE mode |
--port | N/A | 3000 | Port for SSE mode |
--sse | N/A | False | Enables SSE and Streamable HTTP mode |
Sources: mbbank_mcp/main.py:23-35, README.md:46-52
Resource and Tool Management
The system exposes banking data through defined MCP tools. These tools act as the primary interface for an LLM or MCP client to interact with the bank's resources.
Account and Balance Resources
The get_balances tool retrieves current information for both domestic and international accounts. The data is mapped to structured Pydantic models to ensure consistency.
| Tool Name | Return Type | Description |
|---|---|---|
get_balances | BalancesModel | Fetches balances for all accounts |
get_bank_list | dict[str, str] | Returns mapping of bank codes to names |
get_today_date | str | Returns date in dd-mm-yyyy format |
Sources: mbbank_mcp/core.py:126-155, mbbank_mcp/modals.py:7-17
Transaction and Card Monitoring
Transactions can be queried for specific accounts or cards over a defined date range. The system standardizes the display of credits and debits.
This sequence diagram illustrates the flow of a transaction history request.
Sources: mbbank_mcp/core.py:157-187, mbbank_mcp/modals.py:25-36
Transfer State Management
A specialized state management system is implemented for money transfers. Since transfers require multi-step verification (QR code generation followed by OTP confirmation), the server maintains a temporary transfer_manager.
Transfer Lifecycle Logic
- Initiation:
start_transfercreates aTransferContextAsyncand stores it intransfer_managerwith a unique session ID (SID). - QR Generation: A QR code is generated for the user to scan via the MBBank app (D-OTP).
- Expiration: Transfer sessions are strictly limited to 120 seconds. An asynchronous task handles the cleanup of expired sessions.
- Verification:
verify_transferuses the SID and user-provided OTP to finalize the transaction.
The flow of managed transfers including the background expiration mechanism.
Sources: mbbank_mcp/core.py:30-124
Transfer State Structure
class TransferState(TypedDict):
create_time: float
state: TransferContextAsync
Sources: mbbank_mcp/core.py:18-20
Savings and Interest Rate Resources
The system provides detailed access to saving accounts, categorized into Online Savings Accounts (OSA) and Branch Saving Accounts (SBA).
Savings Data Models
| Field | Type | Description |
|---|---|---|
principalAmount | int/float | The initial deposit amount |
ratePercentPerYear | int/float | The annual interest rate |
maturityDate | str | The date the saving term ends |
accruedInterest | str | Interest earned to date (in get_saving_details) |
Sources: mbbank_mcp/modals.py:46-77, mbbank_mcp/core.py:228-278
Conclusion
The Prompts and Resources Management system in mbbank-mcp effectively abstracts the complexities of the MBBank API into a set of manageable MCP tools. By utilizing structured data models and a robust transfer state manager, it provides a secure and predictable interface for monitoring financial assets and executing verified transfers within the Model Context Protocol ecosystem.