Crate ubl_mcp

Crate ubl_mcp 

Source
Expand description

ubl-mcp — Secure Model Context Protocol for LogLine Agents

MCP tools, but with a kernel: policy-first, audit-ready, and boringly predictable.

This crate is a clean implementation of the Model Context Protocol (JSON-RPC 2.0) that routes every tool call through a policy gate. It’s the “universal IO bus” for your agents — interop with the MCP ecosystem without giving the model a foot-gun.

§Security Model

┌─────────────┐     ┌──────────────┐     ┌──────────────┐     ┌─────────────┐
│ Agent Brain ├────▶│ PolicyGate   ├────▶│ Transport    ├────▶│ MCP Server  │
└─────────────┘     │ (permit/deny)│     │ (stdio/http) │     └──────┬──────┘
                    └──────────────┘     └──────────────┘            │
                           │                                         │
                           ▼                                         ▼
                    ┌──────────────┐                          ┌─────────────┐
                    │ AuditSink    │                          │ Tool Result │
                    │ (UBL Ledger) │                          └─────────────┘
                    └──────────────┘
  1. Gate-before-IO: tool calls are proposals → Gate decides Permit/Deny/Challenge
  2. Auditable: every call (success, failure, or blocked) is recorded
  3. Schema-first: tools declare their input schema (via schemars)

§Example

use ubl_mcp::{McpClient, ToolResult, gate::AllowAll, audit::NoAudit, client::MockEndpoint};

let client = McpClient::new(AllowAll, NoAudit, MockEndpoint::with_text("hello"));

let result = client
    .tool("echo", serde_json::json!({"text": "hello"}))
    .execute()
    .await?;

println!("Result: {:?}", result);

§Features

  • client (default): MCP client with SecureToolCall
  • server (default): MCP server with schema-first tool registration
  • transport-stdio (default): stdio transport (line-delimited JSON)
  • transport-http: HTTP transport (optional)
  • gate-tdln: TDLN Gate integration (optional)
  • audit: UBL Ledger audit sink (optional)

Re-exports§

pub use client::McpClient;client
pub use client::MockEndpoint;client
pub use client::RpcEndpoint;client
pub use client::SecureToolCall;client
pub use server::McpServer;server
pub use server::ServerBuilder;server

Modules§

audit
Audit sink for recording tool calls.
clientclient
MCP Client with Gate enforcement and Audit logging.
gate
Policy gate for tool call authorization.
serverserver
MCP Server with schema-first tool registration.
transporttransport-stdio
Transport implementations for MCP.

Structs§

JsonRpcError
JSON-RPC 2.0 error object.
JsonRpcNotification
JSON-RPC 2.0 notification (no ID, no response expected).
JsonRpcRequest
JSON-RPC 2.0 request.
JsonRpcResponse
JSON-RPC 2.0 response.
ToolDefinition
MCP tool definition.
ToolResult
MCP tool execution result.

Enums§

ContentBlock
Content block in a tool result.
McpError
MCP errors specific to this crate.
RequestId
JSON-RPC 2.0 request/response ID.