Interface SessionIdGenerator<T>
- Type Parameters:
T- the transport-specific request type (a NettyHttpRequestfor the HTTP transport); useObjectfor a request-independent generator likeDEFAULT
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
initialize
request. Lets operators base the id on request headers (tenant id, auth subject, a
client-supplied id, …) or the request URI.
Only consulted when sessions are enabled (session(s -> s.enabled(true)));
stateless servers never create a session and never call this.
T is the transport-specific request type handed to generate(dev.tachyonmcp.api.runtime.InteractionContext, T). The HTTP
transport passes a Netty HttpRequest; keep the type variable open (e.g.
SessionIdGenerator<? super HttpRequest>) so a generator stays reusable across
transports and does not pin the public API to a concrete request type.
Example — derive the id from a tenant header, falling back to a random id:
SessionIdGenerator<HttpRequest> byTenant = (ctx, request) -> {
String tenant = request.headers().get("X-Tenant-Id");
return tenant != null ? "sess_" + tenant + "_" + UUID.randomUUID() : SessionIdGenerator.DEFAULT.generate(ctx, request);
};
server.session(s -> s.enabled(true).sessionIdGenerator(byTenant));
- Author:
- Konstantin Pavlov
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SessionIdGenerator<Object> Default generator:sess_<UUID>, ignoring the request. -
Method Summary
Modifier and TypeMethodDescriptiongenerate(InteractionContext channelContext, T request) Derives a session id from the initialize request (headers, URI, …).default booleanWhethergenerate(dev.tachyonmcp.api.runtime.InteractionContext, T)inspects the request (headers, URI, …).
-
Field Details
-
DEFAULT
Default generator:sess_<UUID>, ignoring the request.
-
-
Method Details
-
generate
Derives a session id from the initialize request (headers, URI, …).Contract for the initialize flow:
- A
nullreturn value or any thrown exception causes the server to respond with aninternal-errorand abort session creation. - A blank string (
""or whitespace-only) is accepted as-is and used directly as the session id — the generator must produce a non-blank value if a valid id is required.
- Parameters:
channelContext- the per-channel interaction (protocol version, lifecycle phase, attribute scratch space); may benullin contexts that create a session without an established channelrequest- the incoming initialize request; may benullwhenreadsRequest()isfalse- Returns:
- the session id to assign; must be non-blank when a valid id is required
- A
-
readsRequest
default boolean readsRequest()Whethergenerate(dev.tachyonmcp.api.runtime.InteractionContext, T)inspects the request (headers, URI, …). Whenfalse, the transport skips detaching a per-request snapshot for the async session-creation dispatch.Defaults to
trueso every custom generator is handed a valid request; override tofalsefor a request-independent id (likeDEFAULT) to opt into the fast path.
-