Class SecuredExampleClient

java.lang.Object
org.apache.juneau.examples.mcp.secured.SecuredExampleClient

public final class SecuredExampleClient extends Object
A guided walkthrough of calling SecuredExampleMcpServer, showing the secured request/response cycle a newcomer to MCP OAuth 2.1 needs to see: a rejected unauthenticated call (twice — once at the raw wire level, once through the real McpClient SDK), the full RFC 9728 → RFC 8414 discovery chain, a successful read-only call, a scoped step-up rejection, and finally a successful write once a token carrying the write scope has been acquired.

Run main with three arguments — the secured server's endpoint and the demo client id/secret — all three of which SecuredExampleServer.main(String[]) prints on startup (they cannot be hardcoded here: the demo client secret is freshly randomly generated on every server run, by design; see OfflineAuthorizationServer). Unlike an earlier version of this walkthrough, the token endpoint is no longer a fourth argument (M10): this client discovers it itself, the same way a real client would.

  • Method Details

    • main

      public static void main(String[] args) throws Exception
      Runs the walkthrough against a running SecuredExampleServer.
      Parameters:
      args - Three required arguments: endpoint, client id, client secret — copy these from SecuredExampleServer.main(String[])'s startup banner.
      Throws:
      Exception - If any step fails unexpectedly (a REJECTED call is expected and handled, not thrown).
    • run

      public static void run(String endpoint, String clientId, String clientSecret) throws Exception
      Executes each numbered step of the walkthrough.
      Parameters:
      endpoint - The secured MCP server's endpoint URL.
      clientId - The demo OAuth client id.
      clientSecret - The demo OAuth client secret.
      Throws:
      Exception - If an unexpected (non-auth-related) failure occurs.