"""百工 MCP server 模型(skills-design §5)。 注册的 MCP server 元数据 + 拉取缓存的工具清单(tools_json),供启动加载与 转 ToolSpec register。 支持两种传输协议: - streamable-http:通过 endpoint_url POST /message(标准 MCP Streamable HTTP) - stdio:通过子进程 stdin/stdout 通信(本地 MCP 集成) """ from datetime import datetime from sqlalchemy import DateTime, String, Text from sqlalchemy.orm import Mapped, mapped_column from app.core.ids import new_mcp_server_id from app.core.time import utc_now from app.db.base import Base class McpServer(Base): """MCP server 注册记录。""" __tablename__ = "mcp_servers" id: Mapped[str] = mapped_column(String(80), primary_key=True, default=new_mcp_server_id) name: Mapped[str] = mapped_column(String(120), nullable=False, unique=True) transport: Mapped[str] = mapped_column(String(40), nullable=False, default="streamable-http") # streamable-http 用 endpoint_url: Mapped[str | None] = mapped_column(String(500)) auth_token: Mapped[str | None] = mapped_column(String(500)) # stdio 用 command: Mapped[str | None] = mapped_column(String(500)) args_json: Mapped[str | None] = mapped_column(Text) # JSON list env_json: Mapped[str | None] = mapped_column(Text) # JSON dict cwd: Mapped[str | None] = mapped_column(String(500)) # 通用 status: Mapped[str] = mapped_column(String(40), nullable=False, default="enabled", index=True) tools_json: Mapped[str] = mapped_column(Text, nullable=False, default="[]") created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default=utc_now) updated_at: Mapped[datetime] = mapped_column( DateTime(timezone=True), default=utc_now, onupdate=utc_now )