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.client.mcp.v20260728;
018
019/**
020 * Thrown by the client-side MRTR (SEP-2322) auto-resume helpers
021 * ({@link McpClient#callToolWithElicitation}, {@link McpClient#getPromptWithElicitation},
022 * {@link McpClient#readResourceWithElicitation}) when a server keeps returning {@code input_required} pauses past
023 * the loop's configured maximum number of resume rounds.
024 *
025 * <p>
026 * This is a guard against an unbounded (or maliciously non-terminating) elicitation loop, distinct from a
027 * server-reported JSON-RPC error (which surfaces as {@link org.apache.juneau.bean.jsonrpc.McpException}). It is an
028 * unchecked exception so it does not widen the {@code throws} clause of the helper methods beyond
029 * {@link java.io.IOException}; reaching it almost always indicates a server or handler that never converges rather
030 * than a condition ordinary caller code can recover from.
031 *
032 * @since 10.0.0
033 */
034public class McpElicitationLimitException extends RuntimeException {
035
036   private static final long serialVersionUID = 1L;
037
038   private final int maxRounds;
039
040   /**
041    * Constructor.
042    *
043    * @param maxRounds The configured maximum number of resume rounds that was exceeded.
044    */
045   public McpElicitationLimitException(int maxRounds) {
046      super("MCP elicitation auto-resume exceeded the maximum of " + maxRounds + " round(s) without reaching a terminal result.");
047      this.maxRounds = maxRounds;
048   }
049
050   /**
051    * The configured maximum number of resume rounds that was exceeded.
052    *
053    * @return The max-rounds bound.
054    */
055   public int getMaxRounds() {
056      return maxRounds;
057   }
058}