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

@swoft/middleware

v1.0.2

Published

Shared Express middleware for Swoft microservices

Downloads

6

Readme

@swoft/middleware

Shared Express middleware for Swoft microservices. Provides consistent behavior across all backend services.

Installation

pnpm add @swoft/middleware

Response Metadata Middleware

Adds standardized metadata to all JSON responses for debugging, tracing, and monitoring.

Basic Usage

import express from 'express';
import { createResponseMetadataMiddleware } from '@swoft/middleware';

const app = express();

app.use(
  createResponseMetadataMiddleware({
    serviceName: 'my-service',
    version: '1.0.0',
  })
);

Advanced Configuration

app.use(
  createResponseMetadataMiddleware({
    serviceName: '@swoft/collaboration-backend',
    version: '2.0.0',
    includeDatabase: true,
    databaseType: 'mongodb',
    getDatabaseStatus: () => db.isConnected(),
    getPort: () => parseInt(process.env.PORT || '4004'),
    enableRequestIdHeader: true,
  })
);

Response Structure

All responses will be wrapped with metadata:

{
  "data": {
    /* original response */
  },
  "metadata": {
    "service": "@swoft/collaboration-backend",
    "environment": "development",
    "database": {
      "type": "mongodb",
      "url": "mongodb://localhost:27017/swoft",
      "connected": true
    },
    "server": {
      "hostname": "dev-machine",
      "port": 4004,
      "pid": 12345
    },
    "timestamp": "2025-01-25T16:30:00.000Z",
    "version": "2.0.0",
    "responseTimeMs": 45,
    "requestId": "1753460000000-abc123def"
  }
}

MCP Tool Integration

For MCP tools that call backend services:

import { addMCPMetadata, extractMetadata } from '@swoft/middleware';

// In your MCP tool
const backendResponse = await fetch('/api/gtd/tasks');
const responseWithMCPMetadata = addMCPMetadata(backendResponse, {
  tool: 'gtd_project_list',
  version: '1.0.0',
  processingTimeMs: 5,
});

Production Mode

In production (NODE_ENV=production):

  • Database information is hidden
  • Server hostname and PID are masked
  • Less sensitive metadata is included

Environment Variables

  • NODE_ENV - Controls production mode behavior
  • API_VERSION - Default version if not specified
  • PORT - Default port if getPort not provided
  • MONGODB_URI - Database connection string (password sanitized)

Future Middleware

This package will grow to include:

  • Error handling middleware
  • Request validation middleware
  • Rate limiting middleware
  • Authentication middleware
  • CORS configuration

Contributing

When adding new middleware:

  1. Create a new directory under src/
  2. Export from src/index.ts
  3. Add documentation to this README
  4. Include TypeScript types