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

mcp-completions

v0.0.15

Published

Add MCP tool calling with OAuth authentication to any OpenAI-compatible LLM via a fetch proxy.

Readme

MCP Completions

Add MCP tool calling with OAuth authentication to any OpenAI-compatible LLM via a fetch proxy.

Note: This library requires Cloudflare Workers with Durable Objects.

Quick Start

import { chatCompletionsProxy, OAuthProviders } from "mcp-completions";
import { OpenAI } from "openai";

export { OAuthProviders };

export default {
  fetch: async (request, env, ctx) => {
    const { fetchProxy, idpMiddleware } = chatCompletionsProxy(env, {
      baseUrl: new URL(request.url).origin,
      userId: "your-user-id",
      clientInfo: { name: "My App", title: "My App", version: "1.0.0" },
    });

    // Handle OAuth callbacks
    const oauthResponse = await idpMiddleware(request, env, ctx);
    if (oauthResponse) return oauthResponse;

    const client = new OpenAI({
      apiKey: env.OPENAI_API_KEY,
      fetch: fetchProxy,
    });

    const stream = await client.chat.completions.create({
      model: "gpt-4o",
      stream: true,
      stream_options: { include_usage: true },
      messages: [{ role: "user", content: "What tools do you have?" }],
      tools: [
        { type: "mcp", server_url: "https://mcp.notion.com/mcp" },
        { type: "url_context", max_urls: 10 },
      ],
    });

    return new Response(stream.toReadableStream(), {
      headers: { "content-type": "text/event-stream" },
    });
  },
};

Features

  • MCP Tools: Discover and execute tools from any MCP server
  • Universal OAuth: Automatic OAuth2 for APIs returning 401 with WWW-Authenticate
  • URL Context: Fetch content from URLs in messages with stored auth
  • Shadow URLs: Replace hostnames for better access (e.g., github.comuithub.com)
  • Extract Fallback: Convert HTML/PDF via configurable extract service
  • Cost Tracking: Track additional costs in usage stats

Configuration

chatCompletionsProxy(env, {
  baseUrl: "https://your-app.com",
  userId: "user-123",
  clientInfo: { name: "App", title: "App", version: "1.0.0" },

  // Optional: Replace hostnames for better content access
  shadowUrls: {
    "github.com": "uithub.com",
    "x.com": "xymake.com",
  },

  // Optional: Extract service for HTML/PDF
  extractUrl: {
    url: "https://extract.example.com",
    bearerToken: "your-api-key",
  },
});

Wrangler Setup

{
  "durable_objects": {
    "bindings": [{ "name": "OAuthProviders", "class_name": "OAuthProviders" }]
  },
  "migrations": [{ "tag": "v1", "new_sqlite_classes": ["OAuthProviders"] }]
}

Tool Types

MCP Server

{ type: "mcp", server_url: "https://mcp.notion.com/mcp", require_approval: "never" }

URL Context

{ type: "url_context", max_urls: 10, max_context_length: 1048576 }

Documentation

How It Works

  1. Request with MCP tools hits the proxy
  2. Proxy checks for stored OAuth tokens
  3. If missing, returns login links in the stream
  4. Once authenticated, discovers tools and translates to OpenAI functions
  5. Executes tool calls and streams results back