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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@ai-universe/mcp-conversation-client

v2.1.2

Published

TypeScript client library and JSON schemas for AI Universe Conversation MCP Server with unified auto-creation API

Readme

AI Universe MCP Conversation Client

TypeScript client library for the AI Universe Conversation MCP Server with unified auto-creation API.

Installation

npm install @ai-universe/mcp-conversation-client

Features

  • 🚀 Unified Auto-Creation API - Conversations auto-create on first message
  • 📝 Type-Safe - Full TypeScript support with exported types
  • 🔒 Secure - Built-in userId validation and ownership checks
  • 📊 Complete API Coverage - All 4 MCP conversation tools supported
  • 🎯 Simple & Intuitive - Clean, easy-to-use API
  • Persist-or-Error Contract - v2.0.4+ guarantees every successful sendMessage returns both conversationId and messageId, and the client throws if either is missing

Persist-or-Error Guarantee

Beginning with v2.0.4 the Conversation MCP server retries transient Firestore failures once and only returns success when both the conversation and message records have been persisted. The TypeScript client enforces this contract: if a response omits either identifier it throws, ensuring agents never operate on partially saved data. Remove any synthetic persistence fallbacks in your agents once you upgrade to this release.

Quick Start

import { ConversationClient } from '@ai-universe/mcp-conversation-client';

// Initialize client
const client = new ConversationClient('http://localhost:3000/mcp');

// Send a message (auto-creates conversation if needed)
const result = await client.sendMessage({
  userId: 'user_123',
  content: 'Hello! This is my first message.',
  role: 'user',
  title: 'My Conversation'
});

console.log('Conversation ID:', result.conversationId);
console.log('Created new conversation:', result.created);

// Add another message to the same conversation
await client.sendMessage({
  userId: 'user_123',
  conversationId: result.conversationId,
  content: 'This is my second message.',
  role: 'assistant'
});

// Get conversation metadata
const conversation = await client.getConversation({
  userId: 'user_123',
  conversationId: result.conversationId
});

console.log('Title:', conversation.title);
console.log('Message count:', conversation.messageCount);

// Get message history
const history = await client.getHistory({
  userId: 'user_123',
  conversationId: result.conversationId,
  limit: 50
});

console.log('Messages:', history.messages);

// List all conversations for a user
const conversations = await client.listConversations({
  userId: 'user_123',
  pageSize: 10
});

console.log('Total conversations:', conversations.totalCount);

API Reference

sendMessage(params)

Send a message to a conversation. Auto-creates conversation if conversationId is not provided.

Parameters:

  • userId (string, required) - User identifier
  • content (string, required) - Message content
  • role ('user' | 'assistant', required) - Message role
  • conversationId (string, optional) - Conversation ID. Omit to auto-create.
  • title (string, optional) - Conversation title (only used on auto-creation)

Returns:

{
  conversationId: string;
  messageId: string;
  sequence: number;
  created: boolean;  // true if conversation was auto-created
  title: string;
  timestamp: string; // ISO-8601 timestamp of message creation
}

getConversation(params)

Get conversation metadata.

Parameters:

  • userId (string, required)
  • conversationId (string, required)

Returns:

{
  conversationId: string;
  userId: string;
  title: string;
  messageCount: number;
  createdAt: string;
  updatedAt: string;
}

getHistory(params)

Get conversation message history with pagination.

Parameters:

  • userId (string, required)
  • conversationId (string, required)
  • limit (number, optional) - Max messages to return
  • cursor (string, optional) - Pagination cursor

Returns:

{
  conversationId: string;
  messages: Array<{
    messageId: string;
    conversationId: string;
    content: string;
    role: 'user' | 'assistant';
    sequence: number;
    timestamp: string;
  }>;
  hasMore: boolean;
  nextCursor?: string;
}

listConversations(params)

List all conversations for a user with pagination.

Parameters:

  • userId (string, required)
  • pageSize (number, optional) - Conversations per page
  • cursor (string, optional) - Pagination cursor

Returns:

{
  conversations: Array<{
    conversationId: string;
    title: string;
    messageCount: number;
    createdAt: string;
    updatedAt: string;
  }>;
  totalCount: number;
  hasMore: boolean;
  nextCursor?: string;
}

Auto-Creation Feature

The unified API automatically creates conversations when you send the first message without providing a conversationId:

// First message - auto-creates conversation
const result = await client.sendMessage({
  userId: 'user_123',
  content: 'Hello!',
  role: 'user',
  title: 'My Chat'  // Optional title
});

console.log(result.created);  // true
console.log(result.conversationId);  // Auto-generated ID

// Subsequent messages - use the conversation ID
await client.sendMessage({
  userId: 'user_123',
  conversationId: result.conversationId,
  content: 'Follow-up message',
  role: 'assistant'
});

If no title is provided, one is auto-generated from the first message content with PII redaction.

Error Handling

try {
  const result = await client.sendMessage({
    userId: 'user_123',
    content: 'Hello!',
    role: 'user'
  });
} catch (error) {
  if (error.message.includes('unauthorized')) {
    console.error('User does not own this conversation');
  } else if (error.message.includes('not found')) {
    console.error('Conversation not found');
  } else {
    console.error('Unexpected error:', error);
  }
}

TypeScript Types

All types are exported for use in your application:

import type {
  SendMessageParams,
  SendMessageResponse,
  GetConversationParams,
  ConversationMetadata,
  GetHistoryParams,
  ConversationHistory,
  ListConversationsParams,
  ConversationList,
  Message
} from '@ai-universe/mcp-conversation-client';

JSON Schemas

Starting in v2.1.0, comprehensive JSON schemas are included for all MCP tool requests and responses. These can be used for validation, documentation, code generation, and more.

Using the Schemas

// Import all schemas
import { schemas, requestSchemas, responseSchemas } from '@ai-universe/mcp-conversation-client/schemas';

// Use individual schemas
import {
  sendMessageRequestSchema,
  sendMessageResponseSchema,
  getHistoryRequestSchema,
  getHistoryResponseSchema
} from '@ai-universe/mcp-conversation-client/schemas';

Available Schemas

Request and response schemas are available for all MCP tools:

  • health-check - Health check endpoint
  • convo.send-message - Send message with auto-creation
  • convo.get-conversation - Get conversation metadata
  • convo.get-history - Get conversation history
  • convo.get-message - Get a single message
  • convo.list-conversations - List user conversations

Schema Structure

All schemas are JSON Schema Draft 7 compliant. Example:

// Access a complete tool schema
const sendMessageSchema = schemas['convo.send-message'];
console.log(sendMessageSchema.request);   // Request schema
console.log(sendMessageSchema.response);  // Response schema

// Or access directly
console.log(requestSchemas['convo.send-message']);
console.log(responseSchemas['convo.send-message']);

Validation Example

Use with your favorite JSON Schema validator:

import Ajv from 'ajv';
import { sendMessageRequestSchema } from '@ai-universe/mcp-conversation-client/schemas';

const ajv = new Ajv();
const validate = ajv.compile(sendMessageRequestSchema);

const data = {
  userId: 'user_123',
  content: 'Hello!',
  role: 'user'
};

if (validate(data)) {
  console.log('Valid!');
} else {
  console.log('Invalid:', validate.errors);
}

Version History

2.1.0 (Current)

  • NEW: Comprehensive JSON schemas for all MCP tool requests and responses
  • Export schemas separately via @ai-universe/mcp-conversation-client/schemas
  • JSON Schema Draft 7 compliant for validation, documentation, and code generation
  • All previous v2.0.x features included

2.0.6

  • Unified auto-creation API
  • Complete TypeScript support
  • PII redaction in auto-generated titles
  • Firestore backend support
  • Persist-or-Error contract guarantee

1.x

  • Legacy in-memory storage
  • Manual conversation creation required

License

MIT

Support

For issues and questions: