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
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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMcpServerComponentBase(@NotNull io.modelcontextprotocol.server.McpSyncServer mcpSyncServer) Constructs a newMcpServerComponentBasewith the specified MCP server. -
Method Summary
Modifier and TypeMethodDescriptionprotected StringlocalizeAttribute(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.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.github.thought2code.mcp.annotated.server.component.McpServerComponent
from, register
-
Field Details
-
mcpSyncServer
The MCP synchronous server instance wrapped in anImmutablewrapper for avoiding EI_EXPOSE_REP2 issue.
-
-
Constructor Details
-
McpServerComponentBase
public McpServerComponentBase(@NotNull @NotNull io.modelcontextprotocol.server.McpSyncServer mcpSyncServer) Constructs a newMcpServerComponentBasewith the specified MCP server.- Parameters:
mcpSyncServer- the MCP synchronous server instance to be used by this component
-
-
Method Details
-
localizeAttribute
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 localizedefaultValue- 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:
-