mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-09-17 23:37:15 +00:00
refactor: api
This commit is contained in:
@@ -10,9 +10,10 @@ from .. import group
|
|||||||
@group.group_class('mcp', '/api/v1/mcp')
|
@group.group_class('mcp', '/api/v1/mcp')
|
||||||
class MCPRouterGroup(group.RouterGroup):
|
class MCPRouterGroup(group.RouterGroup):
|
||||||
async def initialize(self) -> None:
|
async def initialize(self) -> None:
|
||||||
@self.route('/servers', methods=['GET'], auth_type=group.AuthType.USER_TOKEN)
|
@self.route('/servers', methods=['GET', 'POST'], auth_type=group.AuthType.USER_TOKEN)
|
||||||
async def _() -> str:
|
async def _() -> str:
|
||||||
"""获取MCP服务器列表"""
|
"""获取MCP服务器列表"""
|
||||||
|
if quart.request.method == 'GET':
|
||||||
if not self.ap or not self.ap.provider_cfg or not self.ap.provider_cfg.data:
|
if not self.ap or not self.ap.provider_cfg or not self.ap.provider_cfg.data:
|
||||||
return self.success(data={'servers': []})
|
return self.success(data={'servers': []})
|
||||||
|
|
||||||
@@ -52,10 +53,7 @@ class MCPRouterGroup(group.RouterGroup):
|
|||||||
servers_with_status.append(server_info)
|
servers_with_status.append(server_info)
|
||||||
|
|
||||||
return self.success(data={'servers': servers_with_status})
|
return self.success(data={'servers': servers_with_status})
|
||||||
|
elif quart.request.method == 'POST':
|
||||||
@self.route('/servers', methods=['POST'], auth_type=group.AuthType.USER_TOKEN)
|
|
||||||
async def _() -> str:
|
|
||||||
"""创建MCP服务器配置"""
|
|
||||||
data = await quart.request.json
|
data = await quart.request.json
|
||||||
|
|
||||||
# 验证必填字段
|
# 验证必填字段
|
||||||
@@ -91,7 +89,11 @@ class MCPRouterGroup(group.RouterGroup):
|
|||||||
)
|
)
|
||||||
elif data['mode'] == 'sse':
|
elif data['mode'] == 'sse':
|
||||||
new_server.update(
|
new_server.update(
|
||||||
{'url': data.get('url', ''), 'headers': data.get('headers', {}), 'timeout': data.get('timeout', 10)}
|
{
|
||||||
|
'url': data.get('url', ''),
|
||||||
|
'headers': data.get('headers', {}),
|
||||||
|
'timeout': data.get('timeout', 10),
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
# 添加到配置
|
# 添加到配置
|
||||||
@@ -112,8 +114,10 @@ class MCPRouterGroup(group.RouterGroup):
|
|||||||
context=ctx,
|
context=ctx,
|
||||||
)
|
)
|
||||||
return self.success(data={'task_id': wrapper.id})
|
return self.success(data={'task_id': wrapper.id})
|
||||||
|
else:
|
||||||
return self.success()
|
return self.success()
|
||||||
|
else:
|
||||||
|
return self.http_status(405, -1, 'Method not allowed')
|
||||||
|
|
||||||
@self.route('/servers/<server_name>', methods=['GET', 'PUT', 'DELETE'], auth_type=group.AuthType.USER_TOKEN)
|
@self.route('/servers/<server_name>', methods=['GET', 'PUT', 'DELETE'], auth_type=group.AuthType.USER_TOKEN)
|
||||||
async def _(server_name: str) -> str:
|
async def _(server_name: str) -> str:
|
||||||
|
|||||||
Reference in New Issue
Block a user