@ezmcpz/transport-http
v0.1.1
Published
HTTP/HTTPS transport for EZMCPZ
Downloads
7
Maintainers
Readme
@ezmcpz/transport-http
HTTP/HTTPS transport for EZMCPZ. Enables remote access to your MCP server via HTTP.
Installation
npm install @ezmcpz/transport-http
# or
pnpm add @ezmcpz/transport-httpUsage
import { McpServer } from '@ezmcpz/core';
import { httpTransport } from '@ezmcpz/transport-http';
const server = new McpServer({
name: 'my-server',
version: '1.0.0'
});
// Add HTTP transport
server.use(httpTransport({
port: 3000,
host: '0.0.0.0'
}));
await server.start();Configuration
Basic Options
httpTransport({
port: 3000, // Port to listen on (default: 3000)
host: '0.0.0.0', // Host to bind to (default: '0.0.0.0')
healthCheck: true, // Enable /health endpoint (default: true)
metricsEndpoint: true, // Enable /metrics endpoint (default: true)
})HTTPS Support
httpTransport({
port: 3443,
https: {
cert: './path/to/cert.pem',
key: './path/to/key.pem'
}
})CORS Configuration
httpTransport({
port: 3000,
cors: {
origin: 'https://example.com',
credentials: true,
methods: ['GET', 'POST']
}
})Security Headers
httpTransport({
port: 3000,
helmet: {
contentSecurityPolicy: {
directives: {
defaultSrc: ["'self'"]
}
}
}
})Endpoints
POST /mcp
Main MCP endpoint for JSON-RPC 2.0 requests.
Request:
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "my_tool",
"arguments": { "arg": "value" }
}
}Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"content": [{
"type": "text",
"text": "result data"
}]
}
}GET /health
Health check endpoint.
Response:
{
"status": "healthy",
"name": "my-server",
"version": "1.0.0",
"uptime_seconds": 3600,
"requests": 1234,
"errors": 5
}GET /metrics
Prometheus-compatible metrics endpoint.
Response:
# HELP mcp_requests_total Total number of requests
# TYPE mcp_requests_total counter
mcp_requests_total 1234
# HELP mcp_errors_total Total number of errors
# TYPE mcp_errors_total counter
mcp_errors_total 5Complete Example
import { McpServer } from '@ezmcpz/core';
import { httpTransport } from '@ezmcpz/transport-http';
import { z } from 'zod';
const server = new McpServer({
name: 'api-server',
version: '1.0.0'
})
.tool('get_user', {
description: 'Get user by ID',
schema: z.object({
userId: z.string()
}),
handler: async (args) => {
return {
user: {
id: args.userId,
name: 'John Doe'
}
};
}
})
.use(httpTransport({
port: 3000,
cors: { origin: '*' },
healthCheck: true
}));
await server.start();
console.log('Server running on http://localhost:3000');Client Usage
# Call a tool
curl -X POST http://localhost:3000/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "get_user",
"arguments": { "userId": "123" }
}
}'
# Check health
curl http://localhost:3000/health
# Get metrics
curl http://localhost:3000/metricsLicense
MIT
