feat: print remote config on MCP service start
Make scripts/mcp_service.sh start create the token env file when missing, then start the user service and print the remote MCP URL, Authorization header, and client JSON. Document the one-command startup flow and cover automatic token creation with tests.
This commit is contained in:
@@ -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/mcp_service.sh new-token first.")
|
||||
raise RuntimeError(f"Missing MCP service env file: {env_path}. Run scripts/mcp_service.sh start to create it.")
|
||||
|
||||
values: dict[str, str] = {}
|
||||
for raw_line in env_path.read_text(encoding="utf-8").splitlines():
|
||||
@@ -262,9 +262,19 @@ def new_token(
|
||||
def start_service(
|
||||
*,
|
||||
project_root: Path,
|
||||
host: str = DEFAULT_HOST,
|
||||
port: int = DEFAULT_PORT,
|
||||
path: str = DEFAULT_PATH,
|
||||
token_bytes: int = DEFAULT_TOKEN_BYTES,
|
||||
) -> str:
|
||||
paths = resolve_service_paths(project_root)
|
||||
token, host, port, path = saved_service_config(project_root)
|
||||
try:
|
||||
token, host, port, path = saved_service_config(project_root)
|
||||
except RuntimeError:
|
||||
if paths.env_path.exists():
|
||||
raise
|
||||
token = generate_token(token_bytes)
|
||||
write_token_env_file(paths.env_path, token, host=host, port=port, path=path)
|
||||
write_service_unit(paths, host=host, port=port, path=path)
|
||||
|
||||
run_systemctl(["daemon-reload"])
|
||||
@@ -307,8 +317,12 @@ def main(argv: Sequence[str] | None = None) -> int:
|
||||
new_token_parser.add_argument("--path", default=DEFAULT_PATH)
|
||||
new_token_parser.add_argument("--token-bytes", default=DEFAULT_TOKEN_BYTES, type=int)
|
||||
|
||||
start_parser = subparsers.add_parser("start", help="Install or update the user service using the saved token.")
|
||||
start_parser = subparsers.add_parser("start", help="Install or update the user service and print remote MCP config.")
|
||||
start_parser.add_argument("--project-root", default=Path(__file__).resolve().parent.parent, type=Path)
|
||||
start_parser.add_argument("--host", default=DEFAULT_HOST)
|
||||
start_parser.add_argument("--port", default=DEFAULT_PORT, type=int)
|
||||
start_parser.add_argument("--path", default=DEFAULT_PATH)
|
||||
start_parser.add_argument("--token-bytes", default=DEFAULT_TOKEN_BYTES, type=int)
|
||||
|
||||
subparsers.add_parser("stop", help="Stop the user service without deleting service files.")
|
||||
|
||||
@@ -335,7 +349,16 @@ def main(argv: Sequence[str] | None = None) -> int:
|
||||
)
|
||||
return 0
|
||||
if args.command == "start":
|
||||
print(start_service(project_root=args.project_root), end="")
|
||||
print(
|
||||
start_service(
|
||||
project_root=args.project_root,
|
||||
host=args.host,
|
||||
port=args.port,
|
||||
path=args.path,
|
||||
token_bytes=args.token_bytes,
|
||||
),
|
||||
end="",
|
||||
)
|
||||
return 0
|
||||
if args.command == "stop":
|
||||
stop_service()
|
||||
|
||||
Reference in New Issue
Block a user