A general-purpose, streaming-friendly MCP (Model Context Protocol) client for Node.js.
Content-Length headers and uses a robust JSON object scannerThis package is designed to be a generic, open-source MCP client.
It works with any MCP-compliant server implementation, including
mcp-server-general – a production-ready, plugin-driven MCP server:
https://github.com/daporun/mcp-server-general
Content-Lengthnpm install -g mcp-client-general
# or
npm install mcp-client-general --save-dev
mcp run "node dist/server.js"
echo '{"jsonrpc":"2.0","id":1,"method":"providers.list"}' \
| mcp run "node ../mcp-server-general/dist/server.js"
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"providers": [
{
"provider": "openai",
"model": "gpt-4o-mini"
}
]
}
}
printf '%s\n%s\n' \
'{"jsonrpc":"2.0","id":1,"method":"providers.list"}' \
'{"jsonrpc":"2.0","id":2,"method":"steps.list"}' \
| mcp run "node ../mcp-server-general/dist/server.js"
{
"jsonrpc": "2.0",
"id": 1,
"result": { "providers": [ /* ... */ ] }
}
{
"jsonrpc": "2.0",
"id": 2,
"result": { "steps": [ /* ... */ ] }
}
echo '{"jsonrpc":"2.0","id":3,"method":"scoring.schema"}' \
| mcp run "node ../mcp-server-general/dist/server.js"
{
"jsonrpc": "2.0",
"id": 3,
"error": {
"code": -32601,
"message": "Method not found: scoring.schema"
}
}
This example shows how to launch and interact with an MCP server programmatically.
import { MCPProcess } from "mcp-client-general";
import type { JSONRPCRequest } from "mcp-client-general/jsonrpc";
async function main() {
const proc = new MCPProcess({
command: "node",
args: ["../mcp-server-general/dist/server.js"],
startupTimeoutMs: 4000,
shutdownTimeoutMs: 3000
});
proc.on("stderr", (msg) => process.stderr.write(String(msg)));
await proc.start();
const req: JSONRPCRequest = {
jsonrpc: "2.0",
id: 1,
method: "providers.list",
params: {}
};
const response = await proc.send(req);
console.log(JSON.stringify(response, null, 2));
await proc.close();
}
main().catch((err) => {
console.error(err);
process.exit(1);
});
To quickly try this client with a production-ready MCP server, see:
The first valid JSON object received from stdout is treated as the handshake.
If the server delays or prints logs first, the client still proceeds safely.
Many servers emit:
Content-Length: 2888\r\n\r\n{ ... JSON ... }
But Content-Length is often wrong or mixed with logs.
This client instead:
{{ / }Works even with imperfect/experimental MCP servers.
Map<id, PendingEntry>Enable verbose debugging:
MCP_DEBUG=1 mcp run "node dist/server.js"
Shows:
MIT – see LICENSE.
No reviews yet. Be the first to rate this tool.
Sign in to leave a review.