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

tiny-mcp-server

v0.0.1

Published

A tiny MCP server implementation for Bun

Readme

tiny-mcp-server

A minimal MCP server implementation for Bun. No dependencies, ~150 lines.

Install

bun add tiny-mcp-server

Usage

import { registerTool, registerResource, registerResourceTemplate, sample, serve } from "tiny-mcp-server";

// Register a tool
registerTool(
  "echo",
  "Echoes back the provided message",
  {
    type: "object",
    properties: {
      message: { type: "string", description: "Message to echo back" }
    },
    required: ["message"]
  },
  async ({ message }) => ({ echoed: message })
);

// Register a resource
registerResource(
  "info://server",
  "Server Info",
  "Basic server information",
  "application/json",
  async () => JSON.stringify({ name: "my-server", version: "1.0.0" })
);

// Register a resource template
registerResourceTemplate(
  "env://{name}",
  "Environment Variable",
  "Read an environment variable",
  "text/plain",
  async ({ name }) => process.env[name!] || ""
);

// Use sampling inside a tool
registerTool(
  "summarize",
  "Summarize text using the client's LLM",
  {
    type: "object",
    properties: { text: { type: "string" } },
    required: ["text"]
  },
  async ({ text }) => {
    const summary = await sample({
      messages: [{ role: "user", content: { type: "text", text: `Summarize: ${text}` } }],
      maxTokens: 200
    });
    return { summary };
  }
);

serve({ name: "my-server", version: "1.0.0" });

Run

bun server.ts

Test

# Initialize
echo '{"jsonrpc":"2.0","id":1,"method":"initialize"}' | bun server.ts

# List tools
echo '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' | bun server.ts

# Call a tool
echo '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"echo","arguments":{"message":"hello"}}}' | bun server.ts

# List resources
echo '{"jsonrpc":"2.0","id":1,"method":"resources/list"}' | bun server.ts

# Read a resource
echo '{"jsonrpc":"2.0","id":1,"method":"resources/read","params":{"uri":"info://server"}}' | bun server.ts

# Read a resource template
echo '{"jsonrpc":"2.0","id":1,"method":"resources/read","params":{"uri":"env://HOME"}}' | bun server.ts

API

registerTool(name, description, schema, handler)

Register a tool that can be called by MCP clients.

| Param | Type | Description | |-------|------|-------------| | name | string | Tool identifier | | description | string | Human-readable description | | schema | object | JSON Schema for input validation | | handler | (params) => Promise<unknown> | Async function to execute |

registerResource(uri, name, description, mimeType, handler)

Register a resource that can be read by MCP clients.

| Param | Type | Description | |-------|------|-------------| | uri | string | Resource URI (e.g. file://config.json) | | name | string | Human-readable name | | description | string | Human-readable description | | mimeType | string | Content type (e.g. application/json) | | handler | () => Promise<string \| Uint8Array> | Async function returning content (text or binary) |

Text resources return strings, binary resources return Uint8Array (auto base64 encoded):

// Binary resource
registerResource(
  "image://logo",
  "Logo",
  "Company logo",
  "image/png",
  async () => Bun.file("logo.png").bytes()
);

registerResourceTemplate(uriTemplate, name, description, mimeType, handler)

Register a dynamic resource with URI variables.

| Param | Type | Description | |-------|------|-------------| | uriTemplate | string | URI pattern with {var} placeholders | | name | string | Human-readable name | | description | string | Human-readable description | | mimeType | string | Content type | | handler | (vars) => Promise<string \| Uint8Array> | Async function receiving extracted variables |

sample(options)

Request an LLM completion from the client. Can only be used inside tool/resource handlers after serve() is running.

| Param | Type | Description | |-------|------|-------------| | options.messages | SampleMessage[] | Conversation messages | | options.maxTokens | number | Max tokens to generate (default: 1000) | | options.temperature | number | Sampling temperature (optional) | | options.systemPrompt | string | System prompt (optional) |

Returns Promise<string> with the assistant's response text.

const response = await sample({
  messages: [
    { role: "user", content: { type: "text", text: "Hello!" } }
  ],
  maxTokens: 100
});

serve(options?)

Start the MCP server on stdio.

| Param | Type | Description | |-------|------|-------------| | options.name | string | Server name (default: "mcp-server") | | options.version | string | Server version (default: "1.0.0") |

License

MIT