使用说明
零售银行系统
使用Python、SQLite和MCP实现的简单零售银行系统。该系统通过MCP工具界面提供银行操作。
特性
-
账户管理
- 创建新账户(储蓄/支票)
- 关闭现有帐户
- 更新帐户详细信息
- 查看帐户信息
-
交易操作
- 存款基金
- 提取资金
- 账户间转账
- 通过日期过滤查看交易历史记录
设置
- 创建并激活虚拟环境:
uv venv
source .venv/bin/activate # On Unix/macOS
# or
.venv\Scripts\activate # On Windows
- 安装包含所有依赖项的项目:
uv pip install -e .
- 运行组合服务器:
python combined_server.py
系统将启动:
- 上的REST API服务器
http://localhost:8000 - MCP工具接口
- SQLite数据库(
banking.db)将在首次运行时自动创建 - API文件可在
http://localhost:8000/docs
开发设置
对于开发,您可能需要安装其他工具:
# Install development dependencies
uv pip install black ruff pytest
# Format code
black .
# Run linting
ruff check .
# Run tests
pytest
REST API端点
账户
- 创建账户
POST /accounts/
Content-Type: application/json
{
"holder_name": "John Doe",
"account_type": "savings",
"initial_deposit": 1000.0
}
- 获取账户余额
GET /accounts/{account_id}/balance
- 列出所有帐户
GET /accounts/
- 更新帐户
PATCH /accounts/{account_id}
Content-Type: application/json
{
"holder_name": "John Smith",
"account_type": "checking"
}
- 关闭帐户
DELETE /accounts/{account_id}
交易
- 存款
POST /accounts/{account_id}/deposit
Content-Type: application/json
{
"amount": 500.0,
"description": "Salary deposit"
}
- 取钱
POST /accounts/{account_id}/withdraw
Content-Type: application/json
{
"amount": 200.0,
"description": "ATM withdrawal"
}
- 转移资金
POST /transfer/
Content-Type: application/json
{
"from_account": "acc123",
"to_account": "acc456",
"amount": 300.0
}
- 获取交易历史记录
GET /accounts/{account_id}/history?start_date=2024-03-01&end_date=2024-03-31
MCP工具
以下操作可通过MCP接口进行:
- 创建帐户:
mcp_open_new_account("John Doe", "savings", 1000)
- 存款金额:
mcp_deposit_money("acc123", 500, "Salary deposit")
- 提款:
mcp_withdraw_money("acc123", 200, "ATM withdrawal")
- 转账资金:
mcp_transfer_funds("acc123", "acc456", 300)
- 检查余额:
mcp_check_balance("acc123")
- 查看交易历史记录:
mcp_get_transaction_history("acc123", "2024-03-01", "2024-03-31")
- 列出帐户:
mcp_list_accounts()
数据库模式
账目表
- account_id(TEXT):主键
- holder_name(文本):账户持有人的姓名
- account_type(TEXT):账户类型(储蓄/支票)
- 余额(REAL):当前余额
- 状态(文本):帐户状态(活动/关闭)
- created_at(TEXT):帐户创建日期
交易记录表
- id(INTEGER):主键
- account_id(TEXT):帐户的外键
- 类型(TEXT):交易类型(贷记/借记)
- 金额(REAL):交易金额
- description(TEXT):交易描述
- balance_after(REAL):交易后余额
- timestamp(TEXT):交易时间戳
