HttpTransport

class HttpTransport(registry: ToolRegistry, port: Int = 8080, bearerToken: String? = null, requireAuth: Boolean = true, readOnly: Boolean = false, context: Context? = null, serverVersion: String = DROID_MCP_VERSION, auditSink: AuditSink? = null, tls: TlsConfig? = null)

Ktor/Netty MCP server for desktop clients. Exposes the JSON-RPC surface at POST /mcp (plus an SSE channel and a /health probe), enforces bearer auth via a TokenStore when requireAuth is set, optionally terminates TLS, and advertises itself over mDNS (_mcp._tcp). Prefer building one through DroidMcp.Builder.enableHttpServer rather than directly.

Parameters

registry

Tools to serve.

port

Plaintext port; overridden by TlsConfig.httpsPort when tls is set.

bearerToken

Fixed primary token; a random one is generated when null and requireAuth is true.

requireAuth

Require a Bearer token on every request. When false the server is open.

readOnly

Serve only read-only tools.

context

Android context for mDNS registration; mDNS is skipped when null.

serverVersion

Version reported in initialize and the mDNS TXT record.

auditSink

Optional per-call audit hook.

tls

TLS material; when set the server binds HTTPS and exposes tlsFingerprint.

Constructors

Link copied to clipboard
constructor(registry: ToolRegistry, port: Int = 8080, bearerToken: String? = null, requireAuth: Boolean = true, readOnly: Boolean = false, context: Context? = null, serverVersion: String = DROID_MCP_VERSION, auditSink: AuditSink? = null, tls: TlsConfig? = null)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Current primary token, or null on an open server. Tracks rotateToken.

Link copied to clipboard

Whether the server terminates TLS.

Link copied to clipboard

mDNS service name advertised on the network, derived from the device model (sanitised, ≤63 chars).

Link copied to clipboard

SHA-256 fingerprint of the server certificate to pin in the pairing QR, or null when TLS is disabled. See TlsConfig.certFingerprintSha256.

Functions

Link copied to clipboard

Whether the embedded server is currently running.

Link copied to clipboard
fun pairClient(label: String): String?

Mint a revocable token for a named client. Re-pairing an existing label replaces its token. Returns the new token, or null on an open server.

Link copied to clipboard

Snapshot of paired clients (excludes the primary). Empty on an open server.

Link copied to clipboard

Revoke a paired client's token. @return true if a client with that label existed.

Link copied to clipboard

Rotate the primary bearer token, invalidating the old one. Paired-client tokens are unaffected. Returns the new token, or null on an open server. Surface the new value in a fresh pairing QR.

Link copied to clipboard
fun start()

Start the embedded server and register mDNS. No-op if already running; rethrows bind failures.

Link copied to clipboard
fun stop()

Stop the server and unregister mDNS. No-op if not running.