fd5787c55f
- .mcp.json - bash/functions/infra/write_mcp_jupyter_config.md - bash/functions/infra/write_mcp_jupyter_config.sh - cpp/CMakeLists.txt - cpp/apps/chart_demo - cpp/apps/shaders_lab - cpp/functions/gfx/gl_framebuffer.cpp - cpp/functions/gfx/gl_framebuffer.h - cpp/functions/gfx/gl_framebuffer.md - cpp/functions/gfx/mesh_gpu.md - ... Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
70 lines
2.5 KiB
Bash
70 lines
2.5 KiB
Bash
# write_mcp_jupyter_config
|
|
# -------------------------
|
|
# Genera o actualiza .mcp.json con la configuracion de jupyter-mcp-server.
|
|
# Usa el console-script `jupyter-mcp-server` del venv local con transport stdio
|
|
# y los flags --jupyter-url / --jupyter-token (NO env vars, NO `-m ...server`).
|
|
# Hace merge si ya existe .mcp.json (requiere jq).
|
|
#
|
|
# GOTCHA (2026-05-28): `python -m jupyter_mcp_server.server` NO arranca nada —
|
|
# server.py no tiene bloque __main__, asi que el proceso importa y sale 0 y el
|
|
# MCP nunca levanta. El entrypoint real es la CLI (`jupyter_mcp_server.CLI:server`,
|
|
# expuesta como console-script `jupyter-mcp-server`), que sin subcomando arranca
|
|
# en stdio por defecto. La config tampoco lee SERVER_URL/TOKEN: usa los flags
|
|
# --jupyter-url / --jupyter-token. El MCP tolera que Jupyter este apagado al
|
|
# arrancar (responde `initialize` tras un connect-timeout ~10s y sirve igual).
|
|
#
|
|
# USO (sourced):
|
|
# source write_mcp_jupyter_config.sh
|
|
# write_mcp_jupyter_config /path/to/project 8888
|
|
|
|
write_mcp_jupyter_config() {
|
|
local project_dir="${1:-.}"
|
|
local port="${2:-8888}"
|
|
local mcp_file="${project_dir}/.mcp.json"
|
|
local abs_project
|
|
abs_project="$(cd "$project_dir" && pwd)"
|
|
|
|
local python_bin="${abs_project}/.venv/bin/python"
|
|
local mcp_bin="${abs_project}/.venv/bin/jupyter-mcp-server"
|
|
if [ ! -f "$python_bin" ]; then
|
|
echo "write_mcp_jupyter_config: python no encontrado en ${python_bin}" >&2
|
|
return 1
|
|
fi
|
|
|
|
# Verificar que el console-script esta instalado
|
|
if [ ! -x "$mcp_bin" ]; then
|
|
echo "write_mcp_jupyter_config: jupyter-mcp-server no instalado en el venv (${mcp_bin}). Instala con: uv pip install jupyter-mcp-server" >&2
|
|
return 1
|
|
fi
|
|
|
|
local new_config
|
|
new_config=$(cat << EOF
|
|
{
|
|
"mcpServers": {
|
|
"jupyter": {
|
|
"command": "${mcp_bin}",
|
|
"args": [
|
|
"--transport", "stdio",
|
|
"--jupyter-url", "http://localhost:${port}",
|
|
"--jupyter-token", ""
|
|
]
|
|
}
|
|
}
|
|
}
|
|
EOF
|
|
)
|
|
|
|
if [ -f "$mcp_file" ] && command -v jq &>/dev/null; then
|
|
# Merge conservando otros servidores MCP. Usa `+` (shallow) en el mapa de
|
|
# servidores para REEMPLAZAR la entrada `jupyter` entera — `*` (deep) dejaba
|
|
# keys huerfanas de configs viejas (ej. bloque `env` obsoleto).
|
|
jq -s '.[0] * {mcpServers: ((.[0].mcpServers // {}) + (.[1].mcpServers // {}))}' \
|
|
"$mcp_file" <(echo "$new_config") > "${mcp_file}.tmp"
|
|
mv "${mcp_file}.tmp" "$mcp_file"
|
|
else
|
|
echo "$new_config" > "$mcp_file"
|
|
fi
|
|
|
|
echo "$mcp_file"
|
|
}
|