Class ExampleServer

java.lang.Object
org.apache.juneau.examples.mcp.ExampleServer
All Implemented Interfaces:
AutoCloseable

public final class ExampleServer extends Object implements AutoCloseable
Boots ExampleMcpServer on an embedded Jetty server.

Run main to start the server on a fixed port (default 10000, or pass a port as the first argument) and leave it running so you can point ExampleClient (or any MCP client) at it. The in-process end-to-end test uses start(0) to boot on an OS-assigned ephemeral port instead.

The wiring mirrors Juneau's own test fixture: a Jetty Server plus the ExampleMcpServer servlet are placed in a BasicBeanStore, and JettyConfiguration (added via Microservice.Builder.configurations(Class...)) auto-mounts the @Rest servlet at "/" and drives the server lifecycle. Because the Server is supplied as a bean, we control the listen port directly — no jetty.xml required.

  • Field Details

  • Method Details

    • start

      public static ExampleServer start(int port) throws Exception
      Starts the example MCP server.
      Parameters:
      port - The TCP port to listen on, or 0 to let the OS assign an ephemeral port.
      Returns:
      A running server handle. Close it (or call close()) to stop.
      Throws:
      Exception - If the server fails to start.
    • getRootUrl

      public URI getRootUrl()
      Returns the root URL the server is listening on (e.g. http://localhost:10000/).
      Returns:
      The root URL. Never null.
    • close

      public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception
    • main

      public static void main(String[] args) throws Exception
      Runs the server until the process is killed.
      Parameters:
      args - Optional single argument: the port to listen on (defaults to DEFAULT_PORT).
      Throws:
      Exception - If the server fails to start.