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.bean.mcp.v20260728;
018
019import org.apache.juneau.commons.bean.*;
020
021/**
022 * CRTP base for MCP {@code 2026-07-28} request params carrying optional negotiation/trace metadata under the
023 * reserved {@code _meta} wire key.
024 *
025 * <p>
026 * Per the {@code 2026-07-28} schema, every v2 request places its metadata under {@code params._meta} rather than
027 * beside the JSON-RPC envelope. The four concrete params beans ({@link CallToolRequest}, {@link GetPromptRequest},
028 * {@link ReadResourceRequest}, and {@link CompleteRequest}) extend this base without gaining any wire-visible
029 * members beyond their own existing payload fields plus the inherited {@code _meta}. {@link RequestParamsOnly} is
030 * the concrete carrier for methods (list/ping/discovery) whose only common params member is {@code _meta}.
031 *
032 * <p>
033 * This base is a lossless wire carrier only: it performs no negotiation validation. Metadata shape and negotiation
034 * rules are owned by {@link RequestMeta} and the {@code 2026-07-28} adapter's dispatch validation.
035 *
036 * <p>
037 * The CRTP type parameter lets each concrete subclass's {@link #setMeta(RequestMeta)} return its own concrete type
038 * for fluent chaining, without duplicating the {@code _meta} accessor in every subclass.
039 *
040 * @param <T> The concrete subclass, for fluent-setter self-typing.
041 */
042public abstract class RequestParams<T extends RequestParams<T>> {
043
044   private RequestMeta meta;
045
046   /**
047    * Per-request negotiation, extension, and trace-context metadata.
048    *
049    * @return The metadata, or {@code null} if not set.
050    */
051   @BeanProp("_meta")
052   public RequestMeta getMeta() {
053      return meta;
054   }
055
056   /**
057    * Sets the per-request metadata.
058    *
059    * @param value The new value.  Can be <jk>null</jk> to unset the property.
060    * @return This object (for method chaining).
061    */
062   @BeanProp("_meta")
063   @SuppressWarnings({
064      "unchecked" // CRTP subclasses bind T to their own concrete type.
065   })
066   public T setMeta(RequestMeta value) {
067      meta = value;
068      return (T)this;
069   }
070}