This commit is contained in:
@@ -35,16 +35,20 @@ class AppMCPServerController(Resource):
|
|||||||
@get_app_model
|
@get_app_model
|
||||||
@marshal_with(app_server_fields)
|
@marshal_with(app_server_fields)
|
||||||
def post(self, app_model):
|
def post(self, app_model):
|
||||||
# The role of the current user in the ta table must be editor, admin, or owner
|
|
||||||
if not current_user.is_editor:
|
if not current_user.is_editor:
|
||||||
raise NotFound()
|
raise NotFound()
|
||||||
parser = reqparse.RequestParser()
|
parser = reqparse.RequestParser()
|
||||||
parser.add_argument("description", type=str, required=True, location="json")
|
parser.add_argument("description", type=str, required=False, location="json")
|
||||||
parser.add_argument("parameters", type=dict, required=True, location="json")
|
parser.add_argument("parameters", type=dict, required=True, location="json")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
description = args.get("description")
|
||||||
|
if not description:
|
||||||
|
description = app_model.description or ""
|
||||||
|
|
||||||
server = AppMCPServer(
|
server = AppMCPServer(
|
||||||
name=app_model.name,
|
name=app_model.name,
|
||||||
description=args["description"],
|
description=description,
|
||||||
parameters=json.dumps(args["parameters"], ensure_ascii=False),
|
parameters=json.dumps(args["parameters"], ensure_ascii=False),
|
||||||
status=AppMCPServerStatus.ACTIVE,
|
status=AppMCPServerStatus.ACTIVE,
|
||||||
app_id=app_model.id,
|
app_id=app_model.id,
|
||||||
@@ -65,14 +69,22 @@ class AppMCPServerController(Resource):
|
|||||||
raise NotFound()
|
raise NotFound()
|
||||||
parser = reqparse.RequestParser()
|
parser = reqparse.RequestParser()
|
||||||
parser.add_argument("id", type=str, required=True, location="json")
|
parser.add_argument("id", type=str, required=True, location="json")
|
||||||
parser.add_argument("description", type=str, required=True, location="json")
|
parser.add_argument("description", type=str, required=False, location="json")
|
||||||
parser.add_argument("parameters", type=dict, required=True, location="json")
|
parser.add_argument("parameters", type=dict, required=True, location="json")
|
||||||
parser.add_argument("status", type=str, required=False, location="json")
|
parser.add_argument("status", type=str, required=False, location="json")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
server = db.session.query(AppMCPServer).filter(AppMCPServer.id == args["id"]).first()
|
server = db.session.query(AppMCPServer).filter(AppMCPServer.id == args["id"]).first()
|
||||||
if not server:
|
if not server:
|
||||||
raise NotFound()
|
raise NotFound()
|
||||||
server.description = args["description"]
|
|
||||||
|
description = args.get("description")
|
||||||
|
if description is None:
|
||||||
|
pass
|
||||||
|
elif not description:
|
||||||
|
server.description = app_model.description or ""
|
||||||
|
else:
|
||||||
|
server.description = description
|
||||||
|
|
||||||
server.parameters = json.dumps(args["parameters"], ensure_ascii=False)
|
server.parameters = json.dumps(args["parameters"], ensure_ascii=False)
|
||||||
if args["status"]:
|
if args["status"]:
|
||||||
if args["status"] not in [status.value for status in AppMCPServerStatus]:
|
if args["status"] not in [status.value for status in AppMCPServerStatus]:
|
||||||
|
@@ -23,6 +23,7 @@ export type ModalProps = {
|
|||||||
data?: MCPServerDetail
|
data?: MCPServerDetail
|
||||||
show: boolean
|
show: boolean
|
||||||
onHide: () => void
|
onHide: () => void
|
||||||
|
appInfo?: any
|
||||||
}
|
}
|
||||||
|
|
||||||
const MCPServerModal = ({
|
const MCPServerModal = ({
|
||||||
@@ -31,13 +32,15 @@ const MCPServerModal = ({
|
|||||||
data,
|
data,
|
||||||
show,
|
show,
|
||||||
onHide,
|
onHide,
|
||||||
|
appInfo,
|
||||||
}: ModalProps) => {
|
}: ModalProps) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { mutateAsync: createMCPServer, isPending: creating } = useCreateMCPServer()
|
const { mutateAsync: createMCPServer, isPending: creating } = useCreateMCPServer()
|
||||||
const { mutateAsync: updateMCPServer, isPending: updating } = useUpdateMCPServer()
|
const { mutateAsync: updateMCPServer, isPending: updating } = useUpdateMCPServer()
|
||||||
const invalidateMCPServerDetail = useInvalidateMCPServerDetail()
|
const invalidateMCPServerDetail = useInvalidateMCPServerDetail()
|
||||||
|
|
||||||
const [description, setDescription] = React.useState(data?.description || '')
|
const defaultDescription = data?.description || appInfo?.description || ''
|
||||||
|
const [description, setDescription] = React.useState(defaultDescription)
|
||||||
const [params, setParams] = React.useState(data?.parameters || {})
|
const [params, setParams] = React.useState(data?.parameters || {})
|
||||||
|
|
||||||
const handleParamChange = (variable: string, value: string) => {
|
const handleParamChange = (variable: string, value: string) => {
|
||||||
@@ -58,21 +61,27 @@ const MCPServerModal = ({
|
|||||||
|
|
||||||
const submit = async () => {
|
const submit = async () => {
|
||||||
if (!data) {
|
if (!data) {
|
||||||
await createMCPServer({
|
const payload: any = {
|
||||||
appID,
|
appID,
|
||||||
description,
|
|
||||||
parameters: getParamValue(),
|
parameters: getParamValue(),
|
||||||
})
|
}
|
||||||
|
|
||||||
|
if (description.trim())
|
||||||
|
payload.description = description
|
||||||
|
|
||||||
|
await createMCPServer(payload)
|
||||||
invalidateMCPServerDetail(appID)
|
invalidateMCPServerDetail(appID)
|
||||||
onHide()
|
onHide()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
await updateMCPServer({
|
const payload: any = {
|
||||||
appID,
|
appID,
|
||||||
id: data.id,
|
id: data.id,
|
||||||
description,
|
|
||||||
parameters: getParamValue(),
|
parameters: getParamValue(),
|
||||||
})
|
}
|
||||||
|
|
||||||
|
payload.description = description
|
||||||
|
await updateMCPServer(payload)
|
||||||
invalidateMCPServerDetail(appID)
|
invalidateMCPServerDetail(appID)
|
||||||
onHide()
|
onHide()
|
||||||
}
|
}
|
||||||
|
@@ -223,6 +223,7 @@ function MCPServiceCard({
|
|||||||
data={serverPublished ? detail : undefined}
|
data={serverPublished ? detail : undefined}
|
||||||
latestParams={latestParams}
|
latestParams={latestParams}
|
||||||
onHide={handleServerModalHide}
|
onHide={handleServerModalHide}
|
||||||
|
appInfo={appInfo}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{/* button copy link/ button regenerate */}
|
{/* button copy link/ button regenerate */}
|
||||||
|
@@ -206,7 +206,7 @@ export const useCreateMCPServer = () => {
|
|||||||
mutationKey: [NAME_SPACE, 'create-mcp-server'],
|
mutationKey: [NAME_SPACE, 'create-mcp-server'],
|
||||||
mutationFn: (payload: {
|
mutationFn: (payload: {
|
||||||
appID: string
|
appID: string
|
||||||
description: string
|
description?: string
|
||||||
parameters?: Record<string, string>
|
parameters?: Record<string, string>
|
||||||
}) => {
|
}) => {
|
||||||
const { appID, ...rest } = payload
|
const { appID, ...rest } = payload
|
||||||
|
Reference in New Issue
Block a user