银行工具MCP服务器

一个为UiPath自动化工作流提供银行相关工具和实用程序的模型上下文协议(MCP)服务器,包括客户数据检索、资金持有分析、信用评估和客户风险全面评估等功能。

  • by SATMAN778
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 SATMAN778/example-mcp-server

使用说明

银行工具MCP服务器

一种模型上下文协议(MCP)服务器实现,为UiPath自动化工作流提供银行相关工具和实用程序。该服务器提供用于客户数据检索、基金持有分析、信用评估和全面客户风险评估的工具。

特性

  • 🏦 客户信息检索

    • 异步PostgreSQL数据库集成
    • 高效的连接池
    • 全面的错误处理
  • 📊 基金持股分析

    • 用pandas处理Excel文件
    • 资产配置计算
    • 历史持股跟踪
  • 🔍 信用评估

    • 制裁名单核查
    • 新闻情绪分析
    • 风险评分计算
  • 🏥 健康监测

    • 数据库连接检查
    • 服务状态监控
    • 依赖性健康跟踪

安装

  1. 使用创建Python虚拟环境 uv:
uv venv
  1. 安装依赖项:
uv pip install fastapi sqlalchemy pandas python-dotenv asyncpg aiohttp
  1. 设置环境变量:
# Copy the example environment file
cp .env.example .env

# Edit .env with your configuration
notepad .env  # or use your preferred editor

配置

服务器是通过环境变量配置的。创建一个 .env 具有以下设置的文件:

# Database Configuration
DB_HOST=localhost
DB_PORT=5432
DB_NAME=banking_db
DB_USER=your_username
DB_PASSWORD=your_password
DB_POOL_SIZE=5
DB_MAX_OVERFLOW=10
DB_ECHO=False

# File Storage Configuration
DATA_DIR=data/holdings

# API Endpoints
SANCTIONS_API_URL=https://api.sanctions-check.example
NEWS_API_URL=https://api.news-sentiment.example

用法

运行服务器

# Start the server
uvicorn server:mcp --reload

可用工具

  1. get_customer_info

    result = await get_customer_info("12345")
    print(f"Customer details: {result}")
    
  2. get_fund_holdings

    holdings = await get_fund_holdings("12345", "2025-09")
    print(f"Total value: ${holdings['total_value']}")
    
  3. 检查信誉

    credit = await check_credit_worthiness("John Doe", "Acme Corp")
    print(f"Credit score: {credit['credit_score']}")
    
  4. 评估_客户

    assessment = await assess_customer("12345", "2025-09")
    print(f"Risk score: {assessment['risk_score']}")
    print(f"Recommendations: {assessment['recommendations']}")
    

健康检查

服务器提供了一个健康检查端点,用于监视:

  • 服务器状态
  • 数据库连接
  • 服务依赖关系

数据库模式

服务器需要以下数据库架构:

CREATE TABLE customers (
    id VARCHAR PRIMARY KEY,
    full_name VARCHAR NOT NULL,
    -- Add other customer fields
);

CREATE TABLE accounts (
    id VARCHAR PRIMARY KEY,
    customer_id VARCHAR REFERENCES customers(id),
    account_number VARCHAR NOT NULL,
    account_type VARCHAR NOT NULL,
    balance DECIMAL NOT NULL
    -- Add other account fields
);

文件结构

基金持有数据应按如下方式组织:

data/
└── holdings/
    └── YYYY-MM/
        └── customer_ID.xlsx

每个Excel文件应包含以下列:

  • value:持有价值
  • asset_class:资产类型
  • 其他相关基金信息

错误处理

服务器实现了全面的错误处理:

  • 数据库连接问题
  • 数据缺失或无效
  • API服务故障
  • 文件访问问题

所有错误都会返回相应的HTTP状态代码和详细的错误消息。

生产注意事项

  1. 安全

    • 使用适当的身份验证/授权
    • 实施速率限制
    • 保护敏感端点
    • 使用生产级证书
  2. 演出

    • 配置适当的池大小
    • 在需要的地方实施缓存
    • 监控资源使用情况
  3. 监控

    • 设置适当的日志记录
    • 配置警报
    • 监控数据库性能

发展

添加新工具

  1. 使用正确的类型创建一个新的异步函数
  2. 添加全面的文档字符串
  3. 使用 @mcp.tool() 装饰器
  4. 实施错误处理
  5. 更新测试和文档

例子:

@mcp.tool()
async def new_banking_tool() -> Dict[str, Any]:
    """Tool description and documentation."""
    try:
        # Implementation
        return {"result": "success"}
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))

贡献

  1. 复刻仓库
  2. 创建要素分支
  3. 实施您的更改
  4. 添加/更新测试
  5. 提交拉取请求

许可证

此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。