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;
022import java.net.URI;
023import java.util.Map;
024
025/**
026 * Immutable routed input for one MCP resource-read invocation.
027 *
028 * <p>The URI and template variables remain application input. Routing does not
029 * authorize the current principal, establish filesystem containment, or say
030 * that the URI is safe for direct client loading. A handler must apply its own
031 * delivery-intent URI allowlist and, for filesystem-backed resources,
032 * canonicalize and contain the target before authorization and opening.
033 *
034 * @author <a href="https://www.revetkn.com">Mark Allen</a>
035 */
036@ThreadSafe
037public interface McpResourceReadContext {
038        /**
039         * Returns the exact routed resource URI supplied by the client.
040         *
041         * @return exact resource URI; not an authorization or dereference decision
042         */
043        @NonNull
044        URI getUri();
045
046        /**
047         * Returns URI-template variables captured while routing this resource.
048         * Values are UTF-8 percent-decoded exactly once: an encoded slash
049         * ({@code %2F}) becomes {@code /}, while {@code %252F} becomes the literal
050         * string {@code %2F}. {@link #getUri()} retains the original client URI.
051         * Captures can be empty and can contain decoded NUL, CR or LF; validate
052         * values for the intended application use before using them.
053         * Capturing a variable does not authorize filesystem access or establish
054         * that a decoded path is safe.
055         *
056         * @return immutable variable map, empty for an exact-URI registration
057         */
058        @NonNull
059        Map<@NonNull String, @NonNull String> getUriTemplateVariables();
060}