Filters and Checks Reference
This reference documents the APIs for filters and initial checks. For usage examples, see Using Filters and Initial Checks.
Filter Interfaces
All filter interfaces follow the same pattern with a test() method that receives the feature information and a FilterContext.
Both test() methods are default methods. Implement the variant with FilterContext; the variant with McpConnection is kept for backward compatibility.
|
ToolFilter
package io.quarkiverse.mcp.server;
public interface ToolFilter {
default boolean test(ToolInfo tool, McpConnection connection) {
return true;
}
/**
* @param tool The tool being tested
* @param context The filter context
* @return true if the tool should be visible, false otherwise
*/
default boolean test(ToolInfo tool, FilterContext context) {
return test(tool, context.connection());
}
}
ResourceFilter
package io.quarkiverse.mcp.server;
public interface ResourceFilter {
default boolean test(ResourceInfo resource, McpConnection connection) {
return true;
}
/**
* @param resource The resource being tested
* @param context The filter context
* @return true if the resource should be visible, false otherwise
*/
default boolean test(ResourceInfo resource, FilterContext context) {
return test(resource, context.connection());
}
}
ResourceTemplateFilter
package io.quarkiverse.mcp.server;
public interface ResourceTemplateFilter {
default boolean test(ResourceTemplateInfo template, McpConnection connection) {
return true;
}
/**
* @param template The template being tested
* @param context The filter context
* @return true if the template should be visible, false otherwise
*/
default boolean test(ResourceTemplateInfo template, FilterContext context) {
return test(template, context.connection());
}
}
PromptFilter
package io.quarkiverse.mcp.server;
public interface PromptFilter {
default boolean test(PromptInfo prompt, McpConnection connection) {
return true;
}
/**
* @param prompt The prompt being tested
* @param context The filter context
* @return true if the prompt should be visible, false otherwise
*/
default boolean test(PromptInfo prompt, FilterContext context) {
return test(prompt, context.connection());
}
}
FilterContext
The FilterContext object provides access to connection and metadata information during filtering.
package io.quarkiverse.mcp.server;
public interface FilterContext {
/**
* @return The MCP method of the current request, e.g. `tools/list`
*/
McpMethod method();
/**
* @return The MCP connection for the current request
*/
McpConnection connection();
/**
* @return The `_meta` of the current request
*/
Meta meta();
/**
* @return The id of the current request
*/
RequestId requestId();
}
McpConnection
The McpConnection object provides access to:
// Get initial request with client info and capabilities
InitialRequest initialRequest = connection.initialRequest();
// Access client information
String clientName = initialRequest.implementation().name();
String clientVersion = initialRequest.implementation().version();
// Check client capabilities
boolean supportsSampling = initialRequest.supportsSampling();
boolean supportsElicitation = initialRequest.supportsElicitationFormMode();
boolean supportsRoots = initialRequest.supportsRoots();
InitialCheck Interface
The InitialCheck interface is used to validate connections during the initialization handshake.
package io.quarkiverse.mcp.server;
import io.smallrye.mutiny.Uni;
public interface InitialCheck {
/**
* Perform the check.
*
* @param initialRequest The initialization request from the client
* @return A Uni<CheckResult> indicating success or failure
*/
Uni<CheckResult> perform(InitialRequest initialRequest);
}
CheckResult
CheckResult is a record nested in the InitialCheck interface that represents the result of an initial check.
The static factory methods return a Uni<CheckResult> that can be returned directly from InitialCheck#perform().
package io.quarkiverse.mcp.server;
public interface InitialCheck {
// ...
record CheckResult(boolean error, String message) {
/**
* A successful check result (convenience constant)
*/
public static final CheckResult SUCCESS = new CheckResult(false, null);
/**
* @return a successful check result
*/
public static Uni<CheckResult> success() {
return Uni.createFrom().item(SUCCESS);
}
/**
* @param message The error message to send to the client
* @return a failed check result
*/
public static Uni<CheckResult> error(String message) {
return Uni.createFrom().item(new CheckResult(true, message));
}
}
}
Usage examples:
import io.quarkiverse.mcp.server.InitialCheck.CheckResult;
// Success
return CheckResult.success();
// Or using the constant
return Uni.createFrom().item(CheckResult.SUCCESS);
// Error with message
return CheckResult.error("Authentication failed");
InitialRequest
The InitialRequest object provides access to client information and capabilities during the initialization handshake.
Client Information
// Get client name and version
String clientName = initialRequest.implementation().name();
String clientVersion = initialRequest.implementation().version();
// Protocol version
String protocolVersion = initialRequest.protocolVersion().version();
Client Capabilities
Check what capabilities the client supports:
// Check for sampling support
boolean supportsSampling = initialRequest.supportsSampling();
// Check for elicitation support
boolean supportsElicitation = initialRequest.supportsElicitationFormMode();
// Check for roots support
boolean supportsRoots = initialRequest.supportsRoots();
Example Usage
@Override
public Uni<CheckResult> perform(InitialRequest initialRequest) {
// Protocol version
String version = initialRequest.protocolVersion().version();
// Client information
String clientName = initialRequest.implementation().name();
String clientVersion = initialRequest.implementation().version();
// Client capabilities
boolean hasSampling = initialRequest.supportsSampling();
boolean hasElicitation = initialRequest.supportsElicitationFormMode();
boolean hasRoots = initialRequest.supportsRoots();
// Make decision based on this information
if (!hasSampling) {
return CheckResult.error("Sampling support required");
}
return CheckResult.success();
}
Feature Information Objects
Filter methods receive feature-specific information objects that provide details about the feature being tested.
ToolInfo
Provides information about a tool:
// Get tool name
String name = tool.name();
// Get tool description
String description = tool.description();
// Additional metadata available through the feature info API
ResourceInfo
Provides information about a resource:
// Get resource URI
String uri = resource.uri();
// Get resource name (if available)
String name = resource.name();
// Get resource description
String description = resource.description();
Execution Behavior
Filter Execution
-
Filters are CDI beans automatically discovered at startup
-
Multiple filters execute in
@Priorityorder (higher values first) -
All filters must return
truefor a feature to be visible (logical AND) -
Filters execute on the event loop (must be non-blocking)
-
Exceptions in filters are logged and ignored
Initial Check Execution
-
Checks execute during the MCP
initializerequest -
Checks execute sequentially by
@Priority(higher values first) -
First failed check stops execution and returns error to client
-
Checks can be async (return
Uni<CheckResult>) -
Failed checks prevent connection establishment
Initial checks are only executed for an explicit initialize request. They are not executed for stateless clients (protocol version 2026-07-28+), which use server/discover instead of the initialize handshake, and for connections that are initialized automatically, e.g. via quarkus.mcp.server.http.streamable.auto-init or the dev mode dummy initialization. Do not rely on initial checks as the only access control mechanism.
|
Related Documentation
-
Using Filters and Initial Checks - Practical guide with examples