import type { AtribRecord } from './types.js'; /** Extracted inbound context from an MCP request. */ export interface InboundContext { /** The record_hash from the upstream token. becomes chain_root of the next record. */ recordHash: Uint8Array; /** The creator_key from the upstream token. identifies the sender. */ creatorKey: Uint8Array; /** OTel trace-id from traceparent, if available. */ contextId: string | undefined; /** Session token from baggage, if available. */ sessionToken: string | undefined; } /** Options for writing outbound context. */ export interface OutboundContextOptions { /** traceparent value to forward (§1.5.4). */ traceparent?: string | undefined; /** session_token to propagate in baggage (§1.5.5). */ sessionToken?: string | undefined; } /** * Read inbound attribution context from an MCP tools/call request (§5.3.2). * Priority: params._meta.atrib > tracestate atrib= > X-Atrib-Chain */ export declare function readInboundContext(params: Record): InboundContext | null; /** * Write outbound attribution context into an MCP response (§5.3.4). * Writes to _meta.atrib, _meta.tracestate, _meta['X-Atrib-Chain'], * and optionally _meta.traceparent and _meta.baggage. */ export declare function writeOutboundContext(result: Record, signedRecord: AtribRecord, options?: OutboundContextOptions): void; /** * Merge a new atrib tracestate entry into an existing tracestate string, * placing atrib leftmost (most-recent), removing any prior atrib entry, and * enforcing the W3C 32-list-member maximum. * * If adding atrib would exceed the 32-entry limit, the rightmost entries are * evicted first per W3C truncation guidance: "entries SHOULD be removed * starting from the end of `tracestate`." */ export declare function mergeTracestate(atribEntry: string, existing: string): string; /** * Merge a new atrib-session baggage entry into an existing baggage string, * deduping any prior atrib-session entry and enforcing the W3C 64-list-member * and 8192-byte maximums. */ export declare function mergeBaggageAtribSession(sessionToken: string, existing: string): string; /** * Parse the `atrib=` entry from a W3C tracestate string. * * Spec: https://www.w3.org/TR/trace-context/. list-member grammar is * `key=value` separated by commas with optional whitespace (OWS) on either * side of the comma. Per the spec, callers SHOULD use single space or no * whitespace, but receivers must accept either. * * Note: tracestate values per the spec are 0-256 printable ASCII, no comma, * no equals sign. so the first `=` after `atrib` cleanly delimits the value. */ export declare function parseTracestateAtrib(tracestate: string): string | null; /** * Extract 32-char trace-id from a W3C traceparent header value. * * Spec: https://www.w3.org/TR/trace-context/#traceparent-header. format is * `version-trace_id-parent_id-trace_flags` where trace-id is 32 lowercase * hex characters and MUST NOT be all zeros. Receivers MUST ignore the * traceparent entirely if either trace-id or parent-id is invalid. */ export declare function extractTraceId(traceparent: string): string | undefined; /** * Parse the `atrib-session=` value from a W3C Baggage string. * * Spec: https://www.w3.org/TR/baggage/. list-member grammar is * `key OWS = OWS value *( OWS ; OWS property )`. The value may be followed * by zero or more `;property` segments which are NOT part of the value. * Receivers MUST strip the property suffix when extracting the value. * * Examples: * `atrib-session=tok123` → `tok123` * `atrib-session = tok123` → `tok123` (OWS around `=`) * `atrib-session=tok123;ttl=300` → `tok123` (property stripped) * `atrib-session = tok123 ; ttl=300` → `tok123` (OWS + property stripped) */ export declare function parseBaggageAtribSession(baggage: string): string | undefined; //# sourceMappingURL=context.d.ts.map