Architecture
Technical overview of the Arch MCP Server implementation following the Arch Way principles.Design Philosophy
This server embodies Arch Linux principles:- Minimalism - No unnecessary abstractions, clean code
- Correctness - Robust error handling, type hints, comprehensive logging
- Transparency - Well-documented, readable source code
- User-centricity - Assumes competent users, provides information over hand-holding
- Pragmatism - Hybrid approach adapts to runtime environment
System Architecture
Module Breakdown
Main Entry Point (arch_ops_server.py)
Responsibilities:
- MCP protocol implementation
- Resource URI handling
- Tool invocation routing
- Prompt template management
- STDIO transport setup
- Async operation for all network calls
- URI parsing for resources
- JSON serialization of responses
- Error propagation from modules
Utilities (utils.py)
Helper functions for platform detection and safe execution:
Arch Wiki Interface (wiki.py)
Manages Arch Wiki searches and page retrieval:
https://wiki.archlinux.org/api.php- Direct page URLs for scraping fallback
- Timeouts (10s default)
- HTTP errors with status codes
- Missing pages (404)
- API errors in response JSON
AUR RPC Interface (aur.py)
Handles AUR package operations and security analysis:
https://aur.archlinux.org/rpchttps://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD
Official Repository Interface (pacman.py)
Hybrid local/remote access to official packages:
- On Arch: Fast local queries, offline-capable
- Remote: API-based, works anywhere
Data Flow Examples
Example 1: Reading an Arch Wiki Page
Example 2: Auditing an AUR Package
Error Handling Strategy
Graceful Degradation
Error Response Format
All errors follow consistent structure:NotFound- Resource doesn’t existTimeoutError- Network timeoutHTTPError- HTTP status errorNotSupported- Feature unavailable on platformCommandNotFound- Required command missingRateLimitError- API rate limit exceeded
Concurrency Model
Async/Await Throughout
All network and subprocess operations are async for non-blocking I/O:- Non-blocking I/O
- Concurrent tool calls possible
- Responsive server
- Timeout support built-in
HTTP Client Management
Useshttpx.AsyncClient with context managers:
- Automatic connection pooling
- Timeout enforcement
- Proper cleanup
- HTTP/2 support
Security Considerations
AUR Safety (Defense in Depth)
- Warning metadata - All AUR responses include warnings
- PKGBUILD analysis - Automated scanning for red flags
- Metadata display - Show votes, maintainer, age
- Manual review - Encourage PKGBUILD inspection
- Official first - Always check official repos first
- Pattern matching can’t catch all malicious code
- Obfuscation can bypass detection
- User judgment still required
Command Execution
Only safe read-only commands:pacman -Si- Query package infocheckupdates- Check for updates (no installation)
- Timeout enforcement (default 10s)
- No shell=True (prevents shell injection)
- Whitelist of allowed commands
- Platform checks before execution
Network Safety
- Timeout limits - All requests have timeouts
- HTTPS only - No plaintext HTTP
- Rate limiting - Handle 429 responses
- Input validation - Sanitize user inputs
Performance Optimizations
Caching Strategy
Current: No caching (always live data) Rationale: Rolling release means data changes frequently Future: Consider time-based caching:- Wiki pages: 1 hour
- Package info: 5 minutes
- AUR metadata: 10 minutes
Request Efficiency
- Single API calls - No unnecessary round trips
- Async operations - Concurrent requests possible
- Connection pooling - httpx manages connections
- Timeout limits - Don’t wait forever
Testing Strategy
Functional Tests
Basic tests verify core functionality:- Wiki search and page retrieval
- AUR search and PKGBUILD fetch
- Official package lookup
- Platform detection
Integration Testing
Use MCP Inspector for interactive testing:Manual Testing Checklist
- Resources work on both Arch and non-Arch
- Tools return proper error responses
- Prompts guide users through workflows
- AUR warnings always present
- Timeouts enforced
- Logging goes to stderr
Extension Points
Adding New Tools
- Create async function in appropriate module
- Export from
__init__.py - Add
@server.tool()decorator in main file - Update
list_tools()with schema - Add handler in
call_tool() - Document in README and examples
Adding New Resources
- Define URI scheme
- Add parsing in
read_resource() - Implement fetch logic in module
- Add example to
list_resources() - Document usage
Adding New Prompts
- Design workflow
- Add
@server.prompt()decorator - Implement in
get_prompt() - Add to
list_prompts() - Create example in documentation
Future Enhancements
Planned Features
- Caching layer for performance
- Arch News integration
- Package dependency tree analysis
- Security advisory integration (arch-audit)
- Local pacman.conf parsing
- File list queries for packages
- Systemd unit analysis
- Custom repository support
Potential Improvements
- Metrics collection (response times, error rates)
- More sophisticated PKGBUILD analysis
- Wiki page diff tracking
- AUR package popularity trends
- Integration with Arch forums
- Batch operations support
Contributing
Want to contribute? See the Contributing Guide for:- Development setup and testing
- Code standards and best practices
- Pull request process
- Feature contribution guidelines
References
Built with ❤️ following the Arch Way.