1
- import modelscope_studio .components .antd as antd
2
- import modelscope_studio .components .base as ms
1
+ # flake8: noqa: F401
3
2
import gradio as gr
4
3
import json
4
+ import modelscope_studio .components .antd as antd
5
+ import modelscope_studio .components .base as ms
5
6
6
7
7
8
def AddMcpServerButton ():
8
- with antd .Button ("添加 MCP Server" , type = "primary" ,
9
- size = "small" ) as add_mcp_server_btn :
10
- with ms .Slot ("icon" ):
11
- antd .Icon ("PlusOutlined" )
9
+ with antd .Button (
10
+ '添加 MCP Server' , type = 'primary' ,
11
+ size = 'small' ) as add_mcp_server_btn :
12
+ with ms .Slot ('icon' ):
13
+ antd .Icon ('PlusOutlined' )
12
14
with antd .Modal (
13
- title = " 添加 MCP Server" ,
15
+ title = ' 添加 MCP Server' ,
14
16
footer = False ,
15
- styles = dict (footer = dict (display = " none" ))) as add_mcp_server_modal :
17
+ styles = dict (footer = dict (display = ' none' ))) as add_mcp_server_modal :
16
18
with antd .Tabs ():
17
- with antd .Tabs .Item (label = "表单添加" ):
18
- with antd .Form (layout = "vertical" ) as add_mcp_server_form :
19
- with antd .Form .Item (form_name = "name" ,
20
- label = "名称" ,
21
- rules = [{
22
- "required" : True
23
- }]):
24
- antd .Input (placeholder = "MCP Server 名称,如 fetch、time 等" )
25
- with antd .Form .Item (form_name = "url" ,
26
- label = "SSE 链接" ,
27
- rules = [{
28
- "required" : True
29
- }]):
30
- antd .Input (placeholder = "MCP Server SSE 链接" )
31
- with antd .Flex (gap = "small" , justify = "end" ):
32
- add_mcp_server_modal_cancel_btn = antd .Button ("取消" )
33
- antd .Button ("确定" , html_type = "submit" , type = "primary" )
34
- with antd .Tabs .Item (label = "JSON 添加" ):
35
- with antd .Form (layout = "vertical" ) as add_mcp_server_json_form :
36
- with antd .Form .Item (form_name = "json" ,
37
- label = "JSON" ,
38
- rules = [{
39
- "required" :
40
- True ,
41
- "validator" :
42
- """(_, value) => {
19
+ with antd .Tabs .Item (label = '表单添加' ):
20
+ with antd .Form (layout = 'vertical' ) as add_mcp_server_form :
21
+ with antd .Form .Item (
22
+ form_name = 'name' ,
23
+ label = '名称' ,
24
+ rules = [{
25
+ 'required' : True
26
+ }]):
27
+ antd .Input (placeholder = 'MCP Server 名称,如 fetch、time 等' )
28
+ with antd .Form .Item (
29
+ form_name = 'url' ,
30
+ label = 'SSE 链接' ,
31
+ rules = [{
32
+ 'required' : True
33
+ }]):
34
+ antd .Input (placeholder = 'MCP Server SSE 链接' )
35
+ with antd .Flex (gap = 'small' , justify = 'end' ):
36
+ add_mcp_server_modal_cancel_btn = antd .Button ('取消' )
37
+ antd .Button ('确定' , html_type = 'submit' , type = 'primary' )
38
+ with antd .Tabs .Item (label = 'JSON 添加' ):
39
+ with antd .Form (layout = 'vertical' ) as add_mcp_server_json_form :
40
+ with antd .Form .Item (
41
+ form_name = 'json' ,
42
+ label = 'JSON' ,
43
+ rules = [{
44
+ 'required' :
45
+ True ,
46
+ 'validator' :
47
+ """(_, value) => {
43
48
if (!value) {
44
49
return Promise.reject('请输入 JSON 值');
45
50
}
@@ -53,40 +58,43 @@ def AddMcpServerButton():
53
58
return Promise.reject('请输入有效的 JSON 值');
54
59
}
55
60
} """
56
- }]):
61
+ }]):
57
62
antd .Input .Textarea (
58
63
auto_size = dict (minRows = 4 , maxRows = 8 ),
59
64
placeholder = json .dumps (
60
65
{
61
- " mcpServers" : {
62
- " fetch" : {
63
- " type" : " sse" ,
64
- " url" : " mcp server sse url"
66
+ ' mcpServers' : {
67
+ ' fetch' : {
68
+ ' type' : ' sse' ,
69
+ ' url' : ' mcp server sse url'
65
70
}
66
71
}
67
72
},
68
73
indent = 4 ))
69
- with antd .Flex (gap = " small" , justify = " end" ):
74
+ with antd .Flex (gap = ' small' , justify = ' end' ):
70
75
add_mcp_server_modal_json_cancel_btn = antd .Button (
71
- "取消" )
72
- antd .Button ("确定" , html_type = "submit" , type = "primary" )
73
- add_mcp_server_btn .click (fn = lambda : gr .update (open = True ),
74
- outputs = [add_mcp_server_modal ],
75
- queue = False )
76
- gr .on (triggers = [
77
- add_mcp_server_modal_cancel_btn .click ,
78
- add_mcp_server_modal_json_cancel_btn .click , add_mcp_server_modal .cancel
79
- ],
80
- queue = False ,
81
- fn = lambda : gr .update (open = False ),
82
- outputs = [add_mcp_server_modal ])
76
+ '取消' )
77
+ antd .Button ('确定' , html_type = 'submit' , type = 'primary' )
78
+ add_mcp_server_btn .click (
79
+ fn = lambda : gr .update (open = True ),
80
+ outputs = [add_mcp_server_modal ],
81
+ queue = False )
82
+ gr .on (
83
+ triggers = [
84
+ add_mcp_server_modal_cancel_btn .click ,
85
+ add_mcp_server_modal_json_cancel_btn .click ,
86
+ add_mcp_server_modal .cancel
87
+ ],
88
+ queue = False ,
89
+ fn = lambda : gr .update (open = False ),
90
+ outputs = [add_mcp_server_modal ])
83
91
add_mcp_server_form .finish (
84
92
lambda : (gr .update (value = {
85
- " name" : "" ,
86
- " url" : "" ,
93
+ ' name' : '' ,
94
+ ' url' : '' ,
87
95
}), gr .update (open = False )),
88
96
outputs = [add_mcp_server_form , add_mcp_server_modal ])
89
97
add_mcp_server_json_form .finish (
90
- lambda : (gr .update (value = {" json" : "" }), gr .update (open = False )),
98
+ lambda : (gr .update (value = {' json' : '' }), gr .update (open = False )),
91
99
outputs = [add_mcp_server_json_form , add_mcp_server_modal ])
92
100
return add_mcp_server_form , add_mcp_server_json_form
0 commit comments