Merge 10e8e8deaabf86dfa46c48c7aaa4735f93ce1d1f into 8ee9fc383dedff93043ed8a67107ee6691f19642

This commit is contained in:
Addison Waldow 2026-02-12 01:53:04 +00:00 committed by GitHub
commit 550911580c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 3 deletions

View File

@ -3,22 +3,28 @@
> **TL;DR**: This PR adds an **opt-in** flag to scaffold privacy-safe analytics wiring for MCPcat in projects generated by `openapi-mcp-generator`.
## Summary
This PR introduces a `--with-mcpcat` CLI flag that scaffolds:
- A tiny analytics shim to emit initialize/tool-call events.
- A default **local redaction** helper to scrub sensitive data before export.
- Minimal config via environment variables.
No behavior changes unless the flag and env vars are set.
No behavior changes unless the flag and env vars are set.
## Motivation
- Make freshly generated MCP servers **observable in minutes**.
- Encourage **privacy-by-default** analytics patterns.
- Reduce copy/paste wiring; standardize event shape (operationId, path, duration, status).
## Changes
### CLI
- `generate` accepts `--with-mcpcat` (default: off).
### Template files (added conditionally)
- `src/analytics/mcpcat.ts` lazy import + safe no-op if SDK absent.
- `src/analytics/redact.ts` OpenAPI-aware heuristics (e.g., `*token*`, `password`, `apiKey`, `authorization`, `email`).
- `src/analytics/config.ts` reads env:
@ -28,6 +34,7 @@ No behavior changes unless the flag and env vars are set.
- `MCPCAT_SAMPLE_RATE=1.0` (01)
### Server wiring
- Hooks server `.initialize` and each tool invocation to record:
- `operationId`, HTTP `method`, `path`
- redacted `args`
@ -35,9 +42,11 @@ No behavior changes unless the flag and env vars are set.
- `duration_ms`
### Docs
- Adds a “Enable analytics (MCPcat)” section to generated README with privacy notes and quickstart.
## Implementation Notes
- **Compile-time optional**: no imports unless flag is used.
- **Runtime safe**: try/catch around SDK import → graceful no-op if not installed.
- **Transport-agnostic**: compatible with stdio, SSE/web, and StreamableHTTP templates.

View File

@ -19,6 +19,9 @@ export function generateEnvExample(
# Server configuration
PORT=3000
LOG_LEVEL=info
# If you have a server outside the servers list from OpenAPI, define it here.
# Otherwise, omit this.
API_BASE_URL=your_api_base_url_here
`;

View File

@ -23,7 +23,7 @@ export function generatePackageJson(
files: ['build', 'src'],
scripts: {
start: 'node build/index.js',
build: 'tsc && chmod 755 build/index.js',
build: 'tsc && shx chmod 755 build/index.js',
typecheck: 'tsc --noEmit',
prestart: 'npm run build',
},
@ -40,6 +40,7 @@ export function generatePackageJson(
devDependencies: {
'@types/node': '^22.15.2',
typescript: '^5.8.3',
shx: '^0.4.0',
},
};

View File

@ -130,7 +130,9 @@ interface McpToolDefinition {
*/
export const SERVER_NAME = "${serverName}";
export const SERVER_VERSION = "${serverVersion}";
export const API_BASE_URL = "${determinedBaseUrl || ''}";
// Base URL for the API, can be set via environment variable or determined from OpenAPI spec
export const API_BASE_URL = process.env.API_BASE_URL || "${determinedBaseUrl || ''}";
console.error("API_BASE_URL is set to:", API_BASE_URL);
/**
* MCP Server instance