Protect an MCP server

@ploba/sdk/mcp wraps your MCP server so every tool call needs a valid Ploba licence key. Listing tools stays public.

Wrap your server

TypeScript
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { withPlobaAuth } from "@ploba/sdk/mcp";

const server = new Server({ name: "my-server", version: "1.0.0" }, { capabilities: { tools: {} } });

// Tool calls now need a valid PLOBA_LICENSE_KEY in the user's environment.
// Your secret key comes from PLOBA_SECRET_KEY on your server (or pass secretKey).
withPlobaAuth(server, { productId: "<your product slug or id>" });

From then on, each tool call reads PLOBA_LICENSE_KEY from the environment of the client running your server. A missing or invalid key fails the call with an Unauthorized error; a valid one runs your handler.

Options

productIdstringrequired
Your product's slug or ID on Ploba. Licence keys for your other products are refused.
secretKeystring
Your Ploba secret key, sent with each check. Defaults to PLOBA_SECRET_KEY from your server’s environment.
apiUrlstring
The Ploba API base URL. Defaults to https://api.ploba.app.
cacheTtlMsnumber
How long a successful check is cached in memory. Defaults to 900000 (15 minutes).

What your users do

Users add their licence key to the server’s environment in their MCP client config:

JSON
{
  "mcpServers": {
    "my-server": {
      "command": "npx",
      "args": ["-y", "my-server"],
      "env": { "PLOBA_LICENSE_KEY": "<their licence key>" }
    }
  }
}

Prove a hosted server is yours

For a remote server, mount plobaVerificationHandler on a path of your choice and give that URL to Ploba. Ploba sends a challenge; the handler answers with an HMAC-SHA256 of it, signed with your server secret, which proves you control the server.

Express
import { plobaVerificationHandler } from "@ploba/sdk";

// Any path you like, for example:
app.post("/ploba/verify", plobaVerificationHandler(process.env.PLOBA_SERVER_SECRET!));

Last updated Oct 9, 2026Report a problem with this page