Package org.machanism.machai.mcp.server
AbstractMcpServer is the common base for all transports. It stores
the optional project directory passed to functions and filters registered
tools using the optional enabledTools configuration property. Each
concrete server uses FunctionToolsLoader to discover function
definitions and an adapter to create transport-specific MCP
specifications.
Tool and prompt adapters
GenericGenaiAdapter converts ParamDescriptor instances into
JSON Schema, registers tool handlers, and invokes each ToolFunction
with request arguments, the configured project directory, and the active
configurator. When a handler receives an
McpSyncServerExchange, it also supplies the exchange session
identifier as a function argument. AbstractPromptGenaiAdapter
performs the corresponding prompt registration and converts function
results into MCP prompt messages. The concrete
StdioGenaiAdapter, HttpStreamableGenericGenaiAdapter, and
HttpStatelessGenericGenaiAdapter classes bind those registrations to
STDIO, streamable HTTP, and stateless HTTP respectively; the stateless
adapter additionally registers resource handlers.
Server transports
StdioMcpServercommunicates through standard input and output, enables tools, prompts, and logging, and installs a JVM shutdown hook to close the built synchronous server.HttpStatelessMcpServerexposes stateless synchronous MCP requests through a Jetty servlet and supports tools, prompts, and resources. Resource functions receive the project directory, configurator, and requested resource URI.HttpStreamableMcpServerexposes streamable synchronous MCP requests through a Jetty servlet and supports tools and prompts.
AbstractHttpMcpServer configures the Jetty connector and selected
transport servlet. HTTP startup failures are wrapped in
McpServerStartupException.
Starting a server
McpServer is the command-line entry point. Use -n or
--name, -v or --version, and -d or
--projectDir to set server metadata and the function project
directory. Use -c or --config to select a properties file;
when omitted, mcp.properties is attempted. Without -p or
--port, the launcher starts StdioMcpServer. With a port, it
starts HttpStatelessMcpServer, or starts
HttpStreamableMcpServer when -s or --session is
specified.
- 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).