Package org.machanism.machai.mcp.server
Class AbstractMcpServer
java.lang.Object
org.machanism.machai.mcp.server.AbstractMcpServer
- Direct Known Subclasses:
AbstractHttpMcpServer,StdioMcpServer
Base implementation of a Model Context Protocol (MCP) server.
This class provides common hooks, constants, and working directory management for custom MCP server implementations designed to interact with generative-AI models.
- Since:
- 1.2.0
- Author:
- Viktor Tovstyi
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static interfaceInterface for building tool and tool specification objects for MCP servers. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected String[]getEnabledTools(Configurator config) Reads the optional enabled-tool list from the server configuration.Returns the configured project directory.voidsetProjectDir(File projectDir) Sets the project directory used by server tools.(package private) abstract voidstart()Starts the MCP server.(package private) abstract voidtools(Configurator config) Registers or defines the available tools for this MCP server.
-
Field Details
-
ENABLED_TOOLS_PARAM_NAME
- See Also:
-
MACHAI_MACHANISM_HOMEPAGE
The homepage URL for the Machai MCP server.- See Also:
-
MACHAI_MACHANISM_ICON
The icon URL for the Machai MCP server.- See Also:
-
projectDir
-
-
Constructor Details
-
AbstractMcpServer
AbstractMcpServer()Constructs a newAbstractMcpServer.
-
-
Method Details
-
getEnabledTools
Reads the optional enabled-tool list from the server configuration. Values may be separated by spaces, commas, semicolons, or whitespace.- Parameters:
config- configuration source; expected to be non-null- Returns:
- enabled tool names, or
nullwhen no restriction is configured
-
tools
Registers or defines the available tools for this MCP server.Subclasses must implement this method to provide tool registration logic.
-
start
Starts the MCP server.Subclasses must implement this method to provide server startup logic.
- Throws:
McpServerStartupException- if the server fails to start
-
setProjectDir
Sets the project directory used by server tools.- Parameters:
projectDir- project directory to use, ornullwhen request-specific
-
getProjectDir
Returns the configured project directory.- Returns:
- project directory, or
nullwhen request-specific
-