Package org.machanism.machai.mcp.server
The package has three layers:
AbstractMcpServerholds the common project-directory and configuration behavior and defines the tool-registration and startup lifecycle.GenericGenaiAdapterand its prompt-aware subclass translate MachaiToolFunctionandParamDescriptordefinitions into MCP tool schemas, invocation handlers, prompt definitions, and prompt results. The stateless HTTP adapter also translates resource definitions into resource read handlers.StdioMcpServer,HttpStatelessMcpServer, andHttpStreamableMcpServersupply STDIO, stateless HTTP, and streamable HTTP transports respectively.AbstractHttpMcpServercentralizes the Jetty connector, servlet, thread-pool, port, and startup setup shared by the HTTP implementations.
Tool and prompt execution
The server launcher discovers function-based tools through
FunctionToolsLoader. The optional
enabledTools configuration property limits registration; its values
may be separated by spaces, commas, semicolons, or other whitespace. Tool
parameters are represented as JSON Schema, required arguments are validated
by the MCP client against that schema, and function results are serialized
into MCP text content. Invocation failures are returned as error tool
results. Prompt arguments are exposed as MCP prompt arguments; string,
collection, and other serialized function results become prompt messages.
Streamable exchanges additionally make their session identifier available to
functions through the tool-function session parameter. Stateless exchanges
do not have a session identifier.
Transport behavior
StdioMcpServercreates a single-session synchronous MCP server over standard input and output, with tools, prompts, and logging enabled.HttpStatelessMcpServerserves synchronous MCP requests through a Jetty servlet without retaining server-side session state. It advertises tools, prompts, and resources; resource functions receive the requested URI, configured project directory, and configurator.HttpStreamableMcpServerserves synchronous streamable HTTP requests through Jetty and preserves the exchange session context for tool and prompt calls.
HTTP startup errors are wrapped in McpServerStartupException.
Implementations report the Machai MCP homepage and icon metadata where the
transport supports server implementation metadata.
Starting the server
McpServer.main(String[]) is the command-line entry point. Use
-n/--name and -v/--version for server
metadata, -d/--projectDir for the project directory, and
-c/--config for an explicit properties file. Without an
explicit configuration path, McpServer attempts
McpServer.MCP_CONFIG_FILE_NAME (mcp.properties) and tolerates
that default file being absent. Without -p/--port, it starts
StdioMcpServer; with a port, it starts
HttpStatelessMcpServer, or HttpStreamableMcpServer when
-s/--session is also supplied.
- Since:
- 1.2.0
- Author:
- Viktor Tovstyi
-
ClassDescriptionAbstract base class for HTTP-based MCP (Model Context Protocol) server implementations.Base implementation of a Model Context Protocol (MCP) server.Interface for building tool and tool specification objects for MCP servers.AbstractPromptGenaiAdapter<E,
S, P> Common prompt-registration support for MCP GenAI adapters.GenericGenaiAdapter<E,S> A generic adapter for integrating GenAI tools with different server implementations.Adapts Machai tools, prompts, and resources to the stateless HTTP MCP transport.HttpStatelessMcpServer sets up and runs a Model Context Protocol (MCP) server that listens for HTTP requests on a specified port.Adapts Machai tools and prompts to the streamable HTTP MCP transport.Configures and runs a streamable HTTP Model Context Protocol (MCP) server that listens for HTTP requests on a specified port.Entry point for starting the MCP (Model Context Protocol) server.Indicates that an MCP server could not be started.Adapts Machai tools and prompts to the synchronous STDIO MCP transport.StdioMcpServer sets up and runs a Model Context Protocol (MCP) server that communicates via standard input and output (STDIO).