npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@reaatech/voice-agent-mcp-client

v0.1.0

Published

JSON-RPC 2.0 client for connecting voice AI agents to any MCP (Model Context Protocol) server endpoint

Readme

@reaatech/voice-agent-mcp-client

npm version License: MIT CI

Status: Pre-1.0 — APIs may change in minor versions. Pin to a specific version in production.

JSON-RPC 2.0 client for connecting to any MCP (Model Context Protocol) server endpoint. Tool discovery, conversation history management, retry with backoff, and response sanitization for TTS output.

Installation

npm install @reaatech/voice-agent-mcp-client
pnpm add @reaatech/voice-agent-mcp-client

Feature Overview

  • JSON-RPC 2.0 transport — Standards-compliant protocol over HTTP POST with fetch
  • Tool discoverydiscoverTools() fetches available tools from MCP server at connect time
  • Bearer and API-key auth — Pluggable authentication via config
  • Conversation history — Automatic history truncation to max turns to control context size
  • Retry with backoff — Configurable retry for 5xx errors, network failures, and timeouts
  • Response sanitization — Strips HTML, markdown links, and HTML entities from MCP responses for clean TTS
  • Abort signal support — Timeout-based abort via AbortController

Quick Start

import { MCPClient } from '@reaatech/voice-agent-mcp-client';

const client = new MCPClient({
  endpoint: 'https://my-agent.example.com/mcp',
  auth: {
    type: 'bearer',
    credentials: { token: process.env.MCP_API_KEY! },
  },
  timeout: 400,
  retryAttempts: 2,
  maxHistoryTurns: 20,
});

await client.connect();

const response = await client.sendRequest({
  sessionId: 'session-123',
  turnId: 'turn-456',
  utterance: 'What is the weather in Tokyo?',
  history: [
    { role: 'user', content: 'Hello' },
    { role: 'assistant', content: 'Hi there! How can I help?' },
  ],
});

console.log(response.text);       // Clean TTS-ready text
console.log(response.toolCalls);  // Any tool calls made
console.log(response.latencyMs);  // Response time in ms

await client.close();

API Reference

MCPClient

class MCPClient {
  constructor(config: MCPClientConfig);

  connect(): Promise<void>;
  close(): Promise<void>;

  sendRequest(params: MCPRequestParams): Promise<MCPResponse>;
  discoverTools(): Promise<MCPTool[]>;
  isConnected(): boolean;
  getDiscoveredTools(): MCPTool[];
}

MCPClientConfig

| Property | Type | Default | Description | |----------|------|---------|-------------| | endpoint | string | — | Required. MCP server URL | | auth | { type, credentials } | — | Authentication configuration | | timeout | number | 400 | Request timeout in ms | | retryAttempts | number | 1 | Number of retry attempts for retryable errors | | retryDelay | number | 100 | Delay between retries in ms | | maxHistoryTurns | number | 20 | Max conversation turns sent in request history |

MCPRequestParams

| Property | Type | Description | |----------|------|-------------| | sessionId | string | Session identifier | | turnId | string | Turn identifier | | utterance | string | User utterance text | | history | Array<{ role, content }> | Previous conversation turns | | tools | MCPTool[] | Optional tool list override (uses discovered tools by default) |

MCPResponse

| Property | Type | Description | |----------|------|-------------| | text | string | Sanitized response text ready for TTS | | toolCalls | MCPToolCall[] | Tool calls made by the agent | | latencyMs | number | Request round-trip latency | | confidence | number | Response confidence (default 0.95) |

MCPTool

interface MCPTool {
  name: string;
  description?: string;
  inputSchema: Record<string, unknown>;
}

Usage Patterns

Authentication

Bearer token:

const client = new MCPClient({
  endpoint: 'https://...',
  auth: { type: 'bearer', credentials: { token: 'sk-...' } },
});

API key:

const client = new MCPClient({
  endpoint: 'https://...',
  auth: { type: 'api-key', credentials: { key: 'pk-...' } },
});

Retry Behavior

Retryable errors: HTTP 5xx responses, fetch failed network errors, AbortError timeouts, TypeError DNS failures. Non-retryable: HTTP 4xx responses.

const client = new MCPClient({
  endpoint: 'https://...',
  retryAttempts: 3,
  retryDelay: 200,   // 200ms between retries
  timeout: 500,
});

Response Sanitization

MCP responses are automatically cleaned for TTS consumption:

  • HTML tags removed: <div>Hello</div>Hello
  • Markdown links stripped: [click here](url)click here
  • HTML entities decoded: &amp;&, &lt;<

Tool Discovery

await client.connect();               // Automatically discovers tools
const tools = client.getDiscoveredTools(); // Cached tool list

console.log('Available tools:', tools.map(t => t.name));

Related Packages

License

MIT