mirror of
https://github.com/kuhyx/screen-locker.git
synced 2026-11-10 17:47:23 +01:00
Expose the screen-locker's compliance and lock-decision state as read-only MCP tools (screen_locker._mcp) so Claude Code and its subagents can query workout status without shelling out to the CLI or opening the Tk window. - _mcp.py: FastMCP stdio server. Read-only tools get_status, get_summary, explain_lock, get_flags. Import leaf over stdout-free status functions (gather_status, format_summary_line, explain_lock_decision, predicates); logs to stderr. NO write/action tools by design — workouts are logged only from RunnerUp-verified TCX data, never from a caller's claim. No tool exposes the sync token or any HMAC key. - .mcp.json + scripts/setup_mcp.sh: registration via a dedicated ~/.venvs/screen-locker-mcp interpreter; mcp is an optional-dep. - 100% coverage of the new module; verified end-to-end over stdio. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LQGQj8Ne6TriBExv91nG8v
46 lines
1.6 KiB
Bash
Executable File
46 lines
1.6 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# ============================================================================
|
|
# Set up the dedicated virtualenv that hosts the screen-locker MCP server.
|
|
# Claude Code spawns this interpreter (see the repo-root .mcp.json) to run
|
|
# `python -m screen_locker._mcp` over stdio.
|
|
#
|
|
# The MCP SDK (`mcp`) lives ONLY in this venv — it is an optional dependency,
|
|
# deliberately kept out of the system/CLI/systemd python path. Both `mcp` and
|
|
# `screen_locker` must be importable by this one interpreter or the MCP server
|
|
# fails to start silently.
|
|
#
|
|
# The server is READ-ONLY: it exposes status/query tools only, never any tool
|
|
# that logs a workout or mutates state.
|
|
#
|
|
# Idempotent: safe to re-run to pick up dependency changes.
|
|
# ============================================================================
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
REPO_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
|
|
readonly SCRIPT_DIR REPO_DIR
|
|
readonly VENV_DIR="${HOME}/.venvs/screen-locker-mcp"
|
|
|
|
main() {
|
|
echo "== Setting up MCP venv at ${VENV_DIR} =="
|
|
|
|
if [[ ! -d "${VENV_DIR}" ]]; then
|
|
python3 -m venv "${VENV_DIR}"
|
|
fi
|
|
|
|
"${VENV_DIR}/bin/pip" install --quiet --upgrade pip
|
|
"${VENV_DIR}/bin/pip" install --quiet -e "${REPO_DIR}[mcp]"
|
|
|
|
echo "== Verifying imports =="
|
|
"${VENV_DIR}/bin/python" -c \
|
|
"import mcp, screen_locker; print('mcp + screen_locker import OK')"
|
|
|
|
echo
|
|
echo "Done. The server is registered via ${REPO_DIR}/.mcp.json"
|
|
echo "Restart Claude Code in this repo and approve the project MCP server prompt."
|
|
}
|
|
|
|
main "$@"
|