Skip to content

Conversation

@naji247
Copy link

@naji247 naji247 commented Oct 2, 2025

🎯 Add MCPcat Analytics and OpenTelemetry Support

Overview

This PR introduces optional analytics and telemetry capabilities to the OpenAPI MCP Generator through integration with MCPcat and OpenTelemetry (OTLP). These features enable developers to gain insights into their MCP server usage and debug issues more effectively.

What's Changed

✨ New Features

  • MCPcat Analytics Integration: Added --with-mcpcat CLI flag to enable product analytics for MCP servers
  • OpenTelemetry Support: Added --with-otel CLI flag to enable OTLP tracing and logging
  • Flexible Configuration: Support for MCPcat-only, OTEL-only, or combined configurations

📝 Implementation Details

  • CLI Options: Added two new optional flags to control analytics/telemetry features

    • --with-mcpcat: Enables MCPcat product analytics
    • --with-otel: Enables OpenTelemetry exporters
  • Code Generation Updates:

    • Generate MCPcat tracking code in server when enabled
    • Include MCPcat environment variables in .env.example
    • Add MCPcat dependency (mcpcat@^0.1.5) to package.json when needed
    • Generate appropriate tracking configurations based on selected options
  • Architecture Improvements:

    • Refactored generator functions to accept full CliOptions object instead of individual parameters
    • Converted module exports to type-only exports for better TypeScript compatibility

Configuration Examples

MCPcat Only

openapi-to-mcp --with-mcpcat

Generates: mcpcat.track(server, process.env.MCPCAT_PROJECT_ID || null);

OpenTelemetry Only

openapi-to-mcp --with-otel

Generates OTLP exporter configuration without MCPcat features

Combined Configuration

openapi-to-mcp --with-mcpcat --with-otel

Generates both MCPcat tracking and OTLP exporters

Environment Variables

When enabled, the following environment variables are added to .env.example:

  • MCPCAT_PROJECT_ID: Project ID from mcpcat.io
  • OTLP_ENDPOINT: OpenTelemetry collector endpoint

Testing

  • ✅ Verified code generation with all three configuration modes
  • ✅ Ensured backward compatibility (features are opt-in)
  • ✅ Validated TypeScript compilation with generated code

Breaking Changes

None - all new features are opt-in via CLI flags

Related Links

Summary by CodeRabbit

  • New Features
    • Added CLI flags --with-mcpcat and --with-otel to enable optional telemetry.
    • Telemetry setup can be included in generated server code when enabled.
    • Generated .env.example and package.json include telemetry-related variables and dependencies when flags are used.
  • Refactor
    • Public API exports clarified by separating value and type exports.
  • Documentation
    • README updated with Analytics & Telemetry usage and env variable guidance.

    - Add --with-mcpcat and --with-otel CLI options for optional analytics and telemetry
    - Generate MCPcat tracking code in server when enabled
    - Include MCPcat environment variables in .env.example when configured
    - Add MCPcat dependency to generated package.json when enabled
    - Support both MCPcat-only, OTEL-only, and combined configurations
    - Update generator functions to accept full CliOptions object
    - Convert module exports to type-only exports where appropriate
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 2, 2025

Walkthrough

Generators and CLI now accept new boolean flags withMcpcat and withOtel. Package.json, env example, and generated server code conditionally include mcpcat/OTEL-related dependencies, env variables, and tracking snippets based on those options. index.ts exports adjusted and options passed through.

Changes

Cohort / File(s) Summary of changes
CLI options & public API
src/index.ts, src/types/index.ts
Added withMcpcat?: boolean and withOtel?: boolean to CliOptions. index.ts wires new CLI flags, passes full options to generators, and separates value/type exports.
Env example generation
src/generator/env-file.ts
generateEnvExample(securitySchemes?, options?: CliOptions) — conditionally appends MCPcat and OpenTelemetry env sections (MCPCAT_PROJECT_ID, OTLP_ENDPOINT) when flags are enabled.
Package.json generation
src/generator/package-json.ts
generatePackageJson(serverName, serverVersion, options: CliOptions) — derives transport from options.transport; conditionally adds mcpcat dependency when withMcpcat or withOtel is true; web-transport logic unchanged.
Server tracking integration
src/generator/server-code.ts
Adds helper to generate MCPcat/OTEL tracking snippet, conditionally imports mcpcat and injects tracking setup into generated server code when enabled.
Docs
README.md
Documentation for new CLI flags and Analytics & Telemetry section describing MCPcat and OpenTelemetry usage and env vars.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User as CLI User
  participant CLI as CLI (options)
  participant GenPkg as generatePackageJson
  participant GenEnv as generateEnvExample
  participant GenSrv as server-code generator
  participant mcpcat as mcpcat (lib)

  User->>CLI: run CLI with options (transport, withMcpcat, withOtel)
  CLI->>GenPkg: pass options
  GenPkg-->>CLI: package.json (includes mcpcat dep if enabled)

  CLI->>GenEnv: pass securitySchemes + options
  GenEnv-->>CLI: .env.example (+MCPCAT_/OTLP_ vars if enabled)

  CLI->>GenSrv: pass options
  alt tracking enabled (withMcpcat or withOtel)
    GenSrv->>mcpcat: add import (if needed)
    GenSrv-->>CLI: server code + tracking snippet
  else
    GenSrv-->>CLI: server code (no tracking)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • harsha-iiiv

Poem

I twitch my ears at flags anew,
Two toggles—mcpcat and otel too.
I hop through generators, stitch and play,
Env, package, server—traces on the way.
A tiny rabbit cheer for telemetry day. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly captures the primary change by stating the addition of MCPcat analytics and OpenTelemetry support, which directly reflects the core purpose of the pull request without unnecessary details or ambiguity.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 518b885 and aaec9c7.

📒 Files selected for processing (1)
  • README.md (4 hunks)
✅ Files skipped from review due to trivial changes (1)
  • README.md

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8ee9fc3 and 518b885.

📒 Files selected for processing (5)
  • src/generator/env-file.ts (2 hunks)
  • src/generator/package-json.ts (2 hunks)
  • src/generator/server-code.ts (4 hunks)
  • src/index.ts (4 hunks)
  • src/types/index.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
src/generator/env-file.ts (1)
src/types/index.ts (1)
  • CliOptions (17-42)
src/index.ts (1)
src/generator/env-file.ts (1)
  • generateEnvExample (15-79)
src/generator/server-code.ts (1)
src/types/index.ts (1)
  • CliOptions (17-42)
src/generator/package-json.ts (1)
src/types/index.ts (1)
  • CliOptions (17-42)

Comment on lines 11 to 19
export function generatePackageJson(
serverName: string,
serverVersion: string,
transportType: string = 'stdio'
options: CliOptions
): string {
const transportType = options.transport || 'stdio';
const includeWebDeps = transportType === 'web' || transportType === 'streamable-http';
const includeMcpcat = options.withMcpcat || options.withOtel;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Restore backward-compatible generatePackageJson signature

Previously this helper accepted either two args (defaulting transport to 'stdio') or an explicit transport string. Making the third argument mandatory—and typing it as the full CliOptions—breaks existing programmatic consumers who relied on the old call shape. Please keep the third parameter optional and scoped to the properties this function actually uses so downstream builds keep compiling.

-export function generatePackageJson(
-  serverName: string,
-  serverVersion: string,
-  options: CliOptions
-): string {
-  const transportType = options.transport || 'stdio';
+export function generatePackageJson(
+  serverName: string,
+  serverVersion: string,
+  options: Pick<CliOptions, 'transport' | 'withMcpcat' | 'withOtel'> = {}
+): string {
+  const transportType = options.transport ?? 'stdio';
   const includeWebDeps = transportType === 'web' || transportType === 'streamable-http';
-  const includeMcpcat = options.withMcpcat || options.withOtel;
+  const includeMcpcat = Boolean(options.withMcpcat || options.withOtel);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export function generatePackageJson(
serverName: string,
serverVersion: string,
transportType: string = 'stdio'
options: CliOptions
): string {
const transportType = options.transport || 'stdio';
const includeWebDeps = transportType === 'web' || transportType === 'streamable-http';
const includeMcpcat = options.withMcpcat || options.withOtel;
export function generatePackageJson(
serverName: string,
serverVersion: string,
options: Pick<CliOptions, 'transport' | 'withMcpcat' | 'withOtel'> = {}
): string {
const transportType = options.transport ?? 'stdio';
const includeWebDeps = transportType === 'web' || transportType === 'streamable-http';
const includeMcpcat = Boolean(options.withMcpcat || options.withOtel);

Copy link
Owner

@harsha-iiiv harsha-iiiv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code style issues found in 3 files. Run Prettier with --write to fix.

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.

2 participants