@postman/postman-mcp-server
Version:
Postman MCP Server — connect AI agents (Claude Code, Cursor, VS Code Copilot, Gemini CLI) to your Postman collections, specifications, and environments via Model Context Protocol (MCP)
34 lines (33 loc) • 1.19 kB
JavaScript
import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
export async function fetchCollection(collectionId, client) {
try {
const response = await client.get(`/collections/${encodeURIComponent(collectionId)}`);
const collectionJSON = response.collection || response;
return {
json: collectionJSON,
name: collectionJSON.info?.name || 'Unknown',
id: collectionId,
};
}
catch (error) {
throw new McpError(ErrorCode.InternalError, `Failed to fetch collection: ${collectionId}`, {
cause: error,
});
}
}
export async function fetchEnvironment(environmentId, client) {
try {
const response = await client.get(`/environments/${encodeURIComponent(environmentId)}`);
const environmentJSON = response.environment || response;
return {
json: environmentJSON,
name: environmentJSON.name || 'Unknown',
id: environmentId,
};
}
catch (error) {
throw new McpError(ErrorCode.InternalError, `Failed to fetch environment: ${environmentId}`, {
cause: error,
});
}
}