Files
FastapiAdmin/backend/app/mcp_server/tool_table.py
T
zhangtao ecec6ceadb feat: 新增MCP服务器和客户端功能,支持AI工具调用和天气查询
refactor: 重构基础模型和响应类,增加success字段

fix: 修复定时任务日志记录和异常处理问题

style: 调整中间件日志记录逻辑,优化参数处理

docs: 更新数据库配置和依赖项说明

perf: 优化文件上传服务,支持OSS存储

test: 添加定时任务日志模型和参数验证

chore: 更新依赖项,添加openai库支持
2025-08-30 13:22:48 +08:00

31 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import json
from fastapi.encoders import jsonable_encoder
from sqlalchemy import select
from config.database import Base
from config.get_db import get_db
import logging
from module_admin.entity.do.car_driver_do import CarDriver
from module_admin.entity.do.student_info_do import StudentInfo
class TableTool:
logger = logging.getLogger(__name__)
# 因为mcp服务是在另外进程里面,需要导入模型,否则Base.registry.mappers是空的
support_modules = [CarDriver, StudentInfo]
@classmethod
async def fetch_table_data(cls, table_name: str) -> str:
async for query_db in get_db():
for mapper in Base.registry.mappers:
table_cls = mapper.class_
if hasattr(table_cls, '__tablename__') and table_cls.__tablename__ == table_name:
result = await query_db.execute(select(table_cls))
data = result.scalars().all()
json_str = json.dumps(jsonable_encoder(data), ensure_ascii=False)
return json_str
raise ValueError(f"No model found for table name: {table_name},to check if you have imported it")