Package org.machanism.machai.mcp.server


package org.machanism.machai.mcp.server
Provides Machai's synchronous Model Context Protocol (MCP) server runtime, command-line launcher, and transport adapters. The package loads function definitions and publishes them as MCP tools and prompts; its stateless HTTP adapter also publishes resource-read handlers.

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

  • StdioMcpServer communicates through standard input and output, enables tools, prompts, and logging, and installs a JVM shutdown hook to close the built synchronous server.
  • HttpStatelessMcpServer exposes 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.
  • HttpStreamableMcpServer exposes 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