Skip to content

Conversation

@TheIsrael1
Copy link
Contributor

@TheIsrael1 TheIsrael1 commented Dec 29, 2025

Summary

Enables Mastra packages to ship embedded documentation that AI coding agents can read directly from node_modules. This allows agents to understand the framework as if they were its creators.

What's Included

Infrastructure

  • scripts/generate-package-docs.ts - Shared script to generate docs from MDX sources
  • SOURCE_MAP.json - Machine-readable index mapping exports → types → implementation (with line numbers)
  • SKILL.md - Claude Skills entry point for automatic discovery
  • EMBEDDED_DOCS.md - Guide for adding embedded docs to any package

Package Coverage (47 packages)

  • Core: memory, rag, evals, mcp, server, auth, deployer, cli, client-js, loggers
  • Voice: 13 providers (openai, deepgram, elevenlabs, etc.)
  • Stores: 22 providers (pg, libsql, pinecone, etc.)

Each package gets:

  • docs.config.json - Topic/source file mappings
  • postbuild script - Auto-generates dist/docs/ after build

How It Works

  1. MDX docs are transformed to clean Markdown (Docusaurus components stripped, code blocks preserved)
  2. Code references are auto-discovered from imports/usage and linked to SOURCE_MAP
  3. Docs are generated to dist/docs/ on every build
  4. Published to npm alongside the package

Example Output

node_modules/@mastra/core/dist/docs/
├── SKILL.md # Agent entry point
├── README.md # Navigation
├── SOURCE_MAP.json # Export → file mappings
├── agents/
│ ├── 01-overview.md
│ └── ...
└── tools/
└── ...

Related

Summary by CodeRabbit

  • New Features

    • Embedded package documentation is now automatically generated and included in published npm packages, making documentation accessible directly within package distributions and enabling integration with AI tools and Claude Skills.
  • Documentation

    • Added comprehensive embedded documentation guide for generating and integrating documentation from source files into package distributions.

✏️ Tip: You can customize this high-level summary in your review settings.

This proposal outlines a strategy to embed documentation inside published
npm packages so coding agents can understand and use Mastra effectively.

Key ideas:
- Per-package docs/ folder with topic-organized content
- SOURCE_MAP.json for machine-readable code navigation
- Links to .d.ts (types) and .js (implementation) files
- Generated from existing MDX documentation

The goal is to enable AI coding agents to write Mastra code as if they
were the framework creators, with full access to version-matched docs
and readable source code.
@changeset-bot
Copy link

changeset-bot bot commented Dec 29, 2025

🦋 Changeset detected

Latest commit: be73428

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 70 packages
Name Type
@mastra/core Patch
@mastra/memory Patch
@mastra/rag Patch
@mastra/evals Patch
@mastra/deployer Patch
@mastra/deployer-cloudflare Patch
@mastra/deployer-netlify Patch
@mastra/deployer-vercel Patch
@mastra/server Patch
@mastra/mcp Patch
@mastra/client-js Patch
@mastra/ai-sdk Patch
@mastra/auth Patch
@mastra/loggers Patch
@mastra/observability Patch
@mastra/otel-bridge Patch
@mastra/otel-exporter Patch
@mastra/arize Patch
@mastra/braintrust Patch
@mastra/langfuse Patch
@mastra/langsmith Patch
@mastra/posthog Patch
@mastra/libsql Patch
@mastra/pg Patch
@mastra/upstash Patch
@mastra/mongodb Patch
@mastra/astra Patch
@mastra/chroma Patch
@mastra/clickhouse Patch
@mastra/cloudflare Patch
@mastra/cloudflare-d1 Patch
@mastra/convex Patch
@mastra/couchbase Patch
@mastra/duckdb Patch
@mastra/dynamodb Patch
@mastra/elasticsearch Patch
@mastra/lance Patch
@mastra/mssql Patch
@mastra/opensearch Patch
@mastra/pinecone Patch
@mastra/qdrant Patch
@mastra/s3vectors Patch
@mastra/turbopuffer Patch
@mastra/vectorize Patch
@mastra/fastembed Patch
@mastra/express Patch
@mastra/hono Patch
@mastra/voice-azure Patch
@mastra/voice-cloudflare Patch
@mastra/voice-deepgram Patch
@mastra/voice-elevenlabs Patch
@mastra/voice-google Patch
@mastra/voice-google-gemini-live Patch
@mastra/voice-murf Patch
@mastra/voice-openai Patch
@mastra/voice-openai-realtime Patch
@mastra/voice-playai Patch
@mastra/voice-sarvam Patch
@mastra/voice-speechify Patch
@mastra/mcp-docs-server Patch
@mastra/react Patch
@mastra/dane Patch
@mastra/auth-clerk Patch
@mastra/auth-workos Patch
@mastra/longmemeval Patch
@mastra/agent-builder Patch
mastra Patch
@mastra/deployer-cloud Patch
@mastra/playground-ui Patch
create-mastra Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Dec 29, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
assistant-ui Ready Ready Preview, Comment Dec 30, 2025 10:49pm
mastra-docs Ready Ready Preview, Comment Dec 30, 2025 10:49pm
mastra-docs-1.x Building Building Preview, Comment Dec 30, 2025 10:49pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 29, 2025

