diff --git a/.github/PULL_REQUEST_TEMPLATE/mcpcat.md b/.github/PULL_REQUEST_TEMPLATE/mcpcat.md index d3c1a4f..8c76063 100644 --- a/.github/PULL_REQUEST_TEMPLATE/mcpcat.md +++ b/.github/PULL_REQUEST_TEMPLATE/mcpcat.md @@ -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` (0–1) ### 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. diff --git a/src/generator/env-file.ts b/src/generator/env-file.ts index d1cc591..1b26c64 100644 --- a/src/generator/env-file.ts +++ b/src/generator/env-file.ts @@ -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 `; diff --git a/src/generator/package-json.ts b/src/generator/package-json.ts index ef97985..20443a1 100644 --- a/src/generator/package-json.ts +++ b/src/generator/package-json.ts @@ -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', }, }; diff --git a/src/generator/server-code.ts b/src/generator/server-code.ts index 6b6a447..a4a39fe 100644 --- a/src/generator/server-code.ts +++ b/src/generator/server-code.ts @@ -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