A comprehensive Model Context Protocol (MCP) server for working with the Stratum V2 mining protocol specification. This tool provides deep insights into Bitcoin mining protocols, TLV extensions, message structures, and the complete Stratum V2 ecosystem.
- π Protocol Analysis: Detailed analysis of Stratum V2 protocol specification
- π·οΈ TLV Field Operations: Create, parse, and validate Type-Length-Value extension fields
- π¨ Message Generation: Generate test messages for all major Stratum V2 message types
- π’ Binary Protocol Support: Handle specialized Bitcoin mining data types (U256, U24, B032, etc.)
- π₯ Role-based Architecture: Understand Pool, Proxy, Mining Device, and Job Declarator roles
- π Security Features: Noise protocol encryption, cryptographic handshakes
- π‘ Multiple Subprotocols: Mining, Job Declaration, and Template Distribution protocols
- π¦ Comprehensive Crate Integration: Utilizes all 19 official Stratum V2 Rust crates
- Installation
- Quick Start
- Usage
- MCP Integration
- API Reference
- Examples
- Architecture
- Contributing
- License
- Rust: 1.70+ (Install Rust)
- Cargo: Included with Rust installation
# Clone the repository
git clone https://github.com/average-gary/sv2-mcp-server.git
cd sv2-mcp-server
# Build the project
cargo build --release
# Verify installation
cargo run -- --help# Analyze the complete Stratum V2 protocol specification
cargo run -- analyze-protocol
# List all supported message types
cargo run -- list-message-types
# List all protocol extensions
cargo run -- list-extensions# Create a TLV field for worker identity tracking
cargo run -- create-tlv-field 2 1 "worker123"
# Parse TLV fields from hex bytes
cargo run -- parse-tlv-fields "0200010900776f726b6572313233"# Generate test messages for different protocols
cargo run -- generate-test-message "SubmitSharesStandard"
cargo run -- generate-test-message "SetupConnection"
cargo run -- generate-test-message "NewTemplate"The server provides a comprehensive CLI for direct interaction with Stratum V2 protocol features.
# Complete protocol specification analysis
cargo run -- analyze-protocol
# List all supported message types
cargo run -- list-message-types
# List all protocol extensions
cargo run -- list-extensions
# Get detailed information about a specific extension
cargo run -- get-extension-info 2# Create a TLV field for worker identity tracking
cargo run -- create-tlv-field 2 1 "worker123"
# Validate a TLV field
cargo run -- validate-tlv-field 2 1 "worker123"
# Parse TLV fields from hex bytes
cargo run -- parse-tlv-fields "0200010900776f726b6572313233"# Generate test messages for different protocols
cargo run -- generate-test-message "SubmitSharesStandard"
cargo run -- generate-test-message "SetupConnection"
cargo run -- generate-test-message "NewTemplate"
cargo run -- generate-test-message "DeclareTransaction"
# Encode a JSON message to binary
cargo run -- encode-message "SubmitSharesStandard" '{"channel_id": 1, "sequence_number": 1}'
# Decode binary data to JSON
cargo run -- decode-message "SubmitSharesStandard" "0100000001000000"# Comprehensive feature demonstration
cargo run -- demonstrate-advanced-features
# Roles architecture explanation
cargo run -- demonstrate-roles-logic
# Noise protocol security features
cargo run -- demonstrate-noise-protocol
# Buffer management capabilities
cargo run -- demonstrate-buffer-managementThis server integrates with Model Context Protocol clients like Blocks Goose and Cursor.
-
Build the server:
cargo build --release
-
Configure MCP: Copy
example-config.jsonand update the path:{ "mcpServers": { "stratum-v2": { "command": "cargo", "args": ["run", "--release"], "cwd": "/path/to/your/sv2-mcp-server" } } } -
Use with Goose:
from goose import Goose g = Goose(config_file="goose-config.json") # Analyze protocol protocol = g.stratum_v2.analyze_protocol() # Create TLV field tlv = g.stratum_v2.create_tlv_field(2, 1, "worker123")
-
Use with Cursor:
- Create
cursor-mcp-config.jsonwith the same configuration - Restart Cursor
- Ask Claude about Stratum V2 protocol features
- Create
For detailed integration instructions, troubleshooting, and advanced usage examples, see MCP_INTEGRATION.md.
analyze_protocol()- Complete protocol specification analysislist_message_types()- All supported message typeslist_extensions()- Available protocol extensionsget_extension_info(extension_type)- Detailed extension information
create_tlv_field(extension_type, field_type, value)- Create TLV fieldparse_tlv_fields(bytes)- Parse TLV fields from binary datavalidate_tlv_field(extension_type, field_type, value)- Validate TLV field
generate_test_message(message_type)- Generate test messageencode_message(message, message_type)- Encode message to binarydecode_message(bytes, message_type)- Decode binary to message
demonstrate_advanced_features()- Comprehensive feature showcasedemonstrate_roles_logic()- Role-based architecture explanationdemonstrate_noise_protocol()- Security features demonstrationdemonstrate_buffer_management()- Buffer management capabilities
SetupConnection- Initial connection setupSubmitSharesStandard- Standard share submissionSubmitSharesExtended- Extended share submission with TLVOpenStandardMiningChannel- Open mining channelSetTarget- Set mining targetSetCustomMiningJob- Set custom mining job
DeclareTransaction- Declare transaction for miningDeclareTransactionSuccess- Transaction declaration successDeclareTransactionError- Transaction declaration error
NewTemplate- New block templateSetNewPrevHash- Set new previous hashSetNewPrevHashSuccess- Previous hash update success
0x0001- Extensions Negotiation0x0002- Worker-Specific Hashrate Tracking
# Create worker identity TLV field
cargo run -- create-tlv-field 2 1 "worker123"Output:
{
"tlv_field": {
"extension_type": 2,
"field_type": 1,
"length": 9,
"value": [119, 111, 114, 107, 101, 114, 49, 50, 51]
},
"encoded_bytes": "0200010900776f726b6572313233",
"error": null
}cargo run -- analyze-protocolOutput includes:
- Complete protocol specification
- Message type definitions
- Extension information
- Security features
- Binary protocol structure
cargo run -- demonstrate-advanced-featuresOutput includes:
- Binary types (U256, U24, B032, etc.)
- TLV extension system
- Noise protocol security
- Role-based architecture
- Multiple subprotocols
- Message framing
- All 19 available Stratum V2 crates
This MCP server integrates with the complete Stratum V2 ecosystem:
binary_sv2- Binary data typesbinary_codec_sv2- Binary encoding/decodingcodec_sv2- High-level codec with encryptionframing_sv2- Message framingnoise_sv2- Noise protocol encryptionbuffer_sv2- Buffer managementerror_handling- Error utilities
common_messages_sv2- Common message typesmining_sv2- Mining protocoljob_declaration_sv2- Job declaration protocoltemplate_distribution_sv2- Template distributionroles_logic_sv2- Role implementations
network_helpers_sv2- Network utilities
- ChaCha20-Poly1305 AEAD encryption
- X25519 elliptic curve Diffie-Hellman
- BLAKE2s cryptographic hash function
- Forward secrecy
- Mutual authentication
- Resistance to man-in-the-middle attacks
- Efficient message encoding
- Length-prefixed messages
- Message integrity checks
- TLV extension support
- Coordinates mining operations
- Manages mining channels
- Distributes work to miners
- Validates submitted shares
- Handles payouts
- Aggregates multiple miners
- Reduces network overhead
- Provides redundancy
- Optimizes communication
- Performs proof-of-work calculations
- Submits valid shares
- Reports hashrate statistics
- Handles job updates
- Selects transactions for blocks
- Constructs coinbase transactions
- Distributes templates to pools
- Manages transaction selection
We welcome contributions! Please see our Contributing Guidelines for details.
# Clone the repository
git clone https://github.com/average-gary/sv2-mcp-server.git
cd sv2-mcp-server
# Install dependencies
cargo build
# Run tests
cargo test
# Run linter
cargo clippy
# Format code
cargo fmt- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests if applicable
- Ensure all tests pass (
cargo test) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project adheres to the Contributor Covenant Code of Conduct. By participating, you are expected to uphold this code.
This project is licensed under the MIT License - see the LICENSE file for details.
- Documentation: Check this README and MCP_INTEGRATION.md
- Issues: Open an issue on GitHub
- Discussions: Start a discussion for questions and ideas
- Build errors: Ensure you have Rust 1.70+ installed
- MCP integration issues: Check the MCP Integration Guide
- Protocol questions: Review the Stratum V2 Specification
- Stratum v2 Reference Implementation for the Rust reference implementation of Stratum v2
- Model Context Protocol for the MCP standard
- Blocks Goose for MCP client implementation
- Cursor for AI-powered development environment
Made with β€οΈ for the Bitcoin mining community