-
Notifications
You must be signed in to change notification settings - Fork 72
Add MCPcat analytics and OpenTelemetry support #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- 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
WalkthroughGenerators and CLI now accept new boolean flags Changes
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
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. Comment |
There was a problem hiding this 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
📒 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)
| 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; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| 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); |
There was a problem hiding this 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.
🎯 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
--with-mcpcatCLI flag to enable product analytics for MCP servers--with-otelCLI flag to enable OTLP tracing and logging📝 Implementation Details
CLI Options: Added two new optional flags to control analytics/telemetry features
--with-mcpcat: Enables MCPcat product analytics--with-otel: Enables OpenTelemetry exportersCode Generation Updates:
.env.examplemcpcat@^0.1.5) topackage.jsonwhen neededArchitecture Improvements:
CliOptionsobject instead of individual parametersConfiguration Examples
MCPcat Only
Generates:
mcpcat.track(server, process.env.MCPCAT_PROJECT_ID || null);OpenTelemetry Only
Generates OTLP exporter configuration without MCPcat features
Combined Configuration
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.ioOTLP_ENDPOINT: OpenTelemetry collector endpointTesting
Breaking Changes
None - all new features are opt-in via CLI flags
Related Links
Summary by CodeRabbit