MyPostmanServer
A lightweight Node.js-based MCP server that exposes custom tools via HTTP and Server-Sent Events (SSE) for clients like Postman. It allows users to register tools with type-safe validation to establish bidirectional communication with MCP clients.
README
MCP Server - MyPostmanServer
A lightweight Model Context Protocol (MCP) server built with Node.js that exposes custom tools via HTTP/SSE for clients like Postman.
Overview
This project implements an MCP server that communicates with external clients using Server-Sent Events (SSE) over HTTP. It demonstrates how to:
- Create and register custom tools
- Validate input parameters with Zod
- Establish bidirectional communication with MCP clients
- Handle tool invocations and return formatted responses
Features
- Custom Tools: Defines a
greettool that clients can invoke - Type-Safe Validation: Uses Zod for runtime parameter validation
- SSE Transport: Full-duplex communication over HTTP without WebSockets
- Express Server: Lightweight HTTP server for handling client connections
Project Structure
.
├── index.js # Main MCP server implementation
├── package.json # Project dependencies and metadata
├── package-lock.json # Dependency lock file
├── .gitignore # Git ignore rules
└── README.md # This file
Prerequisites
- Node.js 16+ (with ES module support)
- npm or yarn for package management
Installation
- Clone the repository:
git clone https://github.com/gunjankum06/mcp.git
cd mcp
- Install dependencies:
npm install
Usage
Starting the Server
node index.js
You should see:
🚀 Server ready at http://localhost:3000/sse
Connecting a Client
MCP clients (like Postman, Claude, or custom applications) can connect to the server:
- Initiate Connection: Make a GET request to
http://localhost:3000/sse - Stream will open: The server establishes a persistent SSE connection
- Call Tools: Send requests to
http://localhost:3000/messageto invoke tools
Available Tools
greet
Greets a person by name.
Parameters:
name(string, required): The name of the person to greet
Response:
{
"content": [
{
"type": "text",
"text": "Hello {name}! MCP is running on your laptop."
}
]
}
Example:
POST http://localhost:3000/message
Content-Type: application/json
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "greet",
"arguments": {
"name": "John"
}
}
}
Architecture
Components
-
MCP Server (
McpServer)- Core component that manages tool definitions and processing
- Exposes tools to connected clients
- Handles tool invocations
-
SSE Transport (
SSEServerTransport)- Manages HTTP streaming connection with clients
- Handles bidirectional message exchange
- Routes
/messagecallbacks back to the server
-
Express API
/sse(GET): Endpoint for client connection initialization/message(POST): Endpoint for receiving client messages
Communication Flow
Client Server
| |
|---- GET /sse -------> |
| Create SSE Transport
| Connect MCP Server
|<----- SSE Stream ---- |
| |
|---- POST /message ------> |
| (tool call request) Process Request
| |
|<----- Response ------- |
| (tool response) |
Dependencies
- @modelcontextprotocol/sdk: MCP protocol implementation
- express: HTTP server framework
- zod: Schema validation library
Configuration
The server is configured in index.js with:
- Server Name:
MyPostmanServer - Server Version:
1.0.0 - Port:
3000
To modify these, edit the corresponding values in the code.
Error Handling
- Invalid tool parameters are caught by Zod schema validation
- Missing transport connections are handled gracefully in the
/messageroute - The server continues running even if individual tool calls fail
Development
Adding New Tools
To add a new tool, use the server.tool() method:
server.tool(
"toolName",
{ param1: z.string(), param2: z.number() },
async ({ param1, param2 }) => ({
content: [{ type: "text", text: `Result: ${param1} ${param2}` }]
})
);
Running in Development
For development with auto-reload, install nodemon:
npm install --save-dev nodemon
nodemon index.js
Troubleshooting
Port Already in Use
If port 3000 is already in use, modify the port number in index.js:
app.listen(YOUR_PORT, () => {
console.log(`🚀 Server ready at http://localhost:YOUR_PORT/sse`);
});
Client Connection Issues
- Ensure the server is running before connecting clients
- Check that the client is using the correct endpoint URL
- Verify that SSE is supported by your client
Tool Not Found
- Ensure tools are registered before the server starts listening
- Check tool names match exactly (case-sensitive)
- Verify input parameters match the defined schema
Resources
License
MIT
Author
gunjankum06 - GitHub user
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。