@mcp1.ai/wrapper v1.0.0
MCP Wrapper
A simple Express server wrapper for MCP (Model Context Protocol) that forwards HTTP JSON-RPC requests to any command-line process following the JSON-RPC 2.0 protocol, and returns the responses to the client.
Features
- Receives JSON-RPC 2.0 requests via HTTP
- Forwards requests to the standard input of a specified command-line process
- Captures JSON-RPC responses from the standard output of the process
- Returns responses to the HTTP client
- Automatically restarts crashed processes
- Flexible configuration of target process and arguments
Installation
# Install globally
npm install -g @mcp1.ai/wrapper
# Or install as a project dependency
npm install --save @mcp1.ai/wrapper
Usage
Starting the Server
When installed globally, you can use the CLI directly:
# Default: uses npx -y @modelcontextprotocol/server-everything
mcp1-wrapper
# Specify a custom process and arguments
mcp1-wrapper <process> [arg1 arg2 ...]
# Example: using uvx mcp-server-fetch
mcp1-wrapper uvx mcp-server-fetch
# Or run a custom JavaScript script
mcp1-wrapper node my-custom-script.js
Or when used as a module in your project:
# Using the package in your project
node node_modules/.bin/mcp1-wrapper <process> [arg1 arg2 ...]
Sending Requests
Once the server is running, you can send JSON-RPC 2.0 requests via HTTP POST to http://localhost:3000
.
For example, using curl:
curl -X POST http://localhost:3000 \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "1",
"method": "initialize",
"params": {
"protocolVersion": "0.1.0",
"capabilities": {
"tools": true
},
"clientInfo": {
"name": "MCP Test Client",
"version": "1.0.0"
}
}
}'
JSON-RPC Request Examples
The package includes several predefined JSON-RPC request examples:
initialize.json
- Initialize the MCP servertools-list.json
- Get a list of available toolstools-call.json
- Call a specific tool
You can use these example files to quickly test the server:
# Use curl to send the tools-list request
curl -X POST http://localhost:3000 -H "Content-Type: application/json" -d @path/to/tools-list.json
Automatic Process Restart
The Express server monitors the child process status and automatically restarts the process if it unexpectedly exits. This ensures high availability of the service, even if the underlying process crashes.
The restart logic includes:
- Detecting process exit events
- Restarting the process after a short delay (to avoid crash loops)
- Handling process switching in request processing
Notes
- The server runs on port 3000 by default
- Request timeout is set to 30 seconds
- Process restart has a 1-second delay to avoid crash loops
- Child processes are automatically terminated when the server is shut down
License
MIT
7 months ago