-
Notifications
You must be signed in to change notification settings - Fork 58
Add container run wrapper script #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| #!/bin/bash | ||
| # | ||
| # Wrapper script to run linux-mcp-server in a container via podman. | ||
| # Use this in AI agent MCP configs for a cleaner setup. | ||
| # | ||
| # Environment variables (matching linux-mcp-server official env vars): | ||
| # See: https://github.com/rhel-lightspeed/linux-mcp-server | ||
| # | ||
| # Additional env vars for container configuration: | ||
| # MCP_CONTAINER_IMAGE - (optional) Container image to use | ||
| # | ||
| # Example AI agent config: | ||
| # { | ||
| # "mcpServers": { | ||
| # "linux-mcp-server": { | ||
| # "command": "/path/to/linux-mcp-container.sh", | ||
| # "env": { | ||
| # "LINUX_MCP_USER": "root", | ||
| # "LINUX_MCP_SSH_KEY_PATH": "/home/user/.ssh/id_rsa", | ||
| # "LINUX_MCP_LOG_LEVEL": "DEBUG" | ||
| # } | ||
| # } | ||
| # } | ||
| # } | ||
| # | ||
|
|
||
| set -e | ||
|
|
||
| # Defaults | ||
| SSH_KEY="${LINUX_MCP_SSH_KEY_PATH:-$HOME/.ssh/id_rsa}" | ||
| IMAGE="${MCP_CONTAINER_IMAGE:-quay.io/redhat-services-prod/rhel-lightspeed-tenant/linux-mcp-server:latest}" | ||
| LOGS_DIR="$HOME/.local/share/linux-mcp-server/logs" | ||
|
|
||
| # Ensure logs directory exists | ||
| mkdir -p "$LOGS_DIR" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Logs directory permissions may restrict container write access. The Apply this diff to ensure the container user can write to the logs directory: -# Ensure logs directory exists
-mkdir -p "$LOGS_DIR"
+# Ensure logs directory exists and is writable by container user
+mkdir -p "$LOGS_DIR"
+chmod 755 "$LOGS_DIR"
🤖 Prompt for AI Agents
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a reasonable precaution to take. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @subpop Thank you for acknowledging the concern! Let me know if you need any help implementing the permission changes or have questions about the approach. 🧠 Learnings used |
||
|
|
||
| # Build podman command | ||
| PODMAN_ARGS=( | ||
| run --rm -i | ||
| --userns "keep-id:uid=1001,gid=0" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, let's find and examine the script file
find . -name "linux-mcp-container.sh" -type fRepository: rhel-lightspeed/linux-mcp-server Length of output: 108 🏁 Script executed: # List the repo structure to understand the project layout
git ls-files | head -30Repository: rhel-lightspeed/linux-mcp-server Length of output: 768 🏁 Script executed: # Search for Dockerfile or podman-related files
fd -e Dockerfile -e containerfile -o -name "*container*" -o -name "*podman*" 2>/dev/null | head -20Repository: rhel-lightspeed/linux-mcp-server Length of output: 58 🏁 Script executed: # Examine the main script
cat -n ./scripts/linux-mcp-container.shRepository: rhel-lightspeed/linux-mcp-server Length of output: 2078 🏁 Script executed: # Check the main Containerfile
cat -n Containerfile | head -80Repository: rhel-lightspeed/linux-mcp-server Length of output: 3188 🏁 Script executed: # Check the devcontainer Containerfile
cat -n .devcontainer/ContainerfileRepository: rhel-lightspeed/linux-mcp-server Length of output: 697 🏁 Script executed: # Get more of the Containerfile to see user setup
cat -n Containerfile | tail -40Repository: rhel-lightspeed/linux-mcp-server Length of output: 1557 🏁 Script executed: # Search for useradd or RUN commands that set up the mcp user
rg "useradd|groupadd|chown" Containerfile -A 2 -B 2Repository: rhel-lightspeed/linux-mcp-server Length of output: 225 🏁 Script executed: # Look for any documentation about container setup or user requirements
cat -n README.md | head -100Repository: rhel-lightspeed/linux-mcp-server Length of output: 4156 Consider making UID/GID configurable to match Containerfile's flexibility. The hard-coded 🤖 Prompt for AI Agents
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure this is necessary. I doubt many people will rebuild the container image using a different UID. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @subpop, that's a fair point. If rebuilding with a custom UID is an edge case for your users, the current hardcoded approach keeps things simpler. The defaults match the Containerfile and should work for the typical deployment scenario. I'm good with keeping it as is. 🧠 Learnings used |
||
| -v "$SSH_KEY:/var/lib/mcp/.ssh/id_rsa:ro,Z" | ||
| -v "$LOGS_DIR:/var/lib/mcp/.local/share/linux-mcp-server/logs:rw,Z" | ||
| ) | ||
|
|
||
| # Pass through all linux-mcp-server environment variables | ||
| [[ -n "$LINUX_MCP_USER" ]] && PODMAN_ARGS+=(-e "LINUX_MCP_USER=$LINUX_MCP_USER") | ||
| [[ -n "$LINUX_MCP_KEY_PASSPHRASE" ]] && PODMAN_ARGS+=(-e "LINUX_MCP_KEY_PASSPHRASE=$LINUX_MCP_KEY_PASSPHRASE") | ||
| [[ -n "$LINUX_MCP_LOG_LEVEL" ]] && PODMAN_ARGS+=(-e "LINUX_MCP_LOG_LEVEL=$LINUX_MCP_LOG_LEVEL") | ||
|
|
||
| PODMAN_ARGS+=("$IMAGE") | ||
|
|
||
| exec podman "${PODMAN_ARGS[@]}" | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate SSH key existence before mounting.
The script defaults to
$HOME/.ssh/id_rsabut never checks if it exists. Podman's mount error will be cryptic and may not make the root cause obvious to users. Adding a simple existence check improves debuggability.Apply this diff to validate the SSH key before attempting to mount:
Also applies to: 41-41
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with this comment. Adding a check for the SSH key is a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@subpop, thank you for confirming! The SSH key validation will help users quickly identify configuration issues before the container attempts to start, making the error messages much clearer. Let me know if you need any clarification on the implementation.
🧠 Learnings used