001/* 002 * Copyright 2022-2026 Revetware LLC. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package com.soklet; 018 019import org.jspecify.annotations.NonNull; 020 021import javax.annotation.concurrent.ThreadSafe; 022 023/** 024 * Programmatic MCP resource-read handler. 025 * 026 * <p>Routing proves neither authorization nor safe dereference. An application 027 * that maps a resource URI to a filesystem must canonicalize its configured 028 * root and requested target, reject targets outside that root after symlink 029 * resolution, authorize the canonical target under the current admitted 030 * identity, and address deployment-specific races between validation and 031 * opening. Soklet provides no filesystem mapper or containment guarantee. 032 * 033 * <p>The application must also define URI policy by delivery intent. A URI 034 * permitted for direct client loading may need a different scheme, authority, 035 * credential, query, and fragment policy from an application-handler-only 036 * URI. Soklet's URI syntax validation and routing do not establish that a URI 037 * is safe or consumable for either purpose. 038 * 039 * <p>Handlers may complete with 040 * {@link McpCompleteResult#fromResourceOutput(McpResourceOutput)} or return a 041 * declared multi-round-trip result. Implementations must be safe for 042 * concurrent invocation. 043 * 044 * @author <a href="https://www.revetkn.com">Mark Allen</a> 045 */ 046@ThreadSafe 047@FunctionalInterface 048public interface McpResourceReadHandler { 049 /** 050 * Reads one routed resource under application authorization and policy. 051 * 052 * @param requestContext request metadata 053 * @param resourceReadContext resolved resource URI and template variables 054 * @param invocationFeatures invocation-scoped optional features 055 * @return recognized non-null operation result 056 * @throws Exception if application handling fails 057 */ 058 @NonNull 059 McpOperationResult handle(@NonNull McpRequestContext requestContext, 060 @NonNull McpResourceReadContext resourceReadContext, 061 @NonNull McpInvocationFeatures invocationFeatures) throws Exception; 062}