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

zod-to-mcp-json

v1.0.1

Published

````markdown # zod-to-mcp-json

Readme

# zod-to-mcp-json

> 🔁 Convert Zod schemas into MCP-compatible JSON effortlessly.

[![npm version](https://badge.fury.io/js/zod-to-mcp-json.svg)](https://www.npmjs.com/package/zod-to-mcp-json)
[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](#license)

---

## 🧩 What is this?

`zod-to-mcp-json` is a small, fast, and powerful tool that converts [Zod](https://github.com/colinhacks/zod) schemas into a JSON format compatible with MCP (Model Configuration Protocol) or other schema-driven systems.

✅ Use it to:
- Export your Zod validation as JSON
- Share schemas between backend, frontend, or configuration tools
- Avoid duplicating type definitions manually

---

## 🚀 Installation

```bash
npm install zod-to-mcp-json
# or
yarn add zod-to-mcp-json

🛠️ Usage (Programmatic)

import { z } from "zod";
import { zodToMCP } from "zod-to-mcp-json";

const schema = z.object({
  id: z.string(),
  name: z.string(),
  age: z.number().default(18),
  status: z.enum(["active", "inactive"]),
  tags: z.array(z.string()),
  metadata: z.record(z.string())
});

const json = zodToMCP(schema);
console.log(JSON.stringify(json, null, 2));

✅ Output

{
  "type": "object",
  "properties": {
    "id": { "type": "string" },
    "name": { "type": "string" },
    "age": { "type": "number", "default": 18 },
    "status": { "type": "string", "enum": ["active", "inactive"] },
    "tags": { "type": "array", "items": { "type": "string" } },
    "metadata": { "type": "object", "additionalProperties": { "type": "string" } }
  },
  "required": ["id", "name", "status", "tags", "metadata"]
}

🔧 CLI Usage

npx zod-to-mcp-json ./example/schema.ts > schema.json

Your .ts file must:

  • Use ESM module style (export default)
  • Export a single Zod schema as the default export

Example:

// example/schema.ts
import { z } from "zod";

export default z.object({
  username: z.string(),
  age: z.number().optional()
});

📘 Supported Zod Types

| Zod Type | MCP Conversion | | --------------------- | ------------------------------ | | z.string() | type: "string" | | z.number() | type: "number" | | z.boolean() | type: "boolean" | | z.literal("x") | enum: ["x"] | | z.enum(["a", "b"]) | enum: [...] | | z.object({...}) | type: "object" | | z.array(z.string()) | type: "array" | | z.union([...]) | oneOf: [...] | | z.optional() | handled | | z.nullable() | anyOf: [..., {type: "null"}] | | z.default(...) | default: ... | | z.record() | additionalProperties: ... | | z.tuple([...]) | prefixItems |


📄 License

MIT License © [Your Name]


🙌 Contributing

PRs are welcome! If you'd like to support additional features like:

  • Custom error messages
  • CLI flags (--out, --pretty, etc.)
  • VS Code integration

Feel free to contribute or open issues.


⭐️ Give it a Star

If you find this useful, please give it a ⭐️ on GitHub!