When deploying your MCP server, you may need the developer who is using your MCP server to provide constants or secrets. These can be API keys for your service or authentication tokens.

These constants are not something the LLM will be able to access or use in the prompt. It is the responsibility of the developer to provide the constants.

For example, if I develop an MCP server that is a weather service, the developer will need to give me the API key for the weather service, and the LLM will need to provide the city name.

Define a constant

To define a constant that your tool will access, you have to prefix a property with an underscore _ in your input schema.

import { tool } from "@mcplug/server";

export const myTool = tool(
  "This is the description of the tool. It is highly recommended to provide a detailed description of the tool."
).input(
  z
    .object({
      _WEATHER_API_KEY: z.string().describe("The API key for the weather service"),
      city: z.string().describe("The city name")
    })
    .handle(async ({ input }) => {
      const { _WEATHER_API_KEY, city } = input;

      const response = await fetch(
        `https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${_WEATHER_API_KEY}`
      );
      const data = await response.json();
      return data;
    })
);

In this example, the _WEATHER_API_KEY is a constant that will be provided by the developer and the city is the city name that the LLM will provide.

How constants are passed to the tool

Constants are passed to the tool when the developer initializes the mcplug client or by setting them in the plug dashboard.

In the code
import { mcplug } from "@mcplug/client";

const tools = await mcplug({
  token: MCPLUG_TOKEN,
  id: "plug_id",
  constants: {
    WEATHER_API_KEY: "1234567890"
  }
});
With a MCP host
{
  "mcpServers": {
    "mcplug": {
      "command": "npx",
      "args": ["-y", "@mcplug/client@latest", "YOUR_PLUG_ID"],
      "env": {
        "MCPLUG_TOKEN": "YOUR_MCPLUG_TOKEN",
        "WEATHER_API_KEY": "1234567890"
      }
    }
  }
}