{"id":32722860,"url":"https://github.com/gnana997/node-stdio-jsonrpc","last_synced_at":"2026-05-17T19:37:42.105Z","repository":{"id":322106328,"uuid":"1088220107","full_name":"gnana997/node-stdio-jsonrpc","owner":"gnana997","description":"TypeScript JSON-RPC 2.0 client over stdio (child process) - clean and developer-friendly","archived":false,"fork":false,"pushed_at":"2025-11-02T16:39:37.000Z","size":50,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-02T17:20:01.457Z","etag":null,"topics":["child-process","json-rpc","jsonrpc","lsp","mcp","rpc","stdio","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gnana997.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-02T14:53:32.000Z","updated_at":"2025-11-02T16:39:40.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/gnana997/node-stdio-jsonrpc","commit_stats":null,"previous_names":["gnana997/node-stdio-jsonrpc"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/gnana997/node-stdio-jsonrpc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gnana997%2Fnode-stdio-jsonrpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gnana997%2Fnode-stdio-jsonrpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gnana997%2Fnode-stdio-jsonrpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gnana997%2Fnode-stdio-jsonrpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gnana997","download_url":"https://codeload.github.com/gnana997/node-stdio-jsonrpc/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gnana997%2Fnode-stdio-jsonrpc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33152097,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-17T09:28:26.183Z","status":"ssl_error","status_checked_at":"2026-05-17T09:27:52.702Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["child-process","json-rpc","jsonrpc","lsp","mcp","rpc","stdio","typescript"],"created_at":"2025-11-02T22:01:22.133Z","updated_at":"2026-05-17T19:37:42.091Z","avatar_url":"https://github.com/gnana997.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-stdio-jsonrpc\n\n[![npm version](https://img.shields.io/npm/v/node-stdio-jsonrpc.svg)](https://www.npmjs.com/package/node-stdio-jsonrpc)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n[![TypeScript](https://img.shields.io/badge/TypeScript-5.x-blue.svg)](https://www.typescriptlang.org/)\n\n**Clean, developer-friendly JSON-RPC 2.0 client over stdio (child process communication)**\n\nBuilt on top of [`@gnana997/node-jsonrpc`](https://www.npmjs.com/package/@gnana997/node-jsonrpc) with a stdio transport layer for communicating with child processes using line-delimited JSON.\n\nPerfect for building clients for:\n- [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) servers\n- Language servers (LSP)\n- Custom stdio-based JSON-RPC services\n- CLI tools with JSON-RPC interfaces\n\n## Features\n\n✨ **Clean API** - Simple, intuitive interface for stdio JSON-RPC communication\n🚀 **TypeScript First** - Full type safety with generics\n📦 **Dual Package** - ESM and CommonJS support\n🔄 **Event-Driven** - Built on EventEmitter for notifications and logs\n🛡️ **Robust** - Comprehensive error handling and process lifecycle management\n🧪 **Well-Tested** - 47 tests with 81%+ coverage\n📝 **Well-Documented** - Examples and TypeScript types included\n\n## Installation\n\n```bash\nnpm install node-stdio-jsonrpc\n```\n\n## Quick Start\n\n```typescript\nimport { StdioClient } from 'node-stdio-jsonrpc';\n\n// Create a client that spawns a child process\nconst client = new StdioClient({\n  command: 'node',\n  args: ['./your-jsonrpc-server.js'],\n  debug: true, // Optional: enable debug logging\n});\n\n// Connect to the server\nawait client.connect();\n\n// Make a request\nconst result = await client.request('yourMethod', { param: 'value' });\nconsole.log('Result:', result);\n\n// Send a notification (no response expected)\nclient.notify('log', { level: 'info', message: 'Hello' });\n\n// Listen for server notifications\nclient.on('notification', (method, params) =\u003e {\n  console.log(`Server notification: ${method}`, params);\n});\n\n// Disconnect when done\nawait client.disconnect();\n```\n\n## API Reference\n\n### `StdioClient`\n\nThe main class for creating JSON-RPC clients over stdio.\n\n#### Constructor\n\n```typescript\nnew StdioClient(config: StdioClientConfig)\n```\n\n**Config Options:**\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| `command` | `string` | *required* | Command to spawn (e.g., `'node'`, `'python'`) |\n| `args` | `string[]` | `[]` | Arguments to pass to the command |\n| `cwd` | `string` | `process.cwd()` | Working directory for the child process |\n| `env` | `NodeJS.ProcessEnv` | `process.env` | Environment variables |\n| `connectionTimeout` | `number` | `10000` | Connection timeout in milliseconds |\n| `requestTimeout` | `number` | `30000` | Request timeout in milliseconds |\n| `debug` | `boolean` | `false` | Enable debug logging |\n\n#### Methods\n\n##### `connect(): Promise\u003cvoid\u003e`\n\nSpawns the child process and establishes the connection.\n\n```typescript\nawait client.connect();\n```\n\n##### `disconnect(): Promise\u003cvoid\u003e`\n\nTerminates the child process and cleans up resources.\n\n```typescript\nawait client.disconnect();\n```\n\n##### `request\u003cTResult\u003e(method: string, params?: unknown): Promise\u003cTResult\u003e`\n\nSends a JSON-RPC request and waits for the response.\n\n```typescript\ninterface CalculateResult {\n  sum: number;\n}\n\nconst result = await client.request\u003cCalculateResult\u003e('calculate', {\n  operation: 'add',\n  a: 5,\n  b: 3,\n});\n\nconsole.log(result.sum); // 8\n```\n\n##### `notify(method: string, params?: unknown): void`\n\nSends a JSON-RPC notification (no response expected).\n\n```typescript\nclient.notify('log', { level: 'info', message: 'Task completed' });\n```\n\n##### `isConnected(): boolean`\n\nChecks if the client is currently connected.\n\n```typescript\nif (client.isConnected()) {\n  console.log('Connected!');\n}\n```\n\n#### Events\n\nThe client extends `EventEmitter` and emits the following events:\n\n| Event | Parameters | Description |\n|-------|------------|-------------|\n| `connected` | `()` | Emitted when connection is established |\n| `disconnected` | `()` | Emitted when disconnected from server |\n| `notification` | `(method: string, params?: unknown)` | Server sent a notification |\n| `error` | `(error: Error)` | An error occurred |\n| `log` | `(message: string)` | Server wrote to stderr |\n\n```typescript\nclient.on('connected', () =\u003e {\n  console.log('Connected to server!');\n});\n\nclient.on('disconnected', () =\u003e {\n  console.log('Disconnected from server');\n});\n\nclient.on('notification', (method, params) =\u003e {\n  console.log(`Notification: ${method}`, params);\n});\n\nclient.on('error', (error) =\u003e {\n  console.error('Error:', error);\n});\n\nclient.on('log', (message) =\u003e {\n  console.log(`Server log: ${message}`);\n});\n```\n\n### `StdioTransport`\n\nLower-level transport implementation. Usually you'll use `StdioClient`, but `StdioTransport` is available if you need direct control.\n\n```typescript\nimport { StdioTransport } from 'node-stdio-jsonrpc/transport';\nimport { JSONRPCClient } from '@gnana997/node-jsonrpc';\n\nconst transport = new StdioTransport({\n  command: 'node',\n  args: ['./server.js'],\n});\n\nconst client = new JSONRPCClient({ transport });\nawait client.connect();\n```\n\n## Examples\n\n### Basic Example\n\n```typescript\nimport { StdioClient } from 'node-stdio-jsonrpc';\n\nconst client = new StdioClient({\n  command: 'node',\n  args: ['./echo-server.js'],\n});\n\nawait client.connect();\n\nconst response = await client.request('echo', { message: 'Hello, World!' });\nconsole.log(response); // { message: 'Hello, World!' }\n\nawait client.disconnect();\n```\n\n### MCP Client Example\n\nPerfect for connecting to Model Context Protocol servers:\n\n```typescript\nimport { StdioClient } from 'node-stdio-jsonrpc';\n\nconst client = new StdioClient({\n  command: 'npx',\n  args: ['@modelcontextprotocol/server-filesystem', '~/Documents'],\n  debug: true,\n});\n\nawait client.connect();\n\n// Initialize MCP session\nconst initResult = await client.request('initialize', {\n  protocolVersion: '2024-11-05',\n  capabilities: { roots: { listChanged: true } },\n  clientInfo: { name: 'my-client', version: '1.0.0' },\n});\n\nclient.notify('notifications/initialized');\n\n// List available tools\nconst { tools } = await client.request('tools/list');\nconsole.log('Available tools:', tools);\n\nawait client.disconnect();\n```\n\nSee the [MCP client example](./examples/mcp-client) for a complete implementation.\n\n### Error Handling\n\n```typescript\nimport { StdioClient, JSONRPCError } from 'node-stdio-jsonrpc';\n\nconst client = new StdioClient({\n  command: 'node',\n  args: ['./server.js'],\n});\n\ntry {\n  await client.connect();\n\n  const result = await client.request('someMethod', { param: 'value' });\n  console.log('Success:', result);\n\n} catch (error) {\n  if (error instanceof JSONRPCError) {\n    console.error('JSON-RPC Error:', error.code, error.message);\n  } else {\n    console.error('Connection/Transport Error:', error);\n  }\n} finally {\n  if (client.isConnected()) {\n    await client.disconnect();\n  }\n}\n```\n\n### Using with TypeScript\n\n```typescript\nimport { StdioClient } from 'node-stdio-jsonrpc';\n\n// Define your request/response types\ninterface CalculateParams {\n  operation: 'add' | 'subtract' | 'multiply' | 'divide';\n  a: number;\n  b: number;\n}\n\ninterface CalculateResult {\n  result: number;\n}\n\nconst client = new StdioClient({\n  command: 'node',\n  args: ['./calculator-server.js'],\n});\n\nawait client.connect();\n\n// Type-safe requests\nconst result = await client.request\u003cCalculateResult\u003e('calculate', {\n  operation: 'add',\n  a: 10,\n  b: 5,\n} satisfies CalculateParams);\n\nconsole.log(result.result); // TypeScript knows this is a number\n\nawait client.disconnect();\n```\n\n## Protocol\n\nThis library implements **JSON-RPC 2.0** over **stdio** (standard input/output) using **line-delimited JSON** framing:\n\n- Each JSON message is on its own line\n- Messages are terminated with `\\n`\n- stdin: Client → Server\n- stdout: Server → Client (JSON-RPC messages)\n- stderr: Server logs (not JSON-RPC)\n\n### Message Format\n\n**Request:**\n```json\n{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"methodName\",\"params\":{\"key\":\"value\"}}\n```\n\n**Success Response:**\n```json\n{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":{\"data\":\"value\"}}\n```\n\n**Error Response:**\n```json\n{\"jsonrpc\":\"2.0\",\"id\":1,\"error\":{\"code\":-32000,\"message\":\"Error message\"}}\n```\n\n**Notification (no id):**\n```json\n{\"jsonrpc\":\"2.0\",\"method\":\"notifyMethod\",\"params\":{\"key\":\"value\"}}\n```\n\n## Requirements\n\n- Node.js 18 or higher\n- TypeScript 5.x (if using TypeScript)\n\n## Related Packages\n\n- [`@gnana997/node-jsonrpc`](https://www.npmjs.com/package/@gnana997/node-jsonrpc) - Core JSON-RPC 2.0 implementation\n- [`node-ipc-jsonrpc`](https://github.com/gnana997/ipc-jsonrpc) - JSON-RPC over IPC (Unix sockets / Windows named pipes)\n\n## Contributing\n\nContributions are welcome! Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines.\n\n## License\n\nMIT © [gnana997](https://github.com/gnana997)\n\n## Changelog\n\nSee [CHANGELOG.md](./CHANGELOG.md) for version history.\n\n---\n\n**Built with ❤️ using TypeScript and [@gnana997/node-jsonrpc](https://www.npmjs.com/package/@gnana997/node-jsonrpc)**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgnana997%2Fnode-stdio-jsonrpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgnana997%2Fnode-stdio-jsonrpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgnana997%2Fnode-stdio-jsonrpc/lists"}