Constants provide a secure method for passing sensitive values to MCP servers. These include API keys, authentication tokens, and configuration parameters that should remain hidden from the LLM and necessary for the MCP server to function.

If a tool requires a constant that is not configured, the tool will not be available to the LLM.

There is two ways of settings constant within a plug:

  • In the dashboard: In the “Constants” tabs, this will set some sort of default values for the plug.
  • In the client: When initializing the mcplug client, provide constants as part of the configuration. Provided constants will override the ones in the dashboard.

When using MCPlug inside a MCP host like Cursor or Claude. You can still set default values for the constants in the “Constants” tab of the MCP host but you can override them by passing constants in the “env” property.

Passing Constants to the Client

When initializing the mcplug client, provide constants as part of the configuration:

import { mcplug } from "@mcplug/client";

const tools = await mcplug({
  token: MCPLUG_TOKEN,
  id: "plug_id",
  constants: {
    WEATHER_API_KEY: "your-api-key-here",
    AUTH_TOKEN: "your-auth-token"
  }
});

How Constants Work

On the server side, constants are identified by an underscore prefix (_) in the tool’s input schema. When you provide these constants during client initialization, they’re automatically passed to the corresponding tools when called.

This approach keeps sensitive information secure, as the LLM has no access to these constants.

Weather API Example

Consider a weather MCP server requiring a paid API key to fetch weather data for specific cities:

  1. The MCP server developer creates a getWeather tool that requires a city name and the WEATHER_API_KEY constant
  2. You provide the API key during client initialization
const tools = await mcplug({
  token: MCPLUG_TOKEN,
  id: "plug_id",
  constants: { WEATHER_API_KEY: "your-api-key-here" }
});

await generateText({
  model: yourModel,
  prompt: "What is the weather in Tokyo?",
  tools
});

Gmail Integration Example

For Gmail tool integration:

  1. You must provide all necessary authentication credentials
  2. Mcplug doesn’t generate these credentials
  3. You’ll need to create your own OAuth2.0 client ID and client secret and store them securely
  4. Store the refresh token in your database as well

Once you have the required credentials, pass them to the client as constants:

const tools = await mcplug({
  token: MCPLUG_TOKEN,
  id: "plug_id",
  constants: {
    GMAIL_CLIENT_ID: "your-client-id-here",
    GMAIL_CLIENT_SECRET: "your-client-secret-here",
    GMAIL_REFRESH_TOKEN: "your-refresh-token-here"
  }
});