| Crates.io | brk_mcp |
| lib.rs | brk_mcp |
| version | 0.0.109 |
| created_at | 2025-06-24 10:02:14.391835+00 |
| updated_at | 2025-09-20 17:22:19.411905+00 |
| description | A bridge for LLMs to access BRK |
| homepage | https://bitcoinresearchkit.org |
| repository | https://github.com/bitcoinresearchkit/brk |
| max_upload_size | |
| id | 1724103 |
| size | 96,178 |
Model Context Protocol bridge enabling LLM access to Bitcoin Research Kit data.
This crate provides a Model Context Protocol (MCP) server implementation that exposes Bitcoin blockchain analytics as tools for Large Language Models. Built on the brk_rmcp library, it creates a standards-compliant bridge allowing LLMs to query Bitcoin data through structured tool calls with type-safe parameters and JSON responses.
Key Features:
Target Use Cases:
Add a bitview custom connector with the following URL:
https://bitview.space/mcp
cargo add brk_mcp
use brk_mcp::MCP;
use brk_interface::Interface;
use brk_rmcp::{ServerHandler, RoleServer};
// Initialize with static interface reference
let interface: &'static Interface = /* your interface */;
let mcp = MCP::new(interface);
// Use as MCP server handler
let server_info = mcp.get_info();
println!("MCP server ready with {} tools", server_info.capabilities.tools.unwrap().len());
// Individual tool usage
let index_count = mcp.get_index_count().await?;
let vec_count = mcp.get_vec_count().await?;
let version = mcp.get_version().await?;
MCP: Main server struct implementing ServerHandler trait#[tool_router] macroDiscovery Tools:
get_index_count() - Total number of available indexesget_vecid_count() - Total number of vector identifiersget_vec_count() - Total vector/index combinationsget_indexes() - List of all available indexesget_accepted_indexes() - Mapping of indexes to their variantsData Access Tools:
get_vecids(pagination) - Paginated list of vector IDsget_index_to_vecids(index, pagination) - Vector IDs supporting specific indexget_vecid_to_indexes(id) - Indexes supported by vector IDget_vecs(params) - Main data query tool with flexible parametersSystem Tools:
get_version() - Bitcoin Research Kit version informationCore Query Parameters:
index: Time dimension (height, date, week, month, etc.)ids: Dataset identifiers (comma or space separated)from/to: Range filtering (supports negative indexing from end)format: Output format (json, csv)Pagination Parameters:
page: Page number for paginated results (up to 1,000 entries)use brk_mcp::MCP;
use brk_interface::{Params, PaginationParam};
let mcp = MCP::new(interface);
// Get system information
let version = mcp.get_version().await?;
println!("BRK version: {:?}", version);
// Discover available data
let indexes = mcp.get_indexes().await?;
let vec_count = mcp.get_vec_count().await?;
// Get paginated vector IDs
let pagination = PaginationParam { page: Some(0) };
let vecids = mcp.get_vecids(pagination).await?;
use brk_mcp::MCP;
use brk_interface::Params;
// Query latest Bitcoin price
let params = Params {
index: "date".to_string(),
ids: vec!["dateindex-to-price-close".to_string()].into(),
from: Some(-1),
..Default::default()
};
let result = mcp.get_vecs(params).await?;
match result {
CallToolResult::Success { content, .. } => {
println!("Latest price: {:?}", content);
},
_ => println!("Query failed"),
}
use brk_interface::Params;
// Get OHLC data for last 30 days
let params = Params {
index: "date".to_string(),
ids: vec![
"dateindex-to-price-open".to_string(),
"dateindex-to-price-high".to_string(),
"dateindex-to-price-low".to_string(),
"dateindex-to-price-close".to_string(),
].into(),
from: Some(-30),
format: Some("csv".to_string()),
..Default::default()
};
let ohlc_data = mcp.get_vecs(params).await?;
use brk_interface::{PaginatedIndexParam, IdParam};
// 1. Get available indexes
let indexes = mcp.get_indexes().await?;
// 2. Find vectors for specific index
let paginated_index = PaginatedIndexParam {
index: "height".to_string(),
pagination: PaginationParam { page: Some(0) },
};
let height_vectors = mcp.get_index_to_vecids(paginated_index).await?;
// 3. Check what indexes a vector supports
let id_param = IdParam { id: "height-to-blockhash".to_string() };
let supported_indexes = mcp.get_vecid_to_indexes(id_param).await?;
MCP Protocol Compliance:
ServerHandler trait for MCP compatibilityServerInfo with tools capability enabledTool Registration:
#[tool_router] macro for automatic tool discovery#[tool] attribute for individual tool definitionsMcpError responsesAxum Router Extension:
MCPRoutes trait for router integrationLocalSessionManager/mcp pathTransport Layer:
StreamableHttpService for MCP over HTTPInterface Layer Access:
brk_interface::Interface for data queriesResponse Formatting:
The MCP server provides comprehensive information to LLMs:
ServerInfo {
protocol_version: ProtocolVersion::LATEST,
capabilities: ServerCapabilities::builder().enable_tools().build(),
server_info: Implementation::from_build_env(),
instructions: "Context about Bitcoin data access and terminology",
}
Built-in instructions explain Bitcoin data concepts:
Main Structure: MCP struct implementing ServerHandler with embedded ToolRouter for automatic tool discovery
Tool Implementation: 10 specialized tools using #[tool] attribute with structured parameters and JSON responses
HTTP Integration: MCPRoutes trait extending Axum routers with conditional MCP endpoint mounting
Parameter Types: Type-safe parameter structs from brk_interface with automatic validation
Error Handling: Consistent McpError responses with proper MCP protocol compliance
Transport Layer: StreamableHttpService with stateless configuration for scalable deployment
Architecture: Standards-compliant MCP bridge providing LLM access to comprehensive Bitcoin analytics
This README was generated by Claude Code