Class McpToolSchemaGenerator

java.lang.Object
org.mockserver.mock.mcp.McpToolSchemaGenerator

public class McpToolSchemaGenerator extends Object
Generates Model Context Protocol tool definitions from the current mock expectations, so an AI agent can discover and (via an MCP client) call the mocked endpoints as tools. Each response expectation with a concrete request matcher becomes one tool: the tool name is derived from the method and path, the inputSchema exposes the query parameters and (when present) a request body, and a _mockserver annotation records the target method/path/expectation id so a caller can route an invocation back to the mock.

Expectations whose method or path is a notted ("match anything except") matcher are skipped, as are non-response actions — neither has a meaningful single-tool representation.

  • Constructor Details

    • McpToolSchemaGenerator

      public McpToolSchemaGenerator()
  • Method Details

    • generate

      public com.fasterxml.jackson.databind.node.ArrayNode generate(List<Expectation> expectations)
      Parameters:
      expectations - the expectations to expose (typically the active expectations)
      Returns:
      an array of MCP tool definition objects (name, description, inputSchema, _mockserver)