Important

Review skipped

Too many files!

133 files out of 283 files are above the max files limit of 150.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This PR introduces a comprehensive embedded documentation generation system for the Mastra monorepo. It adds tooling to generate machine-readable documentation (SKILL.md, SOURCE_MAP.json) from MDX source files and package exports, enabling documentation to be embedded within published npm packages for use in AI tools and MCP integrations.

Changes

Cohort / File(s) Summary
Documentation & Infrastructure
EMBEDDED_DOCS.md, packages/core/docs/EMBEDDED_DOCS_PROPOSAL.md
Adds embedded docs guide detailing generation process, structure of generated artifacts (SKILL.md, SOURCE_MAP.json), configuration format, build pipeline integration, and usage scenarios for Claude Skills and MCP tools.
Core Generation Script
scripts/generate-package-docs.ts
Implements TypeScript CLI script for automating docs generation across packages. Scans dist exports, generates SOURCE_MAP.json mapping exports to source locations, transforms MDX to Markdown, extracts code references from imports and patterns, generates per-topic Markdown files, and produces SKILL.md/README.md with export mappings.
Root Package Configuration
package.json
Adds new generate:docs npm script entry at repository root to invoke the docs generation script.
Client SDK Package
client-sdks/client-js/docs.config.json, client-sdks/client-js/package.json
Defines "Client SDK" documentation skill with reference files and adds postbuild script hook.
Core Package
packages/core/docs.config.json, packages/core/package.json
Configures comprehensive documentation skill covering Agents, Tools, Workflows, Streaming, Observability, and Processors topics; adds postbuild and generate:docs scripts.
Auth/CLI/Deployer/Evals/Loggers/MCP/Memory/RAG/Server Packages
packages/{auth,cli,deployer,evals,loggers,mcp,memory,rag,server}/docs.config.json, packages/{auth,cli,deployer,evals,loggers,mcp,memory,rag,server}/package.json
Adds identical pattern across packages: docs.config.json defining skill metadata and topic-to-source mappings, plus postbuild scripts invoking docs generation.
Storage Provider Packages (Stores)
stores/{astra,chroma,clickhouse,cloudflare,cloudflare-d1,convex,couchbase,duckdb,dynamodb,elasticsearch,lance,libsql,mongodb,mssql,opensearch,pg,pinecone,qdrant,s3vectors,turbopuffer,upstash,vectorize}/docs.config.json, stores/{...}/package.json
Consistently adds storage/vector provider documentation skills with single "Storage" topic and postbuild generation hooks across 22 store implementations.
Voice Provider Packages
voice/{azure,cloudflare,deepgram,elevenlabs,gladia,google,google-gemini-live-api,murf,openai,openai-realtime-api,playai,sarvam,speechify}/docs.config.json, voice/{...}/package.json
Adds "Voice" topic documentation skills for 13 voice provider packages with common sourceFiles pattern and postbuild generation scripts.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~90 minutes

The script scripts/generate-package-docs.ts contains substantial logic for export scanning, source mapping, MDX transformation, and code reference extraction requiring detailed review. While the 80+ configuration and postbuild additions follow homogeneous patterns (reducing per-file effort), their cumulative volume and the need to verify configuration consistency across all packages increases overall complexity.

Possibly related PRs

  • PR #10741 adds @mastra/elasticsearch package — directly coordinates with this PR's elasticsearch docs configuration and postbuild script generation for the same package.

Suggested reviewers

  • LekoArts
  • bookercodes
  • abhiaiyer91

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 58.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: embedded documentation for AI coding agents' clearly and accurately describes the main objective of the PR—adding embedded documentation infrastructure for AI agents. It follows imperative mood conventions, uses proper capitalization with the conventional 'feat:' prefix, and is concise at 49 characters.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 29, 2025

🚨 Redirect Validation Failed

The redirect validation found issues in vercel.json (duplicate sources or broken destination links).

Action Required: Review and fix the redirect configuration.

📋 View workflow logs for details

