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

mcp-codegen

v0.0.6-beta

Published

The official MCP TypeScript SDK requires modeling MCP Tool Schema using a type-system called [Zod](https://zod.dev/). `mcp-codegen` allows you to leverage plain-old-TypeScript-objects.

Readme

mcp-codegen

The official MCP TypeScript SDK requires modeling MCP Tool Schema using a type-system called Zod. mcp-codegen allows you to leverage plain-old-TypeScript-objects.

Installation

npm install mcp-codegen

Build

This package is built using esbuild to transpile TypeScript to ES2015 (ES6) for broad compatibility. The build process generates both JavaScript and TypeScript declaration files.

npm run build:all

Exports

The package exports the following components:

  • McpRequired() - Decorator for required fields
  • McpOptional() - Decorator for optional fields
  • Format(format: string) - Decorator for field format specification
  • SchemaBuilder - Function to generate Zod schema from decorated classes
  • Primitives - TypeScript type for primitive values
  • ZOD_METADATA, ZOD_PROPS - Internal constants

Dependencies

  1. TypeScript experimental decorators (legacy only, TC39 coming soon)
  2. Reflect and reflect-metadata
  3. Zod to JSON Schema (Zod4 coming soon)

Getting Started

Decorate TypeScript Class

Build MCP Tool schema using TypeScript classes and decorators.

import { McpRequired, McpOptional, Format } from "mcp-codegen";

export class ToolCallInput {
	im_just_a_prop: string;

	@McpRequired()
	query: string;
	
	@McpRequired()
	async: boolean;

	@McpOptional()
	max?: number;
	
	@Format('bigint')
	@McpOptional()
	variance?: number;

	@McpOptional()
	queryId?: string;

	@Format('date-time')
	@McpOptional()
	createdAt?: string;
}

Generate Zod object and JSON Schema

import { ToolCallInput } from "decorated-typescript-class";
import { SchemaBuilder } from "mcp-codegen";
import zodToJsonSchema from "zod-to-json-schema";

const zodObject = SchemaBuilder(ToolCallInput);
const jsonSchema = zodToJsonSchema(z.object(zodObject));

Generated JSON Schema

{
  "type": "object",
  "properties": {
    "query": {
      "type": "string"
    },
    "async": {
      "type": "boolean"
    },
    "max": {
      "type": "number"
    },
    "variance": {
      "type": "integer",
      "format": "int64"
    },
    "queryId": {
      "type": "string"
    },
    "createdAt": {
      "type": "string",
      "format": "date-time"
    }
  },
  "required": [
    "query",
    "async"
  ],
  "additionalProperties": false,
  "$schema": "http://json-schema.org/draft-07/schema#"
}

Consume in MCP Tool Handler

import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";

new McpServer().registerTool(
    "example-tool",
    {
        title: "Example Tool",
        inputSchema: toolSchema         // Output of SchemaBuilder
    },
    (args: ToolCallInput): Promise<CallToolResult> => {
        return Promise.resolve({
            content: [
                {
                    type: "text",
                    text: `Results for query: ${args.query}`      // Required type
                },
                {
                    type: "text",
                    text: `Results requested: ${args.max || 100}` // Optional type
                }
            ]
        });
    }
)