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 🙏

© 2025 – Pkg Stats / Ryan Hefner

flowmcp

v2.2.0

Published

Powerful toolkit for MCP (Model Context Protocol) tools and automated workflow processes

Readme

FlowMCP

Powerful toolkit for building MCP (Model Context Protocol) tools with automatic validation, error handling, and project path management.

Installation

npm install flowmcp

Key Features

  • Tool Building - Create MCP tools with automatic schema validation
  • Project Path Management - Automatic project parameter injection and validation
  • Session Handling - Manage MCP request sessions with error handling
  • Independent Logger - Standalone error/warning collection with frequency analysis
  • TypeScript Support - Full type safety and IntelliSense support

Basic Usage

Build MCP Tools

import { McpBuilder } from 'flowmcp';
import { Server } from '@modelcontextprotocol/sdk/server/index.js';

const builder = new McpBuilder();

// Register a tool - project parameter added automatically
const result = builder.addTool({
  name: 'read_file',
  description: 'Read a file from the project',
  inputSchema: {
    type: 'object',
    properties: {
      filename: { type: 'string' }
    },
    required: ['filename']
  }
}, async (session, request) => {
  const { project, filename } = request.params.arguments;
  // project is validated as absolute path
  
  try {
    const content = await readFile(path.join(project, filename));
    return session.getResult({ content, filename });
  } catch (error) {
    session.logger.addError({
      code: 'FILE_READ_ERROR',
      context: { project, filename, error: error.message }
    });
    
    return session.getResult({ error: 'File not found' });
  }
});

// Apply tools to MCP server
const server = new Server({ name: 'file-server', version: '1.0.0' });
builder.applyToServer(server);

Handle MCP Sessions

import { McpSession } from 'flowmcp';

// Create session per request
function handleRequest(requestData) {
  const session = new McpSession();
  
  // Use throwError for critical failures that should stop execution
  if (requestData.invalid) {
    session.throwError({
      code: 'INVALID_REQUEST_DATA',
      context: { invalidFields: requestData.getInvalidFields() }
    });
    // This line never executes - throwError stops execution
  }
  
  // Generate responses
  return session.getResult({ data: 'result' });
}

Independent Error Logging

import { Logger } from 'flowmcp';

// Logger can be used independently of sessions
const logger = new Logger();

// Collect and group errors (by code)
logger.addError({ code: 'VALIDATION_ERROR', context: { field: 'email', format: 'invalid' } });
logger.addWarning({ code: 'DEPRECATED_API', context: { endpoint: '/old-api', replacement: '/v2/api' } });

// Get prioritized summary
const { errors, warnings } = logger.getResponse();

Integration

Complete MCP server integration:

import { McpBuilder } from 'flowmcp';
import { Server } from '@modelcontextprotocol/sdk/server/index.js';

const builder = new McpBuilder();
const server = new Server({ name: 'my-mcp-server', version: '1.0.0' });

// Register tools
builder.addTool({
  name: 'process_data',
  description: 'Process project data',
  inputSchema: {
    type: 'object',
    properties: {
      data: { type: 'string' }
    }
  }
}, async (session, request) => {
  const { project, data } = request.params.arguments;
  
  try {
    const result = await processData(project, data);
    return session.getResult({ result });
  } catch (error) {
    session.logger.addError({ 
      code: 'PROCESSING_ERROR',
      context: { project, data, error: error.message }
    });
    
    return session.getResult({ error: error.message });
  }
});

// Apply all registered tools to the server
builder.applyToServer(server);

// Start the server
server.connect(transport);

Good Practices

Error Handling

  • Use message only when necessary: Add message only when the error code is insufficient for understanding the error
  • Context for LLM guidance: Use context to provide meaningful information for LLM error handling, not duplicate data
  • Avoid duplication: Context should not duplicate information from message or code
  • Grouping by code: All errors/warnings with the same code are grouped together regardless of message
  • Descriptive error codes: Use specific, descriptive error codes that clearly indicate the problem
  • Create error utilities: Build helper functions for common error patterns to ensure consistency

Good Examples

// Good: Code is self-explanatory, context provides actionable info
session.logger.addError({
  code: 'FILE_NOT_FOUND',
  context: { path: '/missing/file.txt', suggestion: 'check file permissions' }
});

// Good: Message adds clarity when code isn't enough
session.logger.addError({
  code: 'VALIDATION_ERROR',
  message: 'Email format is invalid',
  context: { field: 'email', value: 'invalid-email' }
});

// Good: Specific, descriptive error codes
session.logger.addError({
  code: 'FILE_NOT_FOUND',  // clearly indicates what's missing
  context: { path: '/config.json' }
});

// Good: Error utility functions for consistency
function fileNotFoundError(path: string) {
  return {
    code: 'FILE_NOT_FOUND' as const,
    context: { path }
  };
}

session.logger.addError(fileNotFoundError('/missing/file.txt'));

Avoid

// Bad: Message duplicates what code already says
session.logger.addError({
  code: 'FILE_NOT_FOUND',
  message: 'File not found',  // redundant
  context: { path: '/missing/file.txt' }
});

// Bad: Context duplicates message information
session.logger.addError({
  code: 'VALIDATION_ERROR',
  message: 'Invalid email format',
  context: { error: 'Invalid email format' }  // duplicates message
});

// Bad: Vague, non-descriptive error codes
session.logger.addError({
  code: 'NOT_FOUND',  // what wasn't found?
  context: { path: '/config.json' }
});

// Bad: Generic error codes
session.logger.addError({
  code: 'ERROR',  // too generic, provides no useful information
  context: { operation: 'file-read' }
});

Modules

  • McpBuilder - Build and register MCP tools with validation
  • McpSession - Handle MCP requests and critical error management
  • Logger - Independent error/warning collection and analysis

Requirements

  • Node.js 18+
  • TypeScript project (recommended)
  • MCP-compatible environment

License

MIT