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- DEFAULT_PROTOCOL_VERSION =
"2024-11-05"
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.
-
#exclude_tools ⇒ Object
Returns the value of attribute exclude_tools.
-
#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.
-
#protocol_version ⇒ Object
Returns the value of attribute protocol_version.
-
#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.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/swagger_mcp_tool/config.rb', line 34 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 @exclude_tools = [] end |
Instance Attribute Details
#auth_header_name ⇒ Object
Returns the value of attribute auth_header_name.
13 14 15 |
# File 'lib/swagger_mcp_tool/config.rb', line 13 def auth_header_name @auth_header_name end |
#auth_type ⇒ Object
Returns the value of attribute auth_type.
13 14 15 |
# File 'lib/swagger_mcp_tool/config.rb', line 13 def auth_type @auth_type end |
#default_token ⇒ Object
Returns the value of attribute default_token.
13 14 15 |
# File 'lib/swagger_mcp_tool/config.rb', line 13 def default_token @default_token end |
#exclude_tools ⇒ Object
Returns the value of attribute exclude_tools.
13 14 15 |
# File 'lib/swagger_mcp_tool/config.rb', line 13 def exclude_tools @exclude_tools end |
#log_file ⇒ Object
Returns the value of attribute log_file.
13 14 15 |
# File 'lib/swagger_mcp_tool/config.rb', line 13 def log_file @log_file end |
#log_level ⇒ Object
Returns the value of attribute log_level.
13 14 15 |
# File 'lib/swagger_mcp_tool/config.rb', line 13 def log_level @log_level end |
#mcp_description_for_human ⇒ Object
Returns the value of attribute mcp_description_for_human.
13 14 15 |
# File 'lib/swagger_mcp_tool/config.rb', line 13 def mcp_description_for_human @mcp_description_for_human end |
#mcp_description_for_model ⇒ Object
Returns the value of attribute mcp_description_for_model.
13 14 15 |
# File 'lib/swagger_mcp_tool/config.rb', line 13 def mcp_description_for_model @mcp_description_for_model end |
#mcp_name ⇒ Object
Returns the value of attribute mcp_name.
13 14 15 |
# File 'lib/swagger_mcp_tool/config.rb', line 13 def mcp_name @mcp_name end |
#mcp_name_for_human ⇒ Object
Returns the value of attribute mcp_name_for_human.
13 14 15 |
# File 'lib/swagger_mcp_tool/config.rb', line 13 def mcp_name_for_human @mcp_name_for_human end |
#prompts ⇒ Object
Returns the value of attribute prompts.
13 14 15 |
# File 'lib/swagger_mcp_tool/config.rb', line 13 def prompts @prompts end |
#protocol_version ⇒ Object
Returns the value of attribute protocol_version.
13 14 15 |
# File 'lib/swagger_mcp_tool/config.rb', line 13 def protocol_version @protocol_version end |
#resources ⇒ Object
Returns the value of attribute resources.
13 14 15 |
# File 'lib/swagger_mcp_tool/config.rb', line 13 def resources @resources end |
#server_bind ⇒ Object
Returns the value of attribute server_bind.
13 14 15 |
# File 'lib/swagger_mcp_tool/config.rb', line 13 def server_bind @server_bind end |
#server_port ⇒ Object
Returns the value of attribute server_port.
13 14 15 |
# File 'lib/swagger_mcp_tool/config.rb', line 13 def server_port @server_port end |
#server_type ⇒ Object
Returns the value of attribute server_type.
13 14 15 |
# File 'lib/swagger_mcp_tool/config.rb', line 13 def server_type @server_type end |
#swagger_url ⇒ Object
Returns the value of attribute swagger_url.
13 14 15 |
# File 'lib/swagger_mcp_tool/config.rb', line 13 def swagger_url @swagger_url end |
#tools ⇒ Object
Returns the value of attribute tools.
13 14 15 |
# File 'lib/swagger_mcp_tool/config.rb', line 13 def tools @tools end |
Class Method Details
.configure ⇒ Object
Configure the instance
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/swagger_mcp_tool/config.rb', line 111 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.}" raise e end |
Instance Method Details
#create_file_logger ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/swagger_mcp_tool/config.rb', line 94 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
85 86 87 88 89 90 91 92 |
# File 'lib/swagger_mcp_tool/config.rb', line 85 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.}), using stderr for logging" logger end |
#logger ⇒ Object
Get the logger
81 82 83 |
# File 'lib/swagger_mcp_tool/config.rb', line 81 def logger @logger ||= create_logger end |
#setup_auth_defaults ⇒ Object
75 76 77 78 |
# File 'lib/swagger_mcp_tool/config.rb', line 75 def setup_auth_defaults @auth_type = DEFAULT_AUTH_TYPE @default_token = nil end |
#setup_mcp_defaults ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/swagger_mcp_tool/config.rb', line 67 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 @protocol_version = DEFAULT_PROTOCOL_VERSION end |
#setup_server_defaults ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/swagger_mcp_tool/config.rb', line 54 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
63 64 65 |
# File 'lib/swagger_mcp_tool/config.rb', line 63 def setup_swagger_defaults @swagger_url = DEFAULT_SWAGGER_URL end |
#to_context(request) ⇒ Object
Get server context
124 125 126 127 128 129 130 131 132 |
# File 'lib/swagger_mcp_tool/config.rb', line 124 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 |