refactor: consolidate MCP service scripts

Replace per-command shell wrappers with a single scripts/mcp_service.sh entrypoint that forwards subcommands to manage_mcp_service.py.

Update docs and tests so remote MCP service management stays on the consolidated command surface.
This commit is contained in:
Codex
2026-07-05 11:38:49 +00:00
parent 31b0e8dba2
commit baa8c0beae
9 changed files with 28 additions and 31 deletions
+2 -2
View File
@@ -41,8 +41,8 @@ OBSIDIAN_MCP_EXPOSE_PATHS=false
# Run locally:
# OBSIDIAN_MCP_TOKEN='<long-random-token>' obsidian-wiki-mcp --transport streamable-http
# Or manage a user-level service:
# bash scripts/new_mcp_service_token.sh
# bash scripts/start_mcp_service.sh
# bash scripts/mcp_service.sh new-token
# bash scripts/mcp_service.sh start
OBSIDIAN_MCP_TOKEN=
OBSIDIAN_MCP_HOST=127.0.0.1
OBSIDIAN_MCP_PORT=8765
+7 -7
View File
@@ -364,19 +364,19 @@ Client configuration example:
For long-running access from another machine, use the managed user service:
```bash
bash scripts/new_mcp_service_token.sh
bash scripts/start_mcp_service.sh
bash scripts/mcp_service.sh new-token
bash scripts/mcp_service.sh start
```
`new_mcp_service_token.sh` writes `.runtime/obsidian-wiki-mcp.env` with `0600` permissions and prints the remote URL, `Authorization` header, and client JSON. `start_mcp_service.sh` writes `~/.config/systemd/user/obsidian-wiki-mcp.service` and starts it. The service defaults to `0.0.0.0:8765/mcp` because it is intended for remote clients, but it still requires the bearer token. Prefer SSH tunnel, Tailscale, WireGuard, or another trusted network boundary instead of directly exposing the port to the public internet.
`mcp_service.sh new-token` writes `.runtime/obsidian-wiki-mcp.env` with `0600` permissions and prints the remote URL, `Authorization` header, and client JSON. `mcp_service.sh start` writes `~/.config/systemd/user/obsidian-wiki-mcp.service` and starts it. The service defaults to `0.0.0.0:8765/mcp` because it is intended for remote clients, but it still requires the bearer token. Prefer SSH tunnel, Tailscale, WireGuard, or another trusted network boundary instead of directly exposing the port to the public internet.
Useful service commands:
```bash
bash scripts/show_mcp_service_config.sh
bash scripts/stop_mcp_service.sh
bash scripts/uninstall_mcp_service.sh
python3 scripts/manage_mcp_service.py status
bash scripts/mcp_service.sh show-config
bash scripts/mcp_service.sh stop
bash scripts/mcp_service.sh uninstall
bash scripts/mcp_service.sh status
```
### `_raw/` Staging Directory
+1 -1
View File
@@ -124,7 +124,7 @@ def write_token_env_file(
def read_service_env_file(env_path: Path) -> dict[str, str]:
if not env_path.exists():
raise RuntimeError(f"Missing MCP service env file: {env_path}. Run scripts/new_mcp_service_token.sh first.")
raise RuntimeError(f"Missing MCP service env file: {env_path}. Run scripts/mcp_service.sh new-token first.")
values: dict[str, str] = {}
for raw_line in env_path.read_text(encoding="utf-8").splitlines():
@@ -2,4 +2,4 @@
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
exec python3 "$SCRIPT_DIR/manage_mcp_service.py" stop "$@"
exec python3 "$SCRIPT_DIR/manage_mcp_service.py" "$@"
-5
View File
@@ -1,5 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
exec python3 "$SCRIPT_DIR/manage_mcp_service.py" new-token "$@"
-5
View File
@@ -1,5 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
exec python3 "$SCRIPT_DIR/manage_mcp_service.py" show-config "$@"
-5
View File
@@ -1,5 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
exec python3 "$SCRIPT_DIR/manage_mcp_service.py" start "$@"
-5
View File
@@ -1,5 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
exec python3 "$SCRIPT_DIR/manage_mcp_service.py" uninstall "$@"
+17
View File
@@ -15,6 +15,23 @@ import manage_mcp_service
class McpServiceConfigTests(unittest.TestCase):
def test_service_commands_use_one_shell_entrypoint(self):
entrypoint = SCRIPTS_DIR / "mcp_service.sh"
legacy_wrappers = [
"new_mcp_service_token.sh",
"start_mcp_service.sh",
"show_mcp_service_config.sh",
"stop_mcp_service.sh",
"uninstall_mcp_service.sh",
]
self.assertTrue(entrypoint.is_file())
self.assertTrue(os.access(entrypoint, os.X_OK))
content = entrypoint.read_text(encoding="utf-8")
self.assertIn('exec python3 "$SCRIPT_DIR/manage_mcp_service.py" "$@"', content)
for wrapper in legacy_wrappers:
self.assertFalse((SCRIPTS_DIR / wrapper).exists(), f"{wrapper} should be folded into mcp_service.sh")
def test_render_service_unit_uses_http_transport_without_embedding_token(self):
unit = manage_mcp_service.render_service_unit(
project_root=Path("/opt/obsidian-wiki"),