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

@affectively/mcp-framework

v1.0.1

Published

Framework for building Model Context Protocol (MCP) servers with authentication, tool registration, and analytics.

Readme

@affectively/mcp-framework

A framework for building Model Context Protocol (MCP) servers with built-in authentication, tool registration, and analytics.

npm version License: MIT

What is MCP?

The Model Context Protocol (MCP) is an open standard that enables AI applications to securely connect with data sources and tools. This framework makes it easy to build MCP servers that integrate with:

  • GitHub Copilot
  • Claude Desktop
  • Cursor
  • Other MCP-compatible clients

Features

  • Tool Registration - Declarative tool definition with JSON Schema validation
  • Authentication - Firebase Auth integration with token management
  • Transport Modes - stdio (local) and HTTP (deployed) support
  • Analytics - Optional GA4 Measurement Protocol integration
  • Type Safety - Full TypeScript support with inference

Installation

npm install @affectively/mcp-framework
# or
yarn add @affectively/mcp-framework
# or
bun add @affectively/mcp-framework

Quick Start

import { createMCPServer, defineTool } from '@affectively/mcp-framework';

// Define a tool
const greetTool = defineTool({
 name: 'greet',
 description: 'Greet a user by name',
 inputSchema: {
 type: 'object',
 properties: {
 name: { type: 'string', description: 'Name to greet' }
 },
 required: ['name']
 },
 handler: async ({ name }) => {
 return { content: [{ type: 'text', text: `Hello, ${name}!` }] };
 }
});

// Create and start server
const server = createMCPServer({
 name: 'my-mcp-server',
 version: '1.0.0',
 tools: [greetTool]
});

server.start();

Configuration

Environment Variables

# Transport mode: 'stdio' (default) or 'http'
TRANSPORT_MODE=stdio

# HTTP mode settings
PORT=3001
CORS_ORIGIN=*

# Authentication (optional)
FIREBASE_AUTH_TOKEN=your-token-here

# Analytics (optional)
GA4_MEASUREMENT_ID=G-XXXXXXXXXX
GA4_API_SECRET=your-api-secret

MCP Client Configuration

Add to your MCP client config (e.g., ~/.cursor/mcp.json):

{
 "mcpServers": {
 "my-server": {
 "command": "npx",
 "args": ["-y", "@affectively/mcp-framework"],
 "env": {
 "API_BASE_URL": "https://api.example.com"
 }
 }
 }
}

Tool Definition

import { defineTool } from '@affectively/mcp-framework';

const myTool = defineTool({
 // Required
 name: 'tool_name',
 description: 'What this tool does',
 inputSchema: {
 type: 'object',
 properties: {
 param1: { type: 'string', description: 'Description' }
 },
 required: ['param1']
 },
 handler: async (input, context) => {
 // context includes: authToken, userId, logger
 return {
 content: [{ type: 'text', text: 'Result' }]
 };
 },
 
 // Optional
 requiresAuth: true,
 subscriptionTier: 'premium', // 'free' | 'premium' | 'enterprise'
});

Authentication

Token File Authentication

The framework supports token file authentication for persistent sessions:

import { createMCPServer, withAuth } from '@affectively/mcp-framework';

const server = createMCPServer({
 name: 'my-server',
 version: '1.0.0',
 tools: [myTool],
 auth: {
 tokenFilePath: '~/.mcp-auth-token',
 refreshEndpoint: 'https://api.example.com/token/refresh'
 }
});

Built-in Auth Tools

The framework includes built-in tools for authentication:

  • check_login_state - Check current auth status
  • get_login_url - Generate browser login URL
  • login_with_token - Save token from browser flow

HTTP Mode

For deployed servers, enable HTTP transport:

const server = createMCPServer({
 name: 'my-server',
 version: '1.0.0',
 tools: [myTool],
 transport: {
 mode: 'http',
 port: 3001,
 cors: true
 }
});

Analytics

Track tool usage with GA4:

const server = createMCPServer({
 name: 'my-server',
 version: '1.0.0',
 tools: [myTool],
 analytics: {
 measurementId: 'G-XXXXXXXXXX',
 apiSecret: 'your-secret'
 }
});

Tracked events:

  • mcp_tool_call - When a tool is invoked
  • mcp_tool_complete - When a tool completes successfully
  • mcp_tool_error - When a tool fails

API Reference

createMCPServer(options)

Create a new MCP server instance.

defineTool(config)

Define a tool with type-safe input/output.

withAuth(handler)

Wrap a handler to require authentication.

withSubscription(tier, handler)

Wrap a handler to require a subscription tier.

Examples

See the examples/ directory for:

  • Basic tool server
  • Authenticated API proxy
  • Multi-tool server with analytics

Related Packages

License

MIT License - see LICENSE for details.


Made with ️ by AFFECTIVELY