#
tokens: 2551/50000 5/5 files
lines: off (toggle) GitHub
raw markdown copy
# Directory Structure

```
├── .gitignore
├── LICENSE
├── package-lock.json
├── package.json
├── README.md
├── src
│   └── index.ts
└── tsconfig.json
```

# Files

--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------

```
node_modules/
build/
*.log
.env*
```

--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------

```markdown
# Postman Tool Generation MCP Server

An MCP server that generates AI agent tools from Postman collections and requests. This server integrates with the Postman API to convert API endpoints into type-safe code that can be used with various AI frameworks.

<a href="https://www.producthunt.com/posts/mcp-server-for-postman-ai-tool-generator?embed=true&utm_source=badge-featured&utm_medium=badge&utm_souce=badge-mcp&#0045;server&#0045;for&#0045;postman&#0045;ai&#0045;tool&#0045;generator" target="_blank"><img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=824239&theme=dark&t=1737988039824" alt="MCP&#0032;Server&#0032;for&#0032;Postman&#0032;AI&#0032;Tool&#0032;Generator - Convert&#0032;Postman&#0032;APIs&#0032;into&#0032;type&#0045;safe&#0032;AI&#0032;tools&#0032;seamlessly&#0046; | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>

Model Context Protocol (MCP) is a [new, standardized protocol](https://modelcontextprotocol.io/introduction) for managing context between large language models (LLMs) and external systems. In this repository, we provide an installer as well as an MCP Server for [Postman Tool Generation API](https://api.getpostman.com/postbot/generations/tool).

This lets you use [Claude Desktop](https://claude.ai/download), or any MCP Client like [Cline](https://github.com/cline/cline), to use natural language to accomplish things on your Postman account, e.g.:

* `Create an AI tool for:
collectionID: 12345-abcde
requestID: 67890-fghij
typescript
openai`

<a href="https://glama.ai/mcp/servers/36hxinm405"><img width="380" height="200" src="https://glama.ai/mcp/servers/36hxinm405/badge" alt="Postman Tool Generation Server MCP server" /></a>

## Features

- Generate TypeScript/JavaScript code from Postman collections
- Support for multiple AI frameworks (OpenAI, Mistral, Gemini, Anthropic, LangChain, AutoGen)
- Type-safe code generation
- Error handling and response validation

## Demo

<div align="center">
  <a href="https://youtu.be/G1O9ECYRk1M" alt="Demonstrating the newly-released MCP server to explore Postman Tool Generation API">
    <img src="https://img.youtube.com/vi/G1O9ECYRk1M/maxresdefault.jpg" alt="Demonstrating the newly-released MCP server to explore Postman Tool Generation API" width="600"/>
  </a>
</div>

## Setup

1. Install dependencies:
```bash
npm install
```

2. Build the server:
```bash
npm run build
```

3. Configure the MCP settings by adding the following to your Claude settings file (`cline_mcp_settings.json`):
```json
{
  "mcpServers": {
    "postman-ai-tools": {
      "command": "node",
      "args": [
        "/path/to/postman-tool-generation-server/build/index.js"
      ],
      "env": {
        "POSTMAN_API_KEY": "your-postman-api-key"
      },
      "disabled": false,
      "autoApprove": []
    }
  }
}
```

## Usage

The server provides a single tool called `generate_ai_tool` with the following parameters:

```typescript
{
  collectionId: string;    // The Public API Network collection ID
  requestId: string;       // The public request ID
  language: "javascript" | "typescript";  // Programming language to use
  agentFramework: "openai" | "mistral" | "gemini" | "anthropic" | "langchain" | "autogen";  // AI framework
}
```

### Example

```typescript
// Using the tool through MCP
const result = await use_mcp_tool({
  server_name: "postman-ai-tools",
  tool_name: "generate_ai_tool",
  arguments: {
    collectionId: "your-collection-id",
    requestId: "your-request-id",
    language: "typescript",
    agentFramework: "openai"
  }
});
```

### Generated Code

The tool generates type-safe code that includes:

- Type definitions for request/response
- Error handling
- API integration
- OpenAI function definitions
- Documentation and examples

## Development

1. Install dependencies:
```bash
npm install
```

2. Make changes to `src/index.ts`

3. Build the server:
```bash
npm run build
```

4. Restart the Claude app to load the updated server

## Environment Variables

- `POSTMAN_API_KEY`: Your Postman API key (required)

## Error Handling

The server includes comprehensive error handling for:
- Invalid parameters
- API failures
- JSON parsing errors
- Network issues

Error responses include detailed messages to help diagnose issues.

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

MIT License

```

--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------

```json
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "Node16",
    "moduleResolution": "Node16",
    "outDir": "./build",
    "rootDir": "./src",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules"]
}

```

--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------

```json
{
  "name": "postman-tools-server",
  "version": "0.1.0",
  "description": "A Model Context Protocol server",
  "private": true,
  "type": "module",
  "bin": {
    "postman-tools-server": "./build/index.js"
  },
  "files": [
    "build"
  ],
  "scripts": {
    "build": "tsc && node -e \"require('fs').chmodSync('build/index.js', '755')\"",
    "prepare": "npm run build",
    "watch": "tsc --watch",
    "inspector": "npx @modelcontextprotocol/inspector build/index.js"
  },
  "dependencies": {
    "@modelcontextprotocol/sdk": "0.6.0",
    "axios": "^1.7.9"
  },
  "devDependencies": {
    "@types/node": "^20.11.24",
    "typescript": "^5.3.3"
  }
}

```

--------------------------------------------------------------------------------
/src/index.ts:
--------------------------------------------------------------------------------

```typescript
#!/usr/bin/env node
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import {
  CallToolRequestSchema,
  ErrorCode,
  ListToolsRequestSchema,
  McpError,
} from '@modelcontextprotocol/sdk/types.js';
import axios from 'axios';

interface GenerateToolConfig {
  collectionId: string;
  requestId: string;
  config: {
    language: 'javascript' | 'typescript';
    agentFramework: 'openai' | 'mistral' | 'gemini' | 'anthropic' | 'langchain' | 'autogen';
  };
}

class PostmanToolsServer {
  private server: Server;
  private axiosInstance;
  private API_KEY: string;

  constructor() {
    const apiKey = process.env.POSTMAN_API_KEY;
    if (!apiKey) {
      throw new Error('POSTMAN_API_KEY environment variable is required');
    }
    this.API_KEY = apiKey;

    this.server = new Server(
      {
        name: 'postman-tools-server',
        version: '0.1.0',
      },
      {
        capabilities: {
          tools: {},
        },
      }
    );

    this.axiosInstance = axios.create({
      baseURL: 'https://api.getpostman.com',
      headers: {
        'X-API-Key': this.API_KEY,
        'Content-Type': 'application/json',
      },
    });

    this.setupToolHandlers();
    
    this.server.onerror = (error) => console.error('[MCP Error]', error);
    process.on('SIGINT', async () => {
      await this.server.close();
      process.exit(0);
    });
  }

  private setupToolHandlers() {
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: [
        {
          name: 'generate_ai_tool',
          description: 'Generate code for an AI agent tool using a Postman collection and request',
          inputSchema: {
            type: 'object',
            properties: {
              collectionId: {
                type: 'string',
                description: 'The Public API Network collection ID',
              },
              requestId: {
                type: 'string',
                description: 'The public request ID',
              },
              language: {
                type: 'string',
                enum: ['javascript', 'typescript'],
                description: 'Programming language to use',
              },
              agentFramework: {
                type: 'string',
                enum: ['openai', 'mistral', 'gemini', 'anthropic', 'langchain', 'autogen'],
                description: 'AI agent framework to use',
              },
            },
            required: ['collectionId', 'requestId', 'language', 'agentFramework'],
          },
        },
      ],
    }));

    this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
      switch (request.params.name) {
        case 'generate_ai_tool':
          return this.handleGenerateTool(request.params.arguments);
        default:
          throw new McpError(
            ErrorCode.MethodNotFound,
            `Unknown tool: ${request.params.name}`
          );
      }
    });
  }

  private async handleGenerateTool(args: any): Promise<any> {
    if (!args?.collectionId || !args?.requestId || !args?.language || !args?.agentFramework) {
      throw new McpError(
        ErrorCode.InvalidParams,
        'Missing required parameters: collectionId, requestId, language, agentFramework'
      );
    }

    try {
      const response = await this.axiosInstance.post('/postbot/generations/tool', {
        collectionId: args.collectionId,
        requestId: args.requestId,
        config: {
          language: args.language,
          agentFramework: args.agentFramework,
        },
      });

      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(response.data, null, 2),
          },
        ],
      };
    } catch (error) {
      if (axios.isAxiosError(error)) {
        return {
          content: [
            {
              type: 'text',
              text: `Error generating tool: ${error.response?.data?.error || error.message}`,
            },
          ],
          isError: true,
        };
      }
      throw error;
    }
  }

  async run() {
    const transport = new StdioServerTransport();
    await this.server.connect(transport);
    console.error('Postman Tools MCP server running on stdio');
  }
}

const server = new PostmanToolsServer();
server.run().catch(console.error);

```