auto-coder-web 0.1.58__py3-none-any.whl → 0.1.60__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- auto_coder_web/routers/mcp_router.py +188 -0
- auto_coder_web/version.py +1 -1
- auto_coder_web/web/assets/{cssMode-CHKgyP7k.js → cssMode-C28WkqEl.js} +1 -1
- auto_coder_web/web/assets/{freemarker2-VecMn0a-.js → freemarker2-ZqPV3OAn.js} +1 -1
- auto_coder_web/web/assets/{handlebars-suCFZKB1.js → handlebars-BeVH6MoZ.js} +1 -1
- auto_coder_web/web/assets/{html-BaTdlezw.js → html-CbnuufYM.js} +1 -1
- auto_coder_web/web/assets/{htmlMode-DVw8dO4V.js → htmlMode-CpsZVLwy.js} +1 -1
- auto_coder_web/web/assets/{index-CDEGkh-B.css → index-Bnnll9cx.css} +2 -2
- auto_coder_web/web/assets/{index-LPF9pOVA.js → index-U694gZ5i.js} +416 -396
- auto_coder_web/web/assets/{javascript-DzFj73X-.js → javascript-CUA7SFHC.js} +1 -1
- auto_coder_web/web/assets/{jsonMode-B7e1-bLg.js → jsonMode-BzAAFwlN.js} +1 -1
- auto_coder_web/web/assets/{liquid-CMLQaZc5.js → liquid-B1UkAnrE.js} +1 -1
- auto_coder_web/web/assets/{mdx-DCeMDiMx.js → mdx-2eOqd4a8.js} +1 -1
- auto_coder_web/web/assets/{python-BfbGk_j0.js → python-DadwP7sa.js} +1 -1
- auto_coder_web/web/assets/{razor-NtK1iBZB.js → razor-CCybM3Rs.js} +1 -1
- auto_coder_web/web/assets/{tsMode-9oawC9nC.js → tsMode-Bk47zhhf.js} +1 -1
- auto_coder_web/web/assets/{typescript-yE4BX-q5.js → typescript-vvCv9Db5.js} +1 -1
- auto_coder_web/web/assets/{xml-Cy76E2H9.js → xml-CLM5-Fko.js} +1 -1
- auto_coder_web/web/assets/{yaml-LzxmQTR9.js → yaml-BF217FNY.js} +1 -1
- auto_coder_web/web/index.html +2 -2
- {auto_coder_web-0.1.58.dist-info → auto_coder_web-0.1.60.dist-info}/METADATA +2 -2
- {auto_coder_web-0.1.58.dist-info → auto_coder_web-0.1.60.dist-info}/RECORD +25 -24
- {auto_coder_web-0.1.58.dist-info → auto_coder_web-0.1.60.dist-info}/WHEEL +0 -0
- {auto_coder_web-0.1.58.dist-info → auto_coder_web-0.1.60.dist-info}/entry_points.txt +0 -0
- {auto_coder_web-0.1.58.dist-info → auto_coder_web-0.1.60.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,188 @@
|
|
1
|
+
import asyncio
|
2
|
+
import json
|
3
|
+
import os
|
4
|
+
from fastapi import APIRouter, HTTPException, Request, Depends
|
5
|
+
from pydantic import BaseModel, Field
|
6
|
+
from typing import Dict, Any, Optional, List
|
7
|
+
from autocoder.common.mcp_server import (
|
8
|
+
get_mcp_server,
|
9
|
+
McpInstallRequest,
|
10
|
+
McpRemoveRequest,
|
11
|
+
McpListRequest,
|
12
|
+
McpListRunningRequest,
|
13
|
+
McpRefreshRequest,
|
14
|
+
McpServerInfoRequest,
|
15
|
+
McpResponse
|
16
|
+
)
|
17
|
+
from autocoder.common.printer import Printer # For messages
|
18
|
+
from autocoder.chat_auto_coder_lang import get_message_with_format # For formatted messages
|
19
|
+
from loguru import logger
|
20
|
+
from byzerllm.utils.langutil import asyncfy_with_semaphore
|
21
|
+
|
22
|
+
# Use asyncfy_with_semaphore to wrap the synchronous send_request method
|
23
|
+
async_send_request = asyncfy_with_semaphore(get_mcp_server().send_request, max_workers=5)
|
24
|
+
|
25
|
+
router = APIRouter()
|
26
|
+
printer = Printer() # Initialize printer for messages
|
27
|
+
|
28
|
+
# --- Pydantic Models for Requests ---
|
29
|
+
|
30
|
+
class McpAddRequest(BaseModel):
|
31
|
+
server_config: str = Field(..., description="Server configuration string (command-line style or JSON)")
|
32
|
+
|
33
|
+
class McpRemoveRequestModel(BaseModel):
|
34
|
+
server_name: str = Field(..., description="Name of the MCP server to remove")
|
35
|
+
|
36
|
+
class McpRefreshRequestModel(BaseModel):
|
37
|
+
server_name: Optional[str] = Field(None, description="Name of the MCP server to refresh (optional, refreshes all if None)")
|
38
|
+
|
39
|
+
class McpInfoRequestModel(BaseModel):
|
40
|
+
# Assuming model and product_mode might come from global config or request context later
|
41
|
+
# For now, let's make them optional or derive them if possible
|
42
|
+
model: Optional[str] = None
|
43
|
+
product_mode: Optional[str] = None # Example: "lite", "pro"
|
44
|
+
|
45
|
+
# --- Helper Function to Handle MCP Responses ---
|
46
|
+
|
47
|
+
async def handle_mcp_response(request: Any, success_key: str, error_key: str, **kwargs) -> Dict[str, Any]:
|
48
|
+
"""Handles sending request to MCP server and formatting the response."""
|
49
|
+
try:
|
50
|
+
response: McpResponse = await async_send_request(request)
|
51
|
+
if response.error:
|
52
|
+
logger.error(f"MCP Error ({error_key}): {response.error}")
|
53
|
+
# Use get_message_with_format if available, otherwise use the raw error
|
54
|
+
error_message = response.error
|
55
|
+
try:
|
56
|
+
# Attempt to format the error message if a key is provided
|
57
|
+
formatted_error = get_message_with_format(error_key, error=response.error)
|
58
|
+
if formatted_error: # Check if formatting was successful
|
59
|
+
error_message = formatted_error
|
60
|
+
except Exception: # Catch potential errors during formatting
|
61
|
+
pass # Stick with the original error message
|
62
|
+
raise HTTPException(status_code=400, detail=error_message)
|
63
|
+
else:
|
64
|
+
# Use get_message_with_format for success message if available
|
65
|
+
success_message = response.result
|
66
|
+
try:
|
67
|
+
formatted_success = get_message_with_format(success_key, result=response.result, **kwargs)
|
68
|
+
if formatted_success: # Check if formatting was successful
|
69
|
+
success_message = formatted_success
|
70
|
+
except Exception:
|
71
|
+
pass # Stick with the original result message
|
72
|
+
return {"status": "success", "message": success_message, "data": response.result} # Include raw data too
|
73
|
+
except HTTPException as http_exc:
|
74
|
+
raise http_exc # Re-raise HTTPException
|
75
|
+
except Exception as e:
|
76
|
+
logger.error(f"Unexpected error during MCP request ({error_key}): {str(e)}")
|
77
|
+
raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|
78
|
+
|
79
|
+
# --- API Endpoints ---
|
80
|
+
|
81
|
+
@router.post("/api/mcp/add")
|
82
|
+
async def add_mcp_server(request: McpAddRequest):
|
83
|
+
"""
|
84
|
+
Adds or updates an MCP server configuration.
|
85
|
+
Accepts command-line style args or a JSON string.
|
86
|
+
"""
|
87
|
+
mcp_request = McpInstallRequest(server_name_or_config=request.server_config)
|
88
|
+
return await handle_mcp_response(
|
89
|
+
mcp_request,
|
90
|
+
success_key="mcp_install_success",
|
91
|
+
error_key="mcp_install_error",
|
92
|
+
result=request.server_config # Pass original config for success message formatting
|
93
|
+
)
|
94
|
+
|
95
|
+
@router.post("/api/mcp/remove")
|
96
|
+
async def remove_mcp_server(request: McpRemoveRequestModel):
|
97
|
+
"""Removes an MCP server configuration by name."""
|
98
|
+
mcp_request = McpRemoveRequest(server_name=request.server_name)
|
99
|
+
return await handle_mcp_response(
|
100
|
+
mcp_request,
|
101
|
+
success_key="mcp_remove_success",
|
102
|
+
error_key="mcp_remove_error",
|
103
|
+
result=request.server_name # Pass server name for success message formatting
|
104
|
+
)
|
105
|
+
|
106
|
+
@router.get("/api/mcp/list")
|
107
|
+
async def list_mcp_servers():
|
108
|
+
"""Lists all available built-in and external MCP servers."""
|
109
|
+
mcp_request = McpListRequest()
|
110
|
+
# Specific handling for list as the result is the data itself
|
111
|
+
try:
|
112
|
+
response: McpResponse = await async_send_request(mcp_request)
|
113
|
+
if response.error:
|
114
|
+
logger.error(f"MCP Error (mcp_list_builtin_error): {response.error}")
|
115
|
+
error_message = get_message_with_format("mcp_list_builtin_error", error=response.error) or response.error
|
116
|
+
raise HTTPException(status_code=400, detail=error_message)
|
117
|
+
else:
|
118
|
+
# Split the result string into a list for better JSON representation
|
119
|
+
server_list = response.result.strip().split('\n') if response.result else []
|
120
|
+
return {"status": "success", "servers": server_list}
|
121
|
+
except HTTPException as http_exc:
|
122
|
+
raise http_exc
|
123
|
+
except Exception as e:
|
124
|
+
logger.error(f"Unexpected error during MCP list request: {str(e)}")
|
125
|
+
raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|
126
|
+
|
127
|
+
|
128
|
+
@router.get("/api/mcp/list_running")
|
129
|
+
async def list_running_mcp_servers():
|
130
|
+
"""Lists all currently running/connected MCP servers."""
|
131
|
+
mcp_request = McpListRunningRequest()
|
132
|
+
# Specific handling for list_running
|
133
|
+
try:
|
134
|
+
response: McpResponse = await async_send_request(mcp_request)
|
135
|
+
if response.error:
|
136
|
+
logger.error(f"MCP Error (mcp_list_running_error): {response.error}")
|
137
|
+
error_message = get_message_with_format("mcp_list_running_error", error=response.error) or response.error
|
138
|
+
raise HTTPException(status_code=400, detail=error_message)
|
139
|
+
else:
|
140
|
+
# Split the result string into a list
|
141
|
+
running_server_list = response.result.strip().split('\n') if response.result else []
|
142
|
+
# Clean up list (remove potential leading hyphens/spaces)
|
143
|
+
cleaned_list = [s.strip().lstrip('-').strip() for s in running_server_list if s.strip()]
|
144
|
+
return {"status": "success", "running_servers": cleaned_list}
|
145
|
+
except HTTPException as http_exc:
|
146
|
+
raise http_exc
|
147
|
+
except Exception as e:
|
148
|
+
logger.error(f"Unexpected error during MCP list_running request: {str(e)}")
|
149
|
+
raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|
150
|
+
|
151
|
+
@router.post("/api/mcp/refresh")
|
152
|
+
async def refresh_mcp_connections(request: McpRefreshRequestModel):
|
153
|
+
"""Refreshes connections to MCP servers (all or a specific one)."""
|
154
|
+
mcp_request = McpRefreshRequest(name=request.server_name)
|
155
|
+
return await handle_mcp_response(
|
156
|
+
mcp_request,
|
157
|
+
success_key="mcp_refresh_success",
|
158
|
+
error_key="mcp_refresh_error"
|
159
|
+
)
|
160
|
+
|
161
|
+
@router.get("/api/mcp/info")
|
162
|
+
async def get_mcp_server_info(model: Optional[str] = None, product_mode: Optional[str] = None):
|
163
|
+
"""Gets detailed information about connected MCP servers."""
|
164
|
+
# TODO: Determine how to get model/product_mode - from app state, global config, or request?
|
165
|
+
# Using optional query params for now.
|
166
|
+
mcp_request = McpServerInfoRequest(model=model, product_mode=product_mode)
|
167
|
+
# Specific handling for info
|
168
|
+
try:
|
169
|
+
response: McpResponse = await async_send_request(mcp_request)
|
170
|
+
if response.error:
|
171
|
+
logger.error(f"MCP Error (mcp_server_info_error): {response.error}")
|
172
|
+
error_message = get_message_with_format("mcp_server_info_error", error=response.error) or response.error
|
173
|
+
raise HTTPException(status_code=400, detail=error_message)
|
174
|
+
else:
|
175
|
+
# The result is likely a markdown string or complex structure. Return as is.
|
176
|
+
return {"status": "success", "info": response.result}
|
177
|
+
except HTTPException as http_exc:
|
178
|
+
raise http_exc
|
179
|
+
except Exception as e:
|
180
|
+
logger.error(f"Unexpected error during MCP info request: {str(e)}")
|
181
|
+
raise HTTPException(status_code=500, detail=f"Internal server error: {str(e)}")
|
182
|
+
|
183
|
+
# Potentially add endpoints for direct tool calls or resource access if needed in the future
|
184
|
+
# @router.post("/api/mcp/call_tool")
|
185
|
+
# async def call_mcp_tool(...): ...
|
186
|
+
|
187
|
+
# @router.get("/api/mcp/read_resource")
|
188
|
+
# async def read_mcp_resource(...): ...
|
auto_coder_web/version.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "0.1.
|
1
|
+
__version__ = "0.1.60"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import{m as et}from"./index-
|
1
|
+
import{m as et}from"./index-U694gZ5i.js";/*!-----------------------------------------------------------------------------
|
2
2
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
3
3
|
* Version: 0.52.2(404545bded1df6ffa41ea0af4e8ddb219018c6c1)
|
4
4
|
* Released under the MIT license
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import{m as f}from"./index-
|
1
|
+
import{m as f}from"./index-U694gZ5i.js";/*!-----------------------------------------------------------------------------
|
2
2
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
3
3
|
* Version: 0.52.2(404545bded1df6ffa41ea0af4e8ddb219018c6c1)
|
4
4
|
* Released under the MIT license
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import{m as l}from"./index-
|
1
|
+
import{m as l}from"./index-U694gZ5i.js";/*!-----------------------------------------------------------------------------
|
2
2
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
3
3
|
* Version: 0.52.2(404545bded1df6ffa41ea0af4e8ddb219018c6c1)
|
4
4
|
* Released under the MIT license
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import{m as s}from"./index-
|
1
|
+
import{m as s}from"./index-U694gZ5i.js";/*!-----------------------------------------------------------------------------
|
2
2
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
3
3
|
* Version: 0.52.2(404545bded1df6ffa41ea0af4e8ddb219018c6c1)
|
4
4
|
* Released under the MIT license
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import{m as lt}from"./index-
|
1
|
+
import{m as lt}from"./index-U694gZ5i.js";/*!-----------------------------------------------------------------------------
|
2
2
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
3
3
|
* Version: 0.52.2(404545bded1df6ffa41ea0af4e8ddb219018c6c1)
|
4
4
|
* Released under the MIT license
|