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

openai-mcp

v0.0.7

Published

A TypeScript library that provides an OpenAI-compatible client for the Model Context Protocol (MCP).

Downloads

30

Readme

openai-mcp

A TypeScript library that provides an OpenAI-compatible client for the Model Context Protocol (MCP).

Installation

npm install openai-mcp

Features

  • OpenAI API compatibility - works as a drop-in replacement for the OpenAI client
  • Connects to local or remote Model Context Protocol servers
  • Supports tool use and function calling
  • Rate limiting and retry logic built in
  • Configurable logging
  • TypeScript type definitions included

Usage

import { OpenAI } from 'openai-mcp';

// Create an OpenAI-compatible client connected to an MCP server
const openai = new OpenAI({
  mcp: {
    // MCP server URL(s) to connect to
    serverUrls: ['http://localhost:3000/mcp'],
    
    // Optional: set log level (debug, info, warn, error)
    logLevel: 'info',
    
    // Additional configuration options
    // modelName: 'gpt-4',             // Default model to use
    // disconnectAfterUse: true,       // Auto-disconnect after use
    // maxToolCalls: 15,               // Max number of tool calls per conversation
    // toolTimeoutSec: 60,             // Timeout for tool calls
  }
});

// Use the client like a standard OpenAI client
const response = await openai.chat.completions.create({
  model: 'gpt-4',
  messages: [
    { role: 'system', content: 'You are a helpful assistant.' },
    { role: 'user', content: 'Hello, how are you today?' }
  ]
});

console.log(response.choices[0].message.content);

Logging Configuration

import { setMcpLogLevel } from 'openai-mcp';

// Set log level to one of: 'debug', 'info', 'warn', 'error'
setMcpLogLevel('info');

Environment Variables

The library also supports configuration through environment variables:

# MCP Server URL(s) - comma separated for multiple servers
MCP_SERVER_URL=http://localhost:3000/mcp

# API Keys for different model providers
OPENAI_API_KEY=your-openai-api-key
ANTHROPIC_API_KEY=your-anthropic-api-key
GEMINI_API_KEY=your-gemini-api-key

Multi-Model Support

The library supports routing requests to different model providers based on the model name:

import { OpenAI } from 'openai-mcp';

const openai = new OpenAI();

// Uses OpenAI API
const gpt4Response = await openai.chat.completions.create({
  model: 'gpt-4',
  messages: [{ role: 'user', content: 'Hello GPT-4' }]
});

// Uses Anthropic API
const claudeResponse = await openai.chat.completions.create({
  model: 'claude-3',
  messages: [{ role: 'user', content: 'Hello Claude' }]
});

// Uses Google Gemini API
const geminiResponse = await openai.chat.completions.create({
  model: 'gemini-pro',
  messages: [{ role: 'user', content: 'Hello Gemini' }]
});

Examples

The examples/ directory contains various usage examples:

See the Examples README for more details on running these examples.

Development

To build the library:

npm run build

To run tests:

npm test