File size: 2,377 Bytes
db62a8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env bash
set -euo pipefail
cd "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
mcp_entry_name="${MCP_ENTRY_NAME:-MetPy}"
mcp_entry_url="${MCP_ENTRY_URL:-http://localhost:7978/mcp}"
mcp_dir="${HOME}/.cursor"
mcp_path="${mcp_dir}/mcp.json"
mkdir -p "${mcp_dir}"
if command -v python3 >/dev/null 2>&1; then
python3 - "${mcp_path}" "${mcp_entry_name}" "${mcp_entry_url}" <<'PY'
import json, os, sys
path, name, url = sys.argv[1:4]
cfg = {"mcpServers": {}}
if os.path.exists(path):
    try:
        with open(path, "r", encoding="utf-8") as f:
            cfg = json.load(f)
    except Exception:
        cfg = {"mcpServers": {}}
if not isinstance(cfg, dict):
    cfg = {"mcpServers": {}}
servers = cfg.get("mcpServers")
if not isinstance(servers, dict):
    servers = {}
ordered = {}
for k, v in servers.items():
    if k != name:
        ordered[k] = v
ordered[name] = {"url": url}
cfg = {"mcpServers": ordered}
with open(path, "w", encoding="utf-8") as f:
    json.dump(cfg, f, indent=2, ensure_ascii=False)
PY
elif command -v python >/dev/null 2>&1; then
python - "${mcp_path}" "${mcp_entry_name}" "${mcp_entry_url}" <<'PY'
import json, os, sys
path, name, url = sys.argv[1:4]
cfg = {"mcpServers": {}}
if os.path.exists(path):
    try:
        with open(path, "r", encoding="utf-8") as f:
            cfg = json.load(f)
    except Exception:
        cfg = {"mcpServers": {}}
if not isinstance(cfg, dict):
    cfg = {"mcpServers": {}}
servers = cfg.get("mcpServers")
if not isinstance(servers, dict):
    servers = {}
ordered = {}
for k, v in servers.items():
    if k != name:
        ordered[k] = v
ordered[name] = {"url": url}
cfg = {"mcpServers": ordered}
with open(path, "w", encoding="utf-8") as f:
    json.dump(cfg, f, indent=2, ensure_ascii=False)
PY
elif command -v jq >/dev/null 2>&1; then
  name="${mcp_entry_name}"; url="${mcp_entry_url}"
  if [ -f "${mcp_path}" ]; then
    tmp="$(mktemp)"
    jq --arg name "$name" --arg url "$url" '
      .mcpServers = (.mcpServers // {})
      | .mcpServers as $s
      | ($s | with_entries(select(.key != $name))) as $base
      | .mcpServers = ($base + {($name): {"url": $url}})
    ' "${mcp_path}" > "${tmp}" && mv "${tmp}" "${mcp_path}"
  else
    printf '{ "mcpServers": { "%s": { "url": "%s" } } }
' "$name" "$url" > "${mcp_path}"
  fi
fi
docker build -t MetPy-mcp .
docker run --rm -p 7978:7860 MetPy-mcp