|
| 1 | +# Add optional MCPcat analytics scaffolding (`--with-mcpcat`) to generated MCP servers |
| 2 | + |
| 3 | +> **TL;DR**: This PR adds an **opt-in** flag to scaffold privacy-safe analytics wiring for MCPcat in projects generated by `openapi-mcp-generator`. |
| 4 | +
|
| 5 | +## Summary |
| 6 | +This PR introduces a `--with-mcpcat` CLI flag that scaffolds: |
| 7 | +- A tiny analytics shim to emit initialize/tool-call events. |
| 8 | +- A default **local redaction** helper to scrub sensitive data before export. |
| 9 | +- Minimal config via environment variables. |
| 10 | +No behavior changes unless the flag and env vars are set. |
| 11 | + |
| 12 | +## Motivation |
| 13 | +- Make freshly generated MCP servers **observable in minutes**. |
| 14 | +- Encourage **privacy-by-default** analytics patterns. |
| 15 | +- Reduce copy/paste wiring; standardize event shape (operationId, path, duration, status). |
| 16 | + |
| 17 | +## Changes |
| 18 | +### CLI |
| 19 | +- `generate` accepts `--with-mcpcat` (default: off). |
| 20 | + |
| 21 | +### Template files (added conditionally) |
| 22 | +- `src/analytics/mcpcat.ts` – lazy import + safe no-op if SDK absent. |
| 23 | +- `src/analytics/redact.ts` – OpenAPI-aware heuristics (e.g., `*token*`, `password`, `apiKey`, `authorization`, `email`). |
| 24 | +- `src/analytics/config.ts` – reads env: |
| 25 | + - `MCPCAT_ENABLED=true|false` (default `false`) |
| 26 | + - `MCPCAT_PROJECT_ID=<id>` |
| 27 | + - `MCPCAT_ENDPOINT=<optional override>` |
| 28 | + - `MCPCAT_SAMPLE_RATE=1.0` (0–1) |
| 29 | + |
| 30 | +### Server wiring |
| 31 | +- Hooks server `.initialize` and each tool invocation to record: |
| 32 | + - `operationId`, HTTP `method`, `path` |
| 33 | + - redacted `args` |
| 34 | + - `outcome` (`ok`/`error`) + truncated error message |
| 35 | + - `duration_ms` |
| 36 | + |
| 37 | +### Docs |
| 38 | +- Adds a “Enable analytics (MCPcat)” section to generated README with privacy notes and quickstart. |
| 39 | + |
| 40 | +## Implementation Notes |
| 41 | +- **Compile-time optional**: no imports unless flag is used. |
| 42 | +- **Runtime safe**: try/catch around SDK import → graceful no-op if not installed. |
| 43 | +- **Transport-agnostic**: compatible with stdio, SSE/web, and StreamableHTTP templates. |
| 44 | +- **Edge-friendly**: avoids Node-only APIs in scaffolding to support edge runtimes (e.g., Workers). |
0 commit comments