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

pcp-protocol

v0.1.0

Published

Personal Context Protocol client library for web and React applications

Downloads

4

Readme

PCP (Personal Context Protocol) Client Library

Typed JavaScript/TypeScript client for interacting with the PCP browser extension from React, Next.js, and standard web applications.

  • 📦 Distributed as an npm package (pcp)
  • ⚛️ Includes a React hook (usePCP) for effortless integration
  • 🌐 Works in any browser environment with the PCP extension installed
  • 🔄 Automatically refreshes links and handles token expiry

Installation

npm install pcp
# or
pnpm add pcp
# or
yarn add pcp

Note: Make sure the PCP browser extension is installed and the user is signed in.

Usage

React / Next.js

import { usePCP } from "pcp";

export default function ContextPanel() {
  const { status, loading, error, requestAccess, fetchData } = usePCP();

  return (
    <div>
      <button onClick={requestAccess} disabled={loading}>
        {status.connected ? "Re-request Access" : "Request PCP Access"}
      </button>

      <button onClick={() => fetchData().then(console.log)} disabled={!status.connected || loading}>
        Fetch Context Data
      </button>

      {error && <p style={{ color: "red" }}>{error.message}</p>}
      {status.connected && <p>Link expires at: {new Date(status.link!.expires_at).toLocaleString()}</p>}
    </div>
  );
}

Using in Next.js (avoiding SSR)

If you render PCP-dependent UI on the server, guard for the browser:

import dynamic from "next/dynamic";

const SafeContextPanel = dynamic(() => import("../components/ContextPanel"), {
  ssr: false,
});

export default function Page() {
  return <SafeContextPanel />;
}

Plain Browser (vanilla JS)

<script type="module">
  import { requestAccess, fetchData } from "https://cdn.skypack.dev/pcp";

  async function start() {
    try {
      const link = await requestAccess();
      console.log("Access granted", link);

      const data = await fetchData();
      console.log("Context data", data);
    } catch (error) {
      console.error("PCP error", error);
    }
  }

  start();
</script>

API Reference

Core Functions

import {
  requestAccess,
  getStatus,
  fetchData,
  getCurrentLink,
  isConnected,
  ensureConnected,
} from "pcp";
  • requestAccess(): Promise<PCPLink> – Opens the extension prompt and returns the issued link
  • getStatus(): Promise<PCPStatus> – Current connection state
  • fetchData<T = unknown>(): Promise<T> – Fetches user context data from Supabase
  • getCurrentLink(): PCPLink | null – Cached link (if available)
  • isConnected(): boolean – Synchronous connection check
  • ensureConnected(): Promise<PCPLink> – Makes sure a valid link exists, requesting one if necessary

React Hook

import { usePCP } from "pcp";

const {
  status,
  loading,
  error,
  requestAccess,
  fetchData,
  ensureConnected,
  isConnected,
  currentLink,
} = usePCP({ autoConnect: true, refreshIntervalMs: 5000 });
  • status{ connected: boolean; link: PCPLink | null }
  • loading – Indicates in-flight operations
  • error – Last error encountered (if any)
  • requestAccess() – Prompts the extension
  • fetchData() – Fetches context data
  • ensureConnected() – Ensures a valid link is present
  • isConnected / currentLink – Derived convenience values

Publishing the Package

  1. Build the package

    pnpm install   # or npm install
    pnpm build     # outputs to dist/
  2. Test locally (optional)

    pnpm link --global
    # In your app
    pnpm link --global pcp
  3. Publish to npm

    npm publish --access public

Ensure the package.json fields (name, version, author, etc.) are correct before publishing.

Requirements

  • PCP browser extension installed and the user authenticated
  • Browser environment (the extension injects APIs into window)
  • React 17+ when using the usePCP hook

File Structure

library/
  package.json
  tsconfig.json
  src/
    core.ts       # Core logic (no React)
    usePCP.ts     # React hook
    index.ts      # Public exports

License

MIT – free for commercial and personal use.