同步完整源码至远程:扁平化重构现状 + 未入库源文件
- 补入库:server/internal/db/dump.go、redis 分页/扫描预算测试、opsxdb-mcp main_test、 packages/opsxdb-mcp package-lock、docs 审计与对比文档等 37 个新文件 - 含结构扁平化进行中的 80 处修改与 155 处旧结构删除(server/ src/ src-tauri/ 为当前有效源) - 构建产物(bin/target/dist)与签名私钥仍按规则排除
This commit is contained in:
1 parent
5c0be49217
commit
2c0bfafd8d
269 files changed
+10372
-16435
No files matched your search
@@ -37,6 +37,9 @@ func ToolNames() []string {
|
||||
// Runtime 可被 MCP stdio 与将来侧栏 Agent 进程内共用。 // Logan.Li
|
||||
type Runtime struct {
|
||||
Policy Policy
|
||||
// Agent 会话限定到当前编辑器上下文;MCP 外部调用保持独立的白名单策略。
|
||||
BoundConnectionID string
|
||||
BoundDatabase string
|
||||
// LoadConns / FindConn 可注入,便于单测;nil 则读磁盘。
|
||||
LoadConns func() ([]SavedConnection, error)
|
||||
FindConn func(id string) (*SavedConnection, error)
|
||||
@@ -144,6 +147,31 @@ func (r *Runtime) listCol(ctx context.Context, c db.ConnReq) ([]db.ColumnInfo, e
|
||||
|
||||
// Call 统一入口:MCP 与 Agent 都走这里。args 为 JSON object。
|
||||
func (r *Runtime) Call(ctx context.Context, tool string, args map[string]any) (any, error) {
|
||||
if r.BoundConnectionID != "" {
|
||||
if tool == ToolListConnections {
|
||||
return r.listBoundConnection(ctx)
|
||||
}
|
||||
if argString(args, "connection_id") != r.BoundConnectionID {
|
||||
return nil, fmt.Errorf("tool connection differs from the current Agent connection")
|
||||
}
|
||||
if tool == ToolListDatabases && r.BoundDatabase != "" {
|
||||
if _, err := r.resolveAllowed(r.BoundConnectionID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return map[string]any{"databases": []string{r.BoundDatabase}}, nil
|
||||
}
|
||||
if database := argString(args, "database"); database != "" && r.BoundDatabase != "" && database != r.BoundDatabase {
|
||||
return nil, fmt.Errorf("tool database differs from the current Agent database")
|
||||
}
|
||||
if r.BoundDatabase != "" {
|
||||
clone := make(map[string]any, len(args)+1)
|
||||
for k, v := range args {
|
||||
clone[k] = v
|
||||
}
|
||||
clone["database"] = r.BoundDatabase
|
||||
args = clone
|
||||
}
|
||||
}
|
||||
switch tool {
|
||||
case ToolListConnections:
|
||||
return r.listConnections(ctx)
|
||||
@@ -164,6 +192,15 @@ func (r *Runtime) Call(ctx context.Context, tool string, args map[string]any) (a
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Runtime) listBoundConnection(ctx context.Context) (any, error) {
|
||||
_ = ctx
|
||||
c, err := r.resolveAllowed(r.BoundConnectionID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return map[string]any{"connections": []ConnectionSummary{c.Summary()}}, nil
|
||||
}
|
||||
|
||||
func (r *Runtime) listConnections(ctx context.Context) (any, error) {
|
||||
_ = ctx
|
||||
list, err := r.loadConns()
|
||||
@@ -250,7 +287,6 @@ func argBool(args map[string]any, key string) bool {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func (r *Runtime) listDatabases(ctx context.Context, args map[string]any) (any, error) {
|
||||
id := argString(args, "connection_id")
|
||||
c, err := r.resolveAllowed(id)
|
||||
@@ -409,12 +445,15 @@ func (r *Runtime) executeQuery(ctx context.Context, args map[string]any) (any, e
|
||||
if !confirmed {
|
||||
r.audit(AuditEntry{Tool: ToolExecuteQuery, ConnectionID: id, OK: false, Error: "needConfirm", Summary: truncate(sqlText, 80)})
|
||||
bind := ConfirmBindHash(id, sqlText)
|
||||
if r.BoundConnectionID != "" {
|
||||
bind = ConfirmAgentBindHash(id, database, sqlText)
|
||||
}
|
||||
return map[string]any{
|
||||
"needConfirm": true,
|
||||
"sql": sqlText,
|
||||
"confirmBind": bind,
|
||||
"message": "write requires explicit user confirmation",
|
||||
"reason": readReason,
|
||||
"needConfirm": true,
|
||||
"sql": sqlText,
|
||||
"confirmBind": bind,
|
||||
"message": "write requires explicit user confirmation",
|
||||
"reason": readReason,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
@@ -483,12 +522,15 @@ func (r *Runtime) executeRedis(ctx context.Context, args map[string]any) (any, e
|
||||
if !confirmed {
|
||||
r.audit(AuditEntry{Tool: ToolExecuteRedisCommand, ConnectionID: id, OK: false, Error: "needConfirm", Summary: truncate(command, 80)})
|
||||
bind := ConfirmBindHash(id, command)
|
||||
if r.BoundConnectionID != "" {
|
||||
bind = ConfirmAgentBindHash(id, database, command)
|
||||
}
|
||||
return map[string]any{
|
||||
"needConfirm": true,
|
||||
"command": command,
|
||||
"confirmBind": bind,
|
||||
"message": "redis write requires explicit user confirmation",
|
||||
"reason": rerr.Error(),
|
||||
"needConfirm": true,
|
||||
"command": command,
|
||||
"confirmBind": bind,
|
||||
"message": "redis write requires explicit user confirmation",
|
||||
"reason": rerr.Error(),
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user