Class McpToolUtils

java.lang.Object
io.meeds.mcp.server.util.McpToolUtils

public class McpToolUtils extends Object
  • Field Details

  • Method Details

    • parseToolDefinitions

      public static List<SimpleToolDefinition> parseToolDefinitions(URL url)
    • fromJsonString

      public static final ToolDefinitionMethods fromJsonString(String value)
    • fromJsonStringBase64

      public static ToolDefinitionMethods fromJsonStringBase64(String value)
    • toJsonStringBase64

      public static String toJsonStringBase64(ToolDefinitionMethods toolDefinitions)
    • toSnakeCase

      public static String toSnakeCase(String name)
    • toCamelCase

      public static String toCamelCase(String name)
    • getMethodToolFieldValue

      public static Object getMethodToolFieldValue(org.springframework.ai.tool.method.MethodToolCallback toolCallback, String fieldName) throws NoSuchFieldException, IllegalAccessException
      Throws:
      NoSuchFieldException
      IllegalAccessException
    • getCurrentUserName

      public static String getCurrentUserName()
      Resolves the user on behalf of whom the current Tool is executed: the kernel ConversationState identity when set, else, for the internal client-credentials call only, the TOOL_CONTEXT_USER_NAME_PARAM request header, else the authenticated principal. The header is trusted under the gate of getInternalToolCallRequest() and nowhere else; the internal call is recognized by the OAuth client that owns the token (isInternalClientAuthentication(Authentication)), never by the token subject, so a user whose login happens to be the internal client id is just that user.
      Returns:
      the user name, or null when no user can be resolved
    • getCurrentConversationId

      public static String getCurrentConversationId()
      Resolves the AI chat conversation in which the current Tool is executed. The id travels in the TOOL_CONTEXT_CONVERSATION_ID_PARAM request header set by the internal MCP client and is trusted under exactly the same gate as the user name (getInternalToolCallRequest()): any other caller, an external OAuth MCP client for instance, gets null whatever it sends, so it can never choose the conversation its Tool executions are recorded in.
      Returns:
      the conversation id, or null when the call isn't the internal client's or carries no conversation
    • markdownToHtml

      public static String markdownToHtml(String markdown)
    • toDate

      public static Date toDate(String date)
    • formatDate

      public static String formatDate(Long time)
    • formatDate

      public static String formatDate(Date date)
    • getUserTimeZone

      public static TimeZone getUserTimeZone()