Ship Cursor-only MCP admin and modular Admin/Chat UI.

Plugins/Skills install and edit via mcpServers JSON, with clearer row actions, soft reloads, and instant loading placeholders; also drop MCP market and harden related scheduler/logging/exec guards.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-08-12 19:38:26 +08:00
parent 2aff012b48
commit f6f129931f
61 changed files with 18057 additions and 16327 deletions

View file

@ -1,4 +1,4 @@
"""Build a reinstallable MCP JSON from SQLite and persist under ``oclaw/_local/`` for migration."""
"""Build a reinstallable Cursor ``mcpServers`` JSON from SQLite under ``oclaw/_local/``."""
from __future__ import annotations
import json
@ -10,6 +10,7 @@ from typing import Any
from svc.config.paths import PROJECT_ROOT
from svc.persistence.sqlite_store import SqliteStore
from runtime.tools.mcp.cursor_config import build_cursor_mcp_export
from runtime.tools.mcp.registry import McpRegistry
_EXPORT_FILENAME = "mcp_registry_migrated.json"
@ -22,11 +23,7 @@ def mcp_migrated_json_path() -> Path:
def _collapse_entry_arg(arg: str, root: Path) -> str:
"""Rewrite absolute / repo-relative paths to ``__REPO_ROOT__/...`` when they exist on disk under root.
Skips npx flags (``-y``) and tokens that are not an existing file or directory, so package names
(e.g. ``mcp-sqlite``, ``@upstash/foo``) are not mistaken for paths.
"""
"""Rewrite absolute / repo-relative paths to ``__REPO_ROOT__/...`` when under root."""
t = (arg or "").strip()
if not t or t.startswith("__REPO_ROOT__") or t.startswith("-"):
return str(arg)
@ -52,41 +49,24 @@ def _collapse_entry_args(args: list[str], root: Path) -> list[str]:
def build_mcp_install_export_document(store: SqliteStore) -> dict[str, Any]:
rows = McpRegistry(store).list_servers(enabled_only=False)
root = PROJECT_ROOT.resolve()
servers: list[dict[str, Any]] = []
collapsed: list[dict[str, Any]] = []
for r in rows:
if not isinstance(r, dict):
continue
raw_args = r.get("entry_args")
row = dict(r)
raw_args = row.get("entry_args")
if isinstance(raw_args, list):
entry_args = _collapse_entry_args([str(x) for x in raw_args if str(x).strip()], root)
row["entry_args"] = _collapse_entry_args([str(x) for x in raw_args if str(x).strip()], root)
else:
entry_args = []
es = r.get("env_schema")
env_schema = es if isinstance(es, dict) else {}
perms = r.get("required_permissions")
if not isinstance(perms, list):
perms = []
servers.append(
{
"server_id": str(r.get("server_id") or ""),
"source_type": str(r.get("source_type") or ""),
"source_ref": str(r.get("source_ref") or ""),
"version": str(r.get("version") or ""),
"entry_command": str(r.get("entry_command") or ""),
"entry_args": entry_args,
"env_schema": env_schema,
"required_permissions": [str(x) for x in perms if str(x).strip()],
"risk_level": str(r.get("risk_level") or "high"),
"enabled": bool(r.get("enabled")),
"timeout_s": float(r.get("timeout_s") or 30.0),
"dry_run": False,
}
)
return {
"_comment": "管理台导出 / 新安装后自动落盘。可粘到「Install from JSON」;`__REPO_ROOT__/` 在管理台与 seed 中展开为仓库根。已存在路径会写成占位符,其余参数保持原样。",
"exported_at": datetime.now(timezone.utc).isoformat(),
"servers": servers,
}
row["entry_args"] = []
collapsed.append(row)
doc = build_cursor_mcp_export(collapsed)
doc["_comment"] = (
"Cursor mcpServers export. Paste into Admin → Plugins → Install, "
"or feed to seed_mcp_registry.py. Paths under the repo may use __REPO_ROOT__/."
)
doc["exported_at"] = datetime.now(timezone.utc).isoformat()
return doc
def persist_mcp_migrated_file(store: SqliteStore) -> str | None:

View file

@ -1,10 +1,10 @@
"""将 oclaw/data/mcp_registry.seed.json 中的 MCP 定义写入本地 SQLite(与管理台 Install 等价)。
"""将 Cursor ``mcpServers`` JSON 写入本地 SQLite(与管理台 Install 等价)。
库表被清空、换库或新环境时:在项目根执行
python oclaw/scripts/seed_mcp_registry.py
可选:python oclaw/scripts/seed_mcp_registry.py path/to/other.seed.json
python -m runtime.operations.scripts.seed_mcp_registry
可选:python -m runtime.operations.scripts.seed_mcp_registry path/to/mcp.json
随后在各 MCP 上点 Health → Sync Tools;Context7 等需在 src/_local/mcp_local.env 配密钥。
随后在各 MCP 上点 Health → Sync Tools;密钥放在 oclaw/_local/mcp_local.env。
"""
from __future__ import annotations
@ -12,13 +12,15 @@ import json
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
ROOT = Path(__file__).resolve().parents[3]
sys.path.insert(0, str(ROOT))
from svc.config.paths import PROJECT_ROOT, db_path # noqa: E402
from svc.persistence.sqlite_store import SqliteStore # noqa: E402
from svc.persistence.assistant_store import get_assistant_store
from runtime.tools.mcp.installer import McpServerManifest, _safe_server_id, install_mcp_server # noqa: E402
from svc.config.paths import PROJECT_ROOT # noqa: E402
from svc.persistence.assistant_store import get_assistant_store # noqa: E402
from runtime.tools.mcp.cursor_config import parse_cursor_mcp_document # noqa: E402
from runtime.tools.mcp.installer import install_mcp_server # noqa: E402
from runtime.tools.mcp.manifest import McpServerManifest # noqa: E402
from runtime.operations.mcp_registry_export import persist_mcp_migrated_file # noqa: E402
def _subst_repo(path_str: str) -> str:
@ -34,37 +36,30 @@ def main(argv: list[str]) -> int:
print(f"seed file not found: {seed_path}", file=sys.stderr)
return 2
raw = json.loads(seed_path.read_text(encoding="utf-8"))
items = raw.get("servers") if isinstance(raw, dict) else raw
if not isinstance(items, list) or not items:
print("no servers[] in seed file", file=sys.stderr)
try:
items = parse_cursor_mcp_document(raw)
except ValueError as exc:
print(f"invalid Cursor mcpServers document: {exc}", file=sys.stderr)
return 2
store = get_assistant_store()
ok_n = 0
for payload in items:
if not isinstance(payload, dict):
continue
source_type = str(payload.get("source_type") or "").strip().lower()
source_ref = str(payload.get("source_ref") or "").strip()
if source_type not in {"github", "npm", "pypi"} or not source_ref:
print(f"skip invalid: {payload.get('server_id')!r}")
continue
server_id = _safe_server_id(str(payload.get("server_id") or source_ref))
entry_args = [_subst_repo(x) for x in (payload.get("entry_args") or []) if str(x).strip()]
dry_run = bool(payload.get("dry_run", False))
manifest = McpServerManifest(
server_id=server_id,
source_type=source_type,
source_ref=source_ref,
server_id=str(payload.get("server_id") or ""),
source_type=str(payload.get("source_type") or "local"),
source_ref=str(payload.get("source_ref") or ""),
version=str(payload.get("version") or "").strip(),
entry_command=str(payload.get("entry_command") or "").strip(),
entry_args=entry_args,
env_schema=payload.get("env_schema") if isinstance(payload.get("env_schema"), dict) else {},
permissions=[str(x) for x in (payload.get("required_permissions") or [])],
risk_level=str(payload.get("risk_level") or "high"),
enabled=bool(payload.get("enabled")),
enabled=bool(payload.get("enabled", True)),
timeout_s=float(payload.get("timeout_s") or 30.0),
)
dry_run = bool(payload.get("dry_run", False))
inst = install_mcp_server(manifest, dry_run=dry_run)
store.upsert_mcp_server(
server_id=manifest.server_id,
@ -86,10 +81,14 @@ def main(argv: list[str]) -> int:
detail={"error": inst.error, **(inst.details or {}), "seed": True},
install_command=inst.install_command,
)
print(f"{server_id}: install_ok={inst.ok} enabled={manifest.enabled if inst.ok else False} cmd={inst.install_command[:120]!r}")
print(
f"{manifest.server_id}: install_ok={inst.ok} "
f"enabled={manifest.enabled if inst.ok else False} cmd={inst.install_command[:120]!r}"
)
if inst.ok:
ok_n += 1
print(f"done: {ok_n}/{len(items)} npm/pypi install steps succeeded; rows upserted for all valid entries.")
persist_mcp_migrated_file(store)
print(f"done: {ok_n}/{len(items)} install steps succeeded; rows upserted for all valid entries.")
return 0