Class: SwaggerMCPTool::Config
- Inherits:
-
Object
- Object
- SwaggerMCPTool::Config
- Includes:
- Singleton
- Defined in:
- lib/swagger_mcp_tool/config.rb
Overview
Configuration management for SwaggerMCPTool
This class uses the Singleton pattern to ensure a single configuration instance throughout the application lifecycle.
Constant Summary collapse
- DEFAULT_SERVER_PORT =
3001- DEFAULT_SERVER_BIND =
'0.0.0.0'- DEFAULT_SERVER_TYPE =
:puma- DEFAULT_LOG_LEVEL =
Logger::INFO
- DEFAULT_AUTH_HEADER_NAME =
'Token'- DEFAULT_SWAGGER_URL =
'https://petstore.swagger.io/v2/swagger.json'- DEFAULT_MCP_NAME =
'swagger_api_tools'- DEFAULT_MCP_NAME_FOR_HUMAN =
'Swagger API Tools'- DEFAULT_MCP_DESCRIPTION_FOR_HUMAN =
'Tools for interacting with APIs via Swagger/OpenAPI specifications'- DEFAULT_MCP_DESCRIPTION_FOR_MODEL =
'This MCP server provides tools for interacting with APIs via Swagger/OpenAPI specifications.'- DEFAULT_AUTH_TYPE =
'none'- DEFAULT_LOG_FILE =
nil
Instance Attribute Summary collapse
-
#auth_header_name ⇒ Object
Returns the value of attribute auth_header_name.
-
#auth_type ⇒ Object
Returns the value of attribute auth_type.
-
#default_token ⇒ Object
Returns the value of attribute default_token.
-
#log_file ⇒ Object
Returns the value of attribute log_file.
-
#log_level ⇒ Object
Returns the value of attribute log_level.
-
#mcp_description_for_human ⇒ Object
Returns the value of attribute mcp_description_for_human.
-
#mcp_description_for_model ⇒ Object
Returns the value of attribute mcp_description_for_model.
-
#mcp_name ⇒ Object
Returns the value of attribute mcp_name.
-
#mcp_name_for_human ⇒ Object
Returns the value of attribute mcp_name_for_human.
-
#prompts ⇒ Object
Returns the value of attribute prompts.
-
#resources ⇒ Object
Returns the value of attribute resources.
-
#server_bind ⇒ Object
Returns the value of attribute server_bind.
-
#server_port ⇒ Object
Returns the value of attribute server_port.
-
#server_type ⇒ Object
Returns the value of attribute server_type.
-
#swagger_url ⇒ Object
Returns the value of attribute swagger_url.
-
#tools ⇒ Object
Returns the value of attribute tools.
Class Method Summary collapse
-
.configure ⇒ Object
Configure the instance.
Instance Method Summary collapse
- #create_file_logger ⇒ Object
- #create_logger ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
-
#logger ⇒ Object
Get the logger.
- #setup_auth_defaults ⇒ Object
- #setup_mcp_defaults ⇒ Object
- #setup_server_defaults ⇒ Object
- #setup_swagger_defaults ⇒ Object
-
#to_context(request) ⇒ Object
Get server context.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/swagger_mcp_tool/config.rb', line 33 def initialize # Server settings setup_server_defaults # Swagger settings setup_swagger_defaults # MCP settings setup_mcp_defaults # Auth settings setup_auth_defaults # Tools, Prompts and resources @tools = [] @resources = [] @prompts = [] # Will be generated lazily end |
Instance Attribute Details
#auth_header_name ⇒ Object
Returns the value of attribute auth_header_name.
14 15 16 |
# File 'lib/swagger_mcp_tool/config.rb', line 14 def auth_header_name @auth_header_name end |
#auth_type ⇒ Object
Returns the value of attribute auth_type.
14 15 16 |
# File 'lib/swagger_mcp_tool/config.rb', line 14 def auth_type @auth_type end |
#default_token ⇒ Object
Returns the value of attribute default_token.
14 15 16 |
# File 'lib/swagger_mcp_tool/config.rb', line 14 def default_token @default_token end |
#log_file ⇒ Object
Returns the value of attribute log_file.
14 15 16 |
# File 'lib/swagger_mcp_tool/config.rb', line 14 def log_file @log_file end |
#log_level ⇒ Object
Returns the value of attribute log_level.
14 15 16 |
# File 'lib/swagger_mcp_tool/config.rb', line 14 def log_level @log_level end |
#mcp_description_for_human ⇒ Object
Returns the value of attribute mcp_description_for_human.
14 15 16 |
# File 'lib/swagger_mcp_tool/config.rb', line 14 def mcp_description_for_human @mcp_description_for_human end |
#mcp_description_for_model ⇒ Object
Returns the value of attribute mcp_description_for_model.
14 15 16 |
# File 'lib/swagger_mcp_tool/config.rb', line 14 def mcp_description_for_model @mcp_description_for_model end |
#mcp_name ⇒ Object
Returns the value of attribute mcp_name.
14 15 16 |
# File 'lib/swagger_mcp_tool/config.rb', line 14 def mcp_name @mcp_name end |
#mcp_name_for_human ⇒ Object
Returns the value of attribute mcp_name_for_human.
14 15 16 |
# File 'lib/swagger_mcp_tool/config.rb', line 14 def mcp_name_for_human @mcp_name_for_human end |
#prompts ⇒ Object
Returns the value of attribute prompts.
14 15 16 |
# File 'lib/swagger_mcp_tool/config.rb', line 14 def prompts @prompts end |
#resources ⇒ Object
Returns the value of attribute resources.
14 15 16 |
# File 'lib/swagger_mcp_tool/config.rb', line 14 def resources @resources end |
#server_bind ⇒ Object
Returns the value of attribute server_bind.
14 15 16 |
# File 'lib/swagger_mcp_tool/config.rb', line 14 def server_bind @server_bind end |
#server_port ⇒ Object
Returns the value of attribute server_port.
14 15 16 |
# File 'lib/swagger_mcp_tool/config.rb', line 14 def server_port @server_port end |
#server_type ⇒ Object
Returns the value of attribute server_type.
14 15 16 |
# File 'lib/swagger_mcp_tool/config.rb', line 14 def server_type @server_type end |
#swagger_url ⇒ Object
Returns the value of attribute swagger_url.
14 15 16 |
# File 'lib/swagger_mcp_tool/config.rb', line 14 def swagger_url @swagger_url end |
#tools ⇒ Object
Returns the value of attribute tools.
14 15 16 |
# File 'lib/swagger_mcp_tool/config.rb', line 14 def tools @tools end |
Class Method Details
.configure ⇒ Object
Configure the instance
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/swagger_mcp_tool/config.rb', line 108 def self.configure return unless block_given? config_instance = instance yield config_instance log_configuration_details(config_instance) config_instance rescue StandardError => e config_instance.logger.error "Configuration failed: #{e.message}" raise e end |
Instance Method Details
#create_file_logger ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/swagger_mcp_tool/config.rb', line 91 def create_file_logger target = case @log_file when $stdout, $stdout, 'STDOUT', 'stdout' $stdout when $stderr, $stderr, 'STDERR', 'stderr' $stderr when nil, '' $stderr else @log_file end logger = Logger.new(target) logger.level = @log_level logger end |
#create_logger ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/swagger_mcp_tool/config.rb', line 82 def create_logger create_file_logger rescue StandardError => e logger = Logger.new($stdout) logger.level = @log_level logger.warn "Could not create log file #{@log_file} (#{e.message}), using stderr for logging" logger end |
#logger ⇒ Object
Get the logger
78 79 80 |
# File 'lib/swagger_mcp_tool/config.rb', line 78 def logger @logger ||= create_logger end |
#setup_auth_defaults ⇒ Object
72 73 74 75 |
# File 'lib/swagger_mcp_tool/config.rb', line 72 def setup_auth_defaults @auth_type = DEFAULT_AUTH_TYPE @default_token = nil end |
#setup_mcp_defaults ⇒ Object
65 66 67 68 69 70 |
# File 'lib/swagger_mcp_tool/config.rb', line 65 def setup_mcp_defaults @mcp_name = DEFAULT_MCP_NAME @mcp_name_for_human = DEFAULT_MCP_NAME_FOR_HUMAN @mcp_description_for_human = DEFAULT_MCP_DESCRIPTION_FOR_HUMAN @mcp_description_for_model = DEFAULT_MCP_DESCRIPTION_FOR_MODEL end |
#setup_server_defaults ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/swagger_mcp_tool/config.rb', line 52 def setup_server_defaults @server_port = DEFAULT_SERVER_PORT @server_bind = DEFAULT_SERVER_BIND @server_type = DEFAULT_SERVER_TYPE @log_level = DEFAULT_LOG_LEVEL @log_file = nil @auth_header_name = DEFAULT_AUTH_HEADER_NAME end |
#setup_swagger_defaults ⇒ Object
61 62 63 |
# File 'lib/swagger_mcp_tool/config.rb', line 61 def setup_swagger_defaults @swagger_url = DEFAULT_SWAGGER_URL end |
#to_context(request) ⇒ Object
Get server context
121 122 123 124 125 126 127 128 129 |
# File 'lib/swagger_mcp_tool/config.rb', line 121 def to_context(request) auth_header_name = self.auth_header_name || 'Authorization' { user_id: request.env['HTTP_X_USER_ID'] || '1', auth_header_name.to_sym => request.env['HTTP_X_AUTH_TOKEN'], username: request.env['HTTP_X_USERNAME'], email: request.env['HTTP_X_EMAIL'] } end |