π Ship Microsoft 365 Copilot connectors fast β from a single TypeSpec file to a runnable, production-ready project.
cocogen is a TypeSpec-driven generator (run via npx) for scaffolding Microsoft Graph External Connections (Microsoft 365 Copilot connectors) projects.
You bring: a .tsp schema.
You get: a runnable TypeScript or C# connector project with clear defaults, great structure, and a friendly CLI. β¨
Disclaimer This is a personal openβsource project and is not affiliated with, endorsed by, or supported by Microsoft. Microsoft, Microsoft 365, Copilot, and Graph are trademarks of Microsoft Corporation
- Schema-first workflow β define your external item once in TypeSpec.
- Runnables out of the box β provision connections, register schemas, and ingest data.
- People connectors ready β profile source registration and person entity mappings.
- Preview-aware β beta features like
contentCategoryare supported with a flag. - Swappable datasource β CSV included, plug in your own source easily.
- Safe updates β regenerate only schema-derived code via
cocogen update.
- β Create or update an external connection
- β Patch schema changes
- β Ingest items from CSV (or your own datasource)
- β Retry throttled requests with backoff + logging
- β Customize transforms without losing changes on update
End-user guide:
Tutorials:
Agent schema guidance:
cocogen expects a single βitem modelβ decorated with @coco.item() and a single ID property decorated with @coco.id.
Example (product):
import "@wictorwilen/cocogen";
using coco;
@coco.connection({
name: "Product catalog",
connectionId: "productcatalog",
connectionDescription: "External product catalog",
contentCategory: "uncategorized"
})
@coco.item()
model Product {
@coco.id
@coco.schemaDescription("Unique product identifier.")
@coco.search({ queryable: true, retrievable: true })
productId: string;
@coco.label("title")
@coco.schemaDescription("Display name shown in search results.")
@coco.search({ searchable: true, retrievable: true })
name: string;
@coco.label("url")
@coco.schemaDescription("Canonical product page URL.")
@coco.search({ retrievable: true })
url: string;
@coco.content({ type: "text" })
description: string;
}Start here:
Examples:
- Node.js 22+ (the generator targets Node 22 LTS)
- A TypeSpec schema file (
.tsp) - Generated projects support managed identity (preferred) or client secret auth.
No install needed:
npx @wictorwilen/cocogen@latest --helpGlobal install (system-wide command):
npm i -g @wictorwilen/cocogen
cocogen --help| Command | Purpose | Arguments |
|---|---|---|
init |
Create a starter TypeSpec file | --out <path>, --kind <content|people>, --prompt, --force |
validate |
Validate a TypeSpec schema | --tsp <path>, --json, --use-preview-features |
generate |
Generate a runnable connector project | --tsp <path>, --out <dir>, --lang <ts|dotnet|rest>, --name <name>, --data-format <csv|json|yaml|rest|custom>, --force, --use-preview-features |
update |
Regenerate TypeSpec-derived code in a generated project | --out <dir>, --tsp <path>, --use-preview-features |
emit |
Emit cocogen IR as JSON | --tsp <path>, --out <path>, --use-preview-features |
Notes:
--use-preview-featuresis required for Graph beta schemas (for example people connectors).
npx @wictorwilen/cocogen@latest init --promptinit also creates package.json and tspconfig.yaml in the same folder (if missing) so TypeSpec can resolve @wictorwilen/cocogen.
npx @wictorwilen/cocogen@latest validate --tsp ./schema.tspUse --use-preview-features for Graph beta schemas (for example people connectors).
npx @wictorwilen/cocogen@latest generate --tsp ./schema.tsp --out ./my-connectorNotes:
cocogenwill fail fast if the schema is invalid.- Beta features require
--use-preview-features. - Use
--data-format customto emit a stub datasource for custom backends.
After init, the project contains a cocogen.json that records which .tsp file to use.
When you change the schema, regenerate only the TypeSpec-derived files:
npx @wictorwilen/cocogen@latest update --out ./my-connectorOverride the TypeSpec entrypoint (also updates cocogen.json):
npx @wictorwilen/cocogen@latest update --out ./my-connector --tsp ../schema.tspcocogen intentionally separates:
src/<ConnectionName>/**β generated from TypeSpec (safe to overwrite oncocogen update)src/**(non-generated) β runtime code you can edit safely (should not change on update)
- Colors are enabled by default in TTYs.
- Set
NO_COLOR=1to disable colors/spinners. - In CI/non-TTY, spinners are automatically disabled.
MIT. See LICENSE.
Microsoft, Microsoft Graph, Microsoft 365, and Microsoft 365 Copilot are trademarks of Microsoft Corporation.
