feat: implement APT backend for Debian/Debian-derivative support#20
Merged
feat: implement APT backend for Debian/Debian-derivative support#20
Conversation
accdb20 to
cfeb98d
Compare
Angelmmiguel
approved these changes
Feb 3, 2026
| @@ -194,19 +314,19 @@ impl ServerHandler for Apk { | |||
| Ok(exec_result) => { | |||
| if exec_result.status == 0 { | |||
| let success_message = | |||
| format!("✓ Package '{package}' was installed successfully."); | |||
Contributor
There was a problem hiding this comment.
Saving some tokens hehe
Contributor
Author
There was a problem hiding this comment.
It was the initial proposal and I said well.. why not :)
Comment on lines
+38
to
+58
| let router = if std::path::Path::new("/etc/alpine-release").exists() { | ||
| tracing::info!("Detected Alpine Linux, using APK backend"); | ||
| let handler = PackageManagerHandler::new(Apk::new()); | ||
| let service = StreamableHttpService::new( | ||
| move || Ok(handler.clone()), | ||
| LocalSessionManager::default().into(), | ||
| Default::default(), | ||
| ); | ||
| axum::Router::new().nest_service("/mcp", service) | ||
| } else if std::path::Path::new("/etc/debian_version").exists() { | ||
| tracing::info!("Detected Debian/Debian-derivative, using APT backend"); | ||
| let handler = PackageManagerHandler::new(Apt::new()); | ||
| let service = StreamableHttpService::new( | ||
| move || Ok(handler.clone()), | ||
| LocalSessionManager::default().into(), | ||
| Default::default(), | ||
| ); | ||
| axum::Router::new().nest_service("/mcp", service) | ||
| } else { | ||
| anyhow::bail!("Unsupported OS: neither Alpine nor Debian detected"); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduce APT backend support for Debian/Debian-derivative systems alongside the existing APK backend for Alpine Linux. The codebase is refactored from a single APK-specific implementation into a trait-based architecture with a generic
PackageManagerHandler<T>that works with any backend implementing thePackageManagertrait. The server auto-detects the host OS at runtime via file system markers (/etc/alpine-release,/etc/debian_version) and selects the appropriate backend.Changes
PackageManagertrait defining a common interface (install_package,install_package_with_version,search_package,list_installed_packages,refresh_repositories)PackageManagerHandler<T: PackageManager>generic handler that implementsServerHandleronce for all backendssrc/apk.rsintosrc/backend/apk.rsas anApkstruct implementingPackageManagersrc/backend/apt.rswithAptstruct implementingPackageManagerusingapt-get,apt-cache, andaptcommands withDEBIAN_FRONTEND=noninteractivemain.rsto select the correct backend at startupAGENTS.md,Makefile, and.dev-mcp.jsonto reflect multi-backend supportNotes
The APT backend uses
apt-cache madisonfor version lookup ininstall_package_with_version, compared to APK's multi-repository search approach. Input validation for APT additionally allows colons (for architecture-qualified package names likepackage:amd64) and tildes (for Debian version strings like1.0~beta).flowchart TD Start([Server starts]) --> Detect{OS detection} Detect -->|/etc/alpine-release| APK[PackageManagerHandler<Apk>] Detect -->|/etc/debian_version| APT[PackageManagerHandler<Apt>] Detect -->|Neither| Err[Exit with error] APK --> MCP[MCP endpoint at /mcp] APT --> MCPCloses: #7