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

auth-agent-mcp-sdk

v1.0.0

Published

OAuth 2.1 middleware for MCP servers using Auth-Agent

Downloads

8

Readme

@auth-agent/mcp-sdk

OAuth 2.1 middleware for MCP servers using Auth-Agent.

Installation

npm install @auth-agent/mcp-sdk

Quick Start (Hono)

import { Hono } from 'hono';
import { authAgentMiddleware } from '@auth-agent/mcp-sdk';

const app = new Hono();

// Add Auth-Agent middleware
app.use('*', authAgentMiddleware({
  serverId: 'srv_abc123',        // Your MCP server ID
  apiKey: 'sk_xyz789',           // Your API key
  requiredScopes: ['files:read'] // Required OAuth scopes
}));

// Protected routes - user is automatically validated
app.get('/files', (c) => {
  const user = c.get('user');
  return c.json({
    message: `Hello ${user.email}`,
    scopes: user.scopes
  });
});

export default app;

Configuration

AuthAgentConfig

| Option | Type | Required | Default | Description | |--------|------|----------|---------|-------------| | serverId | string | ✅ | - | Your MCP server ID from Auth-Agent | | apiKey | string | ✅ | - | Your API key for token introspection | | requiredScopes | string[] | ❌ | [] | Required OAuth scopes for protected routes | | authServerUrl | string | ❌ | 'https://mcp.auth-agent.com' | Auth-Agent server URL | | cacheTtl | number | ❌ | 300 | Cache introspection results (seconds) |

Advanced Usage

Manual Token Validation

import { AuthAgentClient } from '@auth-agent/mcp-sdk';

const client = new AuthAgentClient({
  serverId: 'srv_abc123',
  apiKey: 'sk_xyz789'
});

try {
  const user = await client.validateToken(accessToken);
  console.log(`User: ${user.email}, Scopes: ${user.scopes.join(', ')}`);
} catch (error) {
  console.error('Invalid token:', error);
}

Scope-Based Authorization

app.get('/files', authAgentMiddleware({
  serverId: 'srv_abc123',
  apiKey: 'sk_xyz789',
  requiredScopes: ['files:read']
}), (c) => {
  // Only users with 'files:read' scope can access this
  return c.json({ files: [...] });
});

app.post('/files', authAgentMiddleware({
  serverId: 'srv_abc123',
  apiKey: 'sk_xyz789',
  requiredScopes: ['files:write']
}), (c) => {
  // Only users with 'files:write' scope can access this
  return c.json({ success: true });
});

Error Handling

The middleware automatically handles authentication errors:

  • 401 Unauthorized - Missing or invalid token
  • 403 Forbidden - Insufficient scopes
  • 500 Internal Server Error - Token validation failed
import { AuthenticationError, AuthorizationError } from '@auth-agent/mcp-sdk';

try {
  const user = await client.validateToken(token);
} catch (error) {
  if (error instanceof AuthenticationError) {
    console.error('Authentication failed:', error.message);
  } else if (error instanceof AuthorizationError) {
    console.error('Insufficient scopes:', error.requiredScopes);
  }
}

Getting Server Credentials

  1. Register your MCP server at Auth-Agent:
curl -X POST https://mcp.auth-agent.com/api/servers \
  -H "Content-Type: application/json" \
  -d '{
    "server_url": "https://your-mcp-server.com",
    "server_name": "My MCP Server",
    "scopes": ["files:read", "files:write"],
    "user_id": "your-user-id"
  }'
  1. Generate an API key:
curl -X POST https://mcp.auth-agent.com/api/servers/srv_abc123/keys \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Production Key"
  }'
  1. Use the returned server_id and api_key in your middleware config.

How It Works

  1. Client Authorization: MCP clients (Claude Code, install-mcp) redirect users to Auth-Agent for OAuth consent
  2. Token Issuance: Auth-Agent issues access tokens with user identity and scopes
  3. Token Validation: Your MCP server validates tokens via introspection endpoint
  4. Scope Enforcement: Middleware checks if user has required scopes before granting access

TypeScript Support

Full TypeScript support with type definitions included:

import type { AuthUser, AuthAgentConfig } from '@auth-agent/mcp-sdk';

const config: AuthAgentConfig = {
  serverId: 'srv_abc123',
  apiKey: 'sk_xyz789',
  requiredScopes: ['files:read']
};

app.get('/user-info', (c) => {
  const user: AuthUser = c.get('user');
  return c.json(user);
});

License

MIT