84 lines
2.1 KiB
Python
84 lines
2.1 KiB
Python
"""MCP server API schema(skills-design §5)。
|
||
|
||
支持两种传输协议:streamable-http / stdio。
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
from datetime import datetime
|
||
from typing import Any
|
||
|
||
from pydantic import BaseModel, Field
|
||
|
||
from app.schemas.common import OrmModel
|
||
|
||
|
||
class CreateMcpServerRequest(BaseModel):
|
||
name: str = Field(min_length=1)
|
||
transport: str = Field(
|
||
default="streamable-http",
|
||
description="传输协议:streamable-http | stdio",
|
||
)
|
||
# streamable-http 用
|
||
endpoint_url: str | None = None
|
||
auth_token: str | None = None
|
||
# stdio 用
|
||
command: str | None = Field(
|
||
default=None,
|
||
description="stdio 可执行文件路径,如 npx",
|
||
)
|
||
args_json: str | None = Field(
|
||
default=None,
|
||
description='启动参数 JSON list,如 \'["-y","@modelcontextprotocol/server-filesystem"]\'',
|
||
)
|
||
env_json: str | None = Field(
|
||
default=None,
|
||
description="环境变量 JSON dict",
|
||
)
|
||
cwd: str | None = Field(default=None, description="工作目录")
|
||
status: str = "enabled"
|
||
|
||
|
||
class McpServerResponse(OrmModel):
|
||
"""MCP server 响应(不暴露 auth_token 原文,仅 has_auth_token)。"""
|
||
|
||
id: str
|
||
name: str
|
||
transport: str
|
||
endpoint_url: str | None
|
||
has_auth_token: bool = False
|
||
command: str | None
|
||
args_json: str | None
|
||
env_json: str | None
|
||
cwd: str | None
|
||
status: str
|
||
tools: list[dict[str, Any]] = Field(default_factory=list)
|
||
created_at: datetime
|
||
updated_at: datetime
|
||
|
||
|
||
class UpdateMcpServerRequest(BaseModel):
|
||
"""更新 MCP server(部分字段)。"""
|
||
|
||
status: str | None = Field(
|
||
default=None,
|
||
description="启用状态:enabled | disabled",
|
||
)
|
||
endpoint_url: str | None = None
|
||
auth_token: str | None = None
|
||
command: str | None = None
|
||
args_json: str | None = None
|
||
env_json: str | None = None
|
||
cwd: str | None = None
|
||
|
||
|
||
class McpServerStatusResponse(BaseModel):
|
||
"""MCP server 进程状态。"""
|
||
|
||
server_id: str
|
||
name: str
|
||
transport: str
|
||
status: str # running | stopped | error
|
||
pid: int | None = None
|
||
uptime_seconds: float | None = None
|