Skip to main content
Glama
runninghare

REST-to-Postman MCP

by runninghare

rest_to_postman_env

Synchronize REST application environment variables with Postman by creating or updating Postman environments, automatically marking sensitive variables as secrets.

Instructions

Creates or updates a Postman environment with the provided environment variables. This tool helps synchronize your REST application's environment configuration with Postman. It supports both creating new environments and updating existing ones in your Postman workspace. Environment variables related to sensitive data (containing 'token' in their names) are automatically marked as secrets. Here's an example:

{ "envName": "REST Environment", "envVars": { "API_URL": "https://api.example.com", "API_TOKEN": "secret-token-1" } }

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
envNameYesThe name of the Postman environment to create or update
envVarsYesA record of environment variables to be added to the Postman environment. Format: { [key: string]: string }

Implementation Reference

  • Core handler function that implements the tool logic: transforms input envVars into Postman EnvValue format (auto-detects secrets), checks for existing environment, and POST/PUT to Postman API to create/update.
    export async function pushEnvironment(environmentName: string, envVars: Record<string, string>, postmanApiKey?: string, workspaceId?: string): Promise<void> {
      try {
        const apiKey = postmanApiKey || process.env.POSTMAN_API_KEY;
        const activeWorkspaceId = workspaceId || process.env.POSTMAN_ACTIVE_WORKSPACE_ID;
    
        // Read all environment variables except POSTMAN_API_KEY and POSTMAN_ACTIVE_WORKSPACE_ID
        const envValues: EnvValue[] = [];
        
        for (const [key, value] of Object.entries(envVars)) {
            envValues.push({
                key,
                value,
                enabled: true,
                type: key.includes('token') ? 'secret' : 'default'
            });
        }
    
        // Check if environment already exists
        const workspaceResponse = await axios({
          method: 'get',
          url: `https://api.getpostman.com/workspaces/${activeWorkspaceId}`,
          headers: {
            'X-Api-Key': apiKey
          }
        });
        
        const workspaceData = workspaceResponse.data as PostmanWorkspaceResponse;
        const existingEnvironment = workspaceData.workspace.environments?.find(
          env => env.name === environmentName
        );
        
        // Prepare the environment data
        const environmentData = {
          environment: {
            name: environmentName,
            values: envValues
          }
        };
    
        let response;
        if (existingEnvironment) {
          response = await axios({
            method: 'put',
            url: `https://api.getpostman.com/environments/${existingEnvironment.id}`,
            headers: {
              'X-Api-Key': apiKey,
              'Content-Type': 'application/json'
            },
            data: environmentData
          });
        } else {
          response = await axios({
            method: 'post',
            url: 'https://api.getpostman.com/environments',
            headers: {
              'X-Api-Key': apiKey,
              'Content-Type': 'application/json'
            },
            data: {
              ...environmentData,
              workspace: activeWorkspaceId
            }
          });
        }
        
      } catch (error) {
        throw error;
      }
    }
  • src/mcp.ts:82-102 (registration)
    Tool registration in the tools list, including name, description, and JSON input schema for MCP listTools.
    {
      "name": "rest_to_postman_env",
      "description": "Creates or updates a Postman environment with the provided environment variables. This tool helps synchronize your REST application's environment configuration with Postman. It supports both creating new environments and updating existing ones in your Postman workspace. Environment variables related to sensitive data (containing 'token' in their names) are automatically marked as secrets. Here's an example: \n\n" + envExample,
      "inputSchema": {
        "type": "object",
        "properties": {
          "envName": {
            "type": "string",
            "description": "The name of the Postman environment to create or update"
          },
          "envVars": {
            "type": "object",
            "description": "A record of environment variables to be added to the Postman environment. Format: { [key: string]: string }",
            "additionalProperties": {
              "type": "string"
            }
          }
        },
        "required": ["envName", "envVars"]
      }
    },
  • MCP callTool request handler specific branch that extracts arguments and invokes the pushEnvironment implementation.
    if (request.params.name === "rest_to_postman_env") {
      if (!request.params.arguments) {
        throw new McpError(ErrorCode.InvalidParams, "Missing arguments");
      }
      const { envName, envVars } = request.params.arguments as { envName: string; envVars: Record<string, string> };
      await pushEnvironment(envName, envVars, process.env.POSTMAN_API_KEY, process.env.POSTMAN_ACTIVE_WORKSPACE_ID);
      return {
        content: [{
          type: "text",
          text: `Successfully created/updated Postman environment: ${envName}`
        }]
      };
  • TypeScript interface defining the structure of environment variables used by pushEnvironment.
    export interface EnvValue {
      key: string;
      value: string;
      enabled: boolean;
      type: string;
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It reveals important behavioral traits: support for both create and update operations, automatic secret marking for variables containing 'token', and workspace context. However, it doesn't disclose authentication requirements, rate limits, error handling, or whether the operation is idempotent, leaving significant gaps for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded with the core functionality in the first sentence. The example is helpful but could be more concise. The text is well-structured with clear sentences, though the example takes up significant space relative to the explanatory content.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a mutation tool with no annotations and no output schema, the description provides adequate basic information about what the tool does and includes a helpful example. However, it lacks important contextual details: no information about return values, error conditions, authentication requirements, or workspace selection logic. The example helps but doesn't compensate for these missing elements.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already fully documents both parameters. The description adds minimal value beyond the schema: it provides an example showing the expected JSON structure and mentions the secret-marking behavior for 'token' variables, but doesn't explain parameter semantics beyond what's in the schema descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verbs ('creates or updates') and resource ('Postman environment with environment variables'). It distinguishes from the sibling tool 'rest_to_postman_collection' by focusing on environments rather than collections, providing clear differentiation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context ('helps synchronize your REST application's environment configuration with Postman') but doesn't explicitly state when to use this tool versus alternatives. No guidance is provided on prerequisites, error conditions, or specific scenarios where this tool is preferred over manual configuration or other tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/runninghare/rest-to-postman'

If you have feedback or need assistance with the MCP directory API, please join our Discord server