getEnvironments
Retrieve details for all environments in a Postman workspace, including variables and values. Specify a workspace ID to filter results.
Instructions
Gets information about all of your environments.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| workspace | No | The workspace's ID. |
Implementation Reference
- src/tools/getEnvironments.ts:1-47 (handler)The main implementation file for the getEnvironments tool. Exports the method name ('getEnvironments'), description, Zod schema (with optional 'workspace' param), annotations, and the async handler function that calls GET /environments via the PostmanAPIClient.
import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getEnvironments'; export const description = 'Gets information about all of your [environments](https://learning.postman.com/docs/sending-requests/managing-environments/).'; export const parameters = z.object({ workspace: z.string().describe("The workspace's ID.").optional(), }); export const annotations = { title: 'Gets information about all of your [environments](https://learning.postman.com/docs/sending-requests/managing-environments/).', readOnlyHint: true, destructiveHint: false, idempotentHint: true, }; export async function handler( args: z.infer<typeof parameters>, extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise<CallToolResult> { try { const endpoint = `/environments`; const query = new URLSearchParams(); if (args.workspace !== undefined) query.set('workspace', String(args.workspace)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; const options: any = { headers: extra.headers, }; const result = await extra.client.get(url, options); return { content: [ { type: 'text', text: `${typeof result === 'string' ? result : JSON.stringify(result, null, 2)}`, }, ], }; } catch (e: unknown) { if (e instanceof McpError) { throw e; } throw asMcpError(e); } } - src/tools/getEnvironments.ts:9-11 (schema)Zod schema for the getEnvironments tool: accepts an optional 'workspace' string parameter describing the workspace ID.
export const parameters = z.object({ workspace: z.string().describe("The workspace's ID.").optional(), }); - src/enabledResources.ts:75-75 (registration)Registration of 'getEnvironments' in the 'full' resource list (line 75).
'getEnvironments', - src/enabledResources.ts:177-177 (registration)Registration of 'getEnvironments' in the 'minimal' resource list (line 177).
'getEnvironments', - src/enabledResources.ts:218-218 (registration)Registration of 'getEnvironments' in the 'code' resource list (line 218).
'getEnvironments',