Class McpServerComponentBase<T>

java.lang.Object
com.github.thought2code.mcp.annotated.server.component.McpServerComponentBase<T>
Type Parameters:
T - the type of component this base class creates (e.g., McpSchema.Resource, McpSchema.Prompt, McpSchema.Tool)
All Implemented Interfaces:
McpServerComponent<T>
Direct Known Subclasses:
McpServerPrompt, McpServerResource, McpServerTool

public abstract class McpServerComponentBase<T> extends Object implements McpServerComponent<T>
Abstract base class that provides common functionality for MCP server components (resource/prompt/tool).

This class implements the McpServerComponent interface and provides shared functionality for all MCP server components, including i18n support and server instance management. It serves as a foundation for concrete component implementations that handle specific types of MCP components.

The class provides:

  • Access to the MCP synchronous server instance through a supplier
  • I18n support through resource bundle handling
  • Attribute localization with fallback to default values
Author:
codeboyzhou
See Also:
  • Field Details

    • mcpSyncServer

      protected final Immutable<io.modelcontextprotocol.server.McpSyncServer> mcpSyncServer
      The MCP synchronous server instance wrapped in an Immutable wrapper for avoiding EI_EXPOSE_REP2 issue.
  • Constructor Details

    • McpServerComponentBase

      public McpServerComponentBase(@NotNull @NotNull io.modelcontextprotocol.server.McpSyncServer mcpSyncServer)
      Constructs a new McpServerComponentBase with the specified MCP server.
      Parameters:
      mcpSyncServer - the MCP synchronous server instance to be used by this component
  • Method Details

    • localizeAttribute

      protected String localizeAttribute(String i18nKey, String defaultValue)
      Localizes an attribute with the specified i18n key using the resource bundle, or returns the default value if the key is not found in the bundle.

      This method attempts to retrieve a localized string from the resource bundle using the provided key. If the key is not found or the bundle is unavailable, it falls back to either the key itself (if it contains a non-blank value) or the specified default value.

      Parameters:
      i18nKey - the i18n key of the attribute to localize
      defaultValue - the default value to return if the i18n key is not found in the bundle
      Returns:
      the localized value of the attribute, or the default value if the i18n key is not found
      See Also: