From 454c0ce7f2104d8fcb5925c1b3b4148d65181cdb Mon Sep 17 00:00:00 2001 From: Dave Kerr Date: Fri, 16 May 2025 13:47:24 -0400 Subject: [PATCH] cli flags for user-agent and oauth creds delivery mechanism --- src/generator/server-code.ts | 3 ++- src/index.ts | 8 ++++++++ src/types/index.ts | 4 ++++ src/utils/security.ts | 21 +++++++++++++++------ 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/generator/server-code.ts b/src/generator/server-code.ts index 3059591..8b4476c 100644 --- a/src/generator/server-code.ts +++ b/src/generator/server-code.ts @@ -35,7 +35,8 @@ export function generateMcpServerCode( // Generate code for API tool execution const executeApiToolFunctionCode = generateExecuteApiToolFunction( - api.components?.securitySchemes + api.components?.securitySchemes, + options, ); // Generate code for request handlers diff --git a/src/index.ts b/src/index.ts index a22d3a3..626c150 100644 --- a/src/index.ts +++ b/src/index.ts @@ -68,6 +68,14 @@ program 'Port for web or streamable-http transport (default: 3000)', (val) => parseInt(val, 10) ) + .option( + '-a, --auth-credentials-delivery ', + 'Delivery method for auth credentials (default: "header")' + ) + .option( + '-u, --user-agent ', + 'User agent for the MCP server (default: "")' + ) .option('--force', 'Overwrite existing files without prompting') .version('2.0.0'); // Match package.json version diff --git a/src/types/index.ts b/src/types/index.ts index c945341..b26e578 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -29,6 +29,10 @@ export interface CliOptions { transport?: TransportType; /** Server port (for web and streamable-http transports) */ port?: number; + /** User agent for the MCP server */ + userAgent?: string; + /** Delivery method for auth credentials (header or body) */ + authCredentialsDelivery?: 'header' | 'body'; } /** diff --git a/src/utils/security.ts b/src/utils/security.ts index a213174..66caace 100644 --- a/src/utils/security.ts +++ b/src/utils/security.ts @@ -2,6 +2,7 @@ * Security handling utilities for OpenAPI to MCP generator */ import { OpenAPIV3 } from 'openapi-types'; +import { CliOptions } from '../types/index.js'; /** * Get environment variable name for a security scheme @@ -80,9 +81,10 @@ export function generateHttpSecurityCode(): string { /** * Generates code for OAuth2 token acquisition * + * @param cliOptions CLI options * @returns Generated code for OAuth2 token acquisition */ -export function generateOAuth2TokenAcquisitionCode(): string { +export function generateOAuth2TokenAcquisitionCode(cliOptions?: CliOptions): string { return ` /** * Type definition for cached OAuth tokens @@ -149,8 +151,11 @@ async function acquireOAuth2Token(schemeName: string, scheme: any): Promise = {}; - const headers: Record = { 'Accept': 'application/json', 'User-Agent': 'orum-mcp-server' }; + const headers: Record = { 'Accept': 'application/json' }; let requestBodyData: any = undefined; +${cliOptions?.userAgent ? `headers['User-Agent'] = options.userAgent;` : ''} + // Apply parameters to the URL path, query, or headers definition.executionParameters.forEach((param) => { const value = validatedArgs[param.name];