- Add Claude Skills support via SKILL.md (Anthropic spec)
- Add MCP tools for @mastra/mcp-docs-server enhancement
- Remove vendor-specific approaches (universal only)
- Add architecture diagram showing Skills + MCP integration
- Update implementation plan with Skills and MCP phases
- Add progressive disclosure explanation
- Reference Anthropic Skills documentation
- Add scripts/generate-package-docs.ts that:
  - Analyzes dist/ to build SOURCE_MAP.json with 215 exports
  - Generates SKILL.md with Anthropic-compatible YAML frontmatter
  - Transforms MDX docs to clean Markdown
  - Adds code links to types and implementation files

- Generate embedded docs:
  - SKILL.md - Claude Skills entry point
  - README.md - Navigation index
  - SOURCE_MAP.json - Machine-readable export map
  - agents/*.md - 7 agent topic docs
  - tools/*.md - 2 tool topic docs
  - workflows/*.md - 4 workflow topic docs
  - streaming/*.md - 2 streaming topic docs

- Update package.json:
  - Add 'docs' to files array for npm publish
  - Add generate:docs script

This completes Phase 1 items 1-4 of the embedded docs proposal.
Loop until no more <!-- patterns remain to prevent incomplete
sanitization that could leave malformed HTML fragments.
- Move script to scripts/generate-package-docs.ts (shared across packages)
- Add docs.config.json for @mastra/core with 8 topics
- Auto-discover code references from MDX imports/usage
- Protect code blocks during MDX transformation
- Fix PropertiesTable and JSX expression handling
- Add mastra, server, observability, processors topics
- Generate 44 markdown files across all topics
- Add postbuild script to generate docs to dist/docs/
- Remove committed generated docs (now generated at build time)
- Add EMBEDDED_DOCS.md guide for adding docs to other packages
- Update turbo.json with generate:docs task
- Update package.json files array to include docs folder
@abhiaiyer91 abhiaiyer91 merged commit bc72b52 into main Dec 31, 2025
43 of 44 checks passed
@abhiaiyer91 abhiaiyer91 deleted the feat/embedded-docs-proposal branch December 31, 2025 00:39
TheIsrael1 added a commit that referenced this pull request Jan 2, 2026
Adds 5 new MCP tools to read embedded documentation from installed @mastra/* packages:

- listInstalledMastraPackages: Discover packages with embedded docs
- readMastraSourceMap: Read export mappings from SOURCE_MAP.json
- findMastraExport: Get type definitions and implementation for specific exports
- readMastraEmbeddedDocs: Read topic documentation
- searchMastraEmbeddedDocs: Search across all embedded docs

These tools enable AI coding agents to understand Mastra packages by reading
documentation directly from node_modules, complementing the embedded docs
infrastructure merged in #11472.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@anowardear062-svg
Copy link

Thanks for the update

astout55555 pushed a commit to astout55555/mastra that referenced this pull request Jan 6, 2026
## Summary

Enables Mastra packages to ship embedded documentation that AI coding
agents can read directly from `node_modules`. This allows agents to
understand the framework as if they were its creators.

## What's Included

### Infrastructure
- **`scripts/generate-package-docs.ts`** - Shared script to generate
docs from MDX sources
- **`SOURCE_MAP.json`** - Machine-readable index mapping exports → types
→ implementation (with line numbers)
- **`SKILL.md`** - Claude Skills entry point for automatic discovery
- **`EMBEDDED_DOCS.md`** - Guide for adding embedded docs to any package

### Package Coverage (47 packages)
- **Core:** memory, rag, evals, mcp, server, auth, deployer, cli,
client-js, loggers
- **Voice:** 13 providers (openai, deepgram, elevenlabs, etc.)
- **Stores:** 22 providers (pg, libsql, pinecone, etc.)

Each package gets:
- `docs.config.json` - Topic/source file mappings
- `postbuild` script - Auto-generates `dist/docs/` after build

## How It Works

1. MDX docs are transformed to clean Markdown (Docusaurus components
stripped, code blocks preserved)
2. Code references are auto-discovered from imports/usage and linked to
SOURCE_MAP
3. Docs are generated to `dist/docs/` on every build
4. Published to npm alongside the package

## Example Output
node_modules/@mastra/core/dist/docs/
├── SKILL.md # Agent entry point
├── README.md # Navigation
├── SOURCE_MAP.json # Export → file mappings
├── agents/
 │ ├── 01-overview.md
 │ └── ...
└── tools/
└── ...


## Related

- Follow-up PR for MCP tools: mastra-ai#11488

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Embedded package documentation is now automatically generated and
included in published npm packages, making documentation accessible
directly within package distributions and enabling integration with AI
tools and Claude Skills.

* **Documentation**
* Added comprehensive embedded documentation guide for generating and
integrating documentation from source files into package distributions.

<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants