Package org.apache.juneau.examples.mcp
Class ExampleServer
java.lang.Object
org.apache.juneau.examples.mcp.ExampleServer
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault listen port used bymain(String[])when none is supplied. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Returns the root URL the server is listening on (e.g.static voidRuns the server until the process is killed.static ExampleServerstart(int port) Starts the example MCP server.
-
Field Details
-
DEFAULT_PORT
Default listen port used bymain(String[])when none is supplied.- See Also:
-
-
Method Details
-
start
Starts the example MCP server. -
getRootUrl
Returns the root URL the server is listening on (e.g.http://localhost:10000/).- Returns:
- The root URL. Never
null .
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
main
Runs the server until the process is killed.- Parameters:
args- Optional single argument: the port to listen on (defaults toDEFAULT_PORT).- Throws:
Exception- If the server fails to start.
-