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

@xava-labs/mcp

v0.2.1

Published

Model Context Protocol (MCP) server implementation for Cloudflare Workers

Readme

MCP Server Implementation for Cloudflare Workers

This package provides a Model Context Protocol (MCP) server implementation for Cloudflare Workers with Hono integration for HTTP routing.

Features

  • Hono Integration - Seamless integration with the Hono framework
  • Message Validation - Validates incoming messages against the MCP JSON-RPC schema
  • Server-Sent Events (SSE) - Provides real-time communication
  • Extensible Design - Easily extend the base server with custom routes and functionality

Architecture

The implementation is based on a Hono server that extends the base MCP server class:

  1. McpHonoServerDO - Base class that implements core MCP functionality with Hono
  2. Transport Layer - Handles communication between clients and the server
  3. Custom Extensions - Extend the base server with your own routes and implementations

Components

  • SSETransport - Implements the MCP Transport interface using Server-Sent Events
  • McpHonoServerDO - Base Hono server implementation for MCP

Setup

1. Create Your Custom MCP Server

Create a custom server by extending the McpHonoServerDO class:

import { McpHonoServerDO } from '@vibework/mcp/hono-server';
import { Implementation } from '@modelcontextprotocol/sdk/types.js';
import { Hono } from 'hono';

/**
 * Custom MCP Server implementation
 */
export class MyMcpServer extends McpHonoServerDO {
  /**
   * Implementation of the required abstract method
   */
  getImplementation(): Implementation {
    return {
      name: 'MyMcpServer',
      version: '1.0.0',
      vendor: 'Your Company'
    };
  }

  /**
   * Override setupRoutes to add custom routes
   */
  protected setupRoutes(app: Hono): void {
    // Call the parent implementation first to setup SSE and other MCP routes
    super.setupRoutes(app);
    
    // Add your custom routes
    app.get('/', (c) => {
      return c.text('Hello from MyMcpServer!');
    });

    // Add additional MCP-related routes
    app.get('/status', (c) => {
      const implementation = this.getImplementation();
      return c.json({
        name: implementation.name,
        version: implementation.version,
        status: 'running'
      });
    });
  }
  
  /**
   * You can optionally override configureServer to add custom tools
   */
  protected configureServer(server): void {
    // Register custom tools and methods
    server.tool('MyTool', 'My custom tool', async (params: any) => {
      // Implement your tool logic here
      return {
        content: [
          {
            type: 'text',
            text: 'Tool response'
          }
        ]
      };
    });
  }
}

2. Configure Your Worker

// worker.ts
import { MyMcpServer } from './my-mcp-server';

// Worker entrypoint
export default {
  fetch(request: Request, env: any, ctx: ExecutionContext) {
    // Create a new instance of your server and handle the request
    const server = new MyMcpServer();
    return server.fetch(request, env, ctx);
  }
};

3. Set Up Wrangler Configuration

If you're using Durable Objects or other Cloudflare features, configure them in your wrangler.jsonc:

{
  "name": "my-mcp-worker",
  "main": "src/worker.ts",
  "compatibility_date": "2023-10-30",
  "compatibility_flags": ["nodejs_compat"]
}

Client Connection Options

Clients can connect to your MCP server via Server-Sent Events (SSE):

import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";

// Connect with SSE
const sseUrl = new URL('https://your-worker.example.com/');
const transport = new SSEClientTransport(sseUrl);
const client = new Client({
  name: 'my-client',
  version: '1.0.0'
});

await client.connect(transport);

How It Works

  1. HTTP Request Flow:

    • Your custom server class inherits from McpHonoServerDO
    • The base class sets up the core MCP routes for SSE
    • You can add custom routes and functionality by overriding methods
  2. SSE Connection:

    • Client connects to the base path (e.g., /)
    • The server creates an SSE stream for communication
    • Server sends events to client; client sends requests via separate HTTP POST requests

Session Management

The server generates a unique session ID for SSE connections and passes it in the initial event.

Advanced Configuration

You can customize various aspects of the MCP server:

  1. Tool Registration - Override configureServer method to register custom tools
  2. Custom Routes - Override setupRoutes to add custom HTTP endpoints
  3. Request Handlers - Implement custom request handling logic

References