HTTP client library for communicating with Binary Ninja MCP servers.
This crate provides a Rust client for the Binary Ninja MCP server (from binary_ninja_mcp/). It enables smartdiff to fetch binary analysis data from Binary Ninja without requiring direct Binary Ninja API dependencies.
Key Features:
- ✅ No Binary Ninja dependencies required
- ✅ Works with Personal License (via Binary Ninja MCP server)
- ✅ Simple HTTP/JSON API
- ✅ Multi-binary support
- ✅ Async/await with tokio
- ✅ Comprehensive error handling
smartdiff (Rust)
↓ (HTTP client - this crate)
Binary Ninja MCP Server (Python)
↓ (Python API)
Binary Ninja (GUI with Personal License)
use smart_diff_binary_ninja_client::BinaryNinjaClient;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let client = BinaryNinjaClient::new();
// Discover available Binary Ninja servers
let servers = client.discover_servers().await?;
for server in servers {
println!("Found binary: {} on port {}", server.filename, server.port);
// List functions
let functions = client.list_functions(&server.binary_id).await?;
println!(" Functions: {}", functions.len());
// Decompile a function
if let Some(func) = functions.first() {
let code = client.decompile_function(&server.binary_id, &func.name).await?;
println!(" Decompiled {}:\n{}", func.name, code);
}
}
Ok(())
}use smart_diff_binary_ninja_client::{BinaryNinjaClient, ClientConfig};
use std::time::Duration;
let config = ClientConfig {
base_url: "http://localhost".to_string(),
base_port: 9009,
max_servers: 10,
connect_timeout: Duration::from_secs(2),
read_timeout: Duration::from_secs(30),
max_retries: 2,
};
let client = BinaryNinjaClient::with_config(config);Create a new client with default configuration.
Create a new client with custom configuration.
Discover available Binary Ninja MCP servers by scanning ports 9009+.
Returns a list of servers with metadata about loaded binaries.
Get information about a specific binary server.
List all functions in a binary.
Returns a list of function names. Use get_function_info for detailed information.
Search for functions by name.
Decompile a function and return the decompiled code.
Get detailed information about a function including decompiled code.
Information about a Binary Ninja MCP server instance.
pub struct BinaryNinjaServer {
pub binary_id: String, // e.g., "port_9009"
pub url: String, // e.g., "http://localhost:9009"
pub port: u16, // e.g., 9009
pub filename: String, // e.g., "malware.exe"
pub metadata: Option<BinaryMetadata>,
}Information about a function in a binary.
pub struct FunctionInfo {
pub name: String,
pub address: String,
pub raw_name: Option<String>,
pub symbol: Option<SymbolInfo>,
pub decompiled_code: Option<String>,
}Information about a binary.
pub struct BinaryInfo {
pub binary_id: String,
pub filename: String,
pub loaded: bool,
pub metadata: Option<BinaryMetadata>,
}The crate uses BinaryNinjaError for domain-specific errors:
pub enum BinaryNinjaError {
NoServersAvailable,
ServerNotFound(String),
RequestFailed(String),
ParseError(String),
BinaryNinjaError(String),
FunctionNotFound(String),
Timeout,
}All public methods return anyhow::Result<T> for easy error propagation.
To use this client, you need:
- Binary Ninja (with Personal License or higher)
- Binary Ninja MCP Server running (from
binary_ninja_mcp/) - Binaries loaded in Binary Ninja with MCP server started
- Start Binary Ninja and load a binary
- Start the MCP server for that binary:
- Plugins > MCP Server > Start Server for This Binary
- Server will start on port 9009 (or next available port)
- Use this client to connect and fetch data
Run tests with:
cargo test -p smart-diff-binary-ninja-clientNote: Most tests are unit tests that don't require a running Binary Ninja server. Integration tests that require a server are marked with #[ignore].
reqwest- HTTP clientserde/serde_json- JSON serializationtokio- Async runtimeanyhow/thiserror- Error handlingtracing- Logging
AGPL-3.0-only
- Binary Ninja MCP Server - The server this client connects to
- smartdiff MCP Server - Uses this client for binary comparison
- Binary Ninja - The reverse engineering platform