001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.rest.server.mcp.v20260728;
018
019import java.util.*;
020
021/**
022 * The resolved MCP operation an {@link McpOperationScopeResolver} decides required scopes for (SEP-2350 per-operation
023 * step-up).
024 *
025 * <p>
026 * Carries the JSON-RPC {@code method} (e.g. {@code tools/call}), the operation {@code name} (the tool / prompt name or
027 * resource URI, as returned by the revision's routing-name derivation), and an opaque read-only view of the raw JSON-RPC
028 * request {@code params}.  A static per-operation scope map keys on {@code (method, name)}; the {@code params} view is the
029 * seam a future dynamic resolver could consult (not built for 10.0).
030 *
031 * <p>
032 * {@code params} is the <em>raw</em> JSON-RPC {@code params} object, not the unwrapped tool-call arguments: for a
033 * {@code tools/call} request it is {@code {"name":<tool>, "arguments":{...}}}, so a resolver reads the tool arguments via
034 * {@code ctx.params().get("arguments")} rather than treating {@code params} as the argument map itself.
035 *
036 * @param method The JSON-RPC method.  Never {@code null}.
037 * @param name The operation name (tool/prompt name or resource URI), or {@code null} for methods without one.
038 * @param params A read-only view of the raw JSON-RPC request params.  Never {@code null}.
039 * @since 10.0.0
040 */
041public record McpOperationContext(String method, String name, Map<String,Object> params) {
042
043   /**
044    * Compact constructor enforcing a non-null method and defensively copying the params to a read-only map.
045    */
046   public McpOperationContext {
047      Objects.requireNonNull(method, "method");
048      params = params == null ? Map.of() : Collections.unmodifiableMap(new LinkedHashMap<>(params));
049   }
050}