Class: Coverband::MCP::Server
- Inherits:
-
Object
- Object
- Coverband::MCP::Server
- Defined in:
- lib/coverband/mcp/server.rb
Constant Summary collapse
- DEFAULT_HTTP_PORT =
9023
Instance Attribute Summary collapse
-
#mcp_server ⇒ Object
readonly
Returns the value of attribute mcp_server.
Instance Method Summary collapse
- #handle_json(json_request) ⇒ Object
-
#initialize ⇒ Server
constructor
A new instance of Server.
- #run_http(port: DEFAULT_HTTP_PORT, host: "localhost") ⇒ Object
- #run_stdio ⇒ Object
Constructor Details
#initialize ⇒ Server
Returns a new instance of Server.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/coverband/mcp/server.rb', line 18 def initialize # Ensure Coverband is configured Coverband.configure unless Coverband.configured? # Security check: Ensure MCP is enabled and environment is allowed unless Coverband.configuration.mcp_enabled? raise SecurityError, "MCP is not enabled. Set config.mcp_enabled = true and ensure the current environment is in mcp_allowed_environments." end @mcp_server = ::MCP::Server.new( name: "coverband", version: Coverband::VERSION, instructions: "Coverband production code coverage MCP server. " \ "Query coverage data, find dead code, and analyze view/route/translation usage.", tools: tools ) end |
Instance Attribute Details
#mcp_server ⇒ Object (readonly)
Returns the value of attribute mcp_server.
14 15 16 |
# File 'lib/coverband/mcp/server.rb', line 14 def mcp_server @mcp_server end |
Instance Method Details
#handle_json(json_request) ⇒ Object
86 87 88 |
# File 'lib/coverband/mcp/server.rb', line 86 def handle_json(json_request) @mcp_server.handle_json(json_request) end |
#run_http(port: DEFAULT_HTTP_PORT, host: "localhost") ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/coverband/mcp/server.rb', line 41 def run_http(port: DEFAULT_HTTP_PORT, host: "localhost") require "rack" require "rackup" transport = ::MCP::Server::Transports::StreamableHTTPTransport.new(@mcp_server) @mcp_server.transport = transport app = create_rack_app(transport) puts <<~MESSAGE === Coverband MCP Server (HTTP) === 🔒 SECURITY NOTICE: This server exposes production coverage data. Ensure proper network security (firewall, VPN, etc.) Environment: #{(defined?(Rails) && Rails.respond_to?(:env) && Rails.env) || ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"} Authentication: #{Coverband.configuration.mcp_password ? "✓ Enabled" : "⚠️ DISABLED"} Server running at http://#{host}:#{port} Available tools: - get_coverage_summary - get_file_coverage - get_uncovered_files - get_dead_methods - get_view_tracker_data - get_route_tracker_data - get_translation_tracker_data For Claude Desktop, configure with: { "mcpServers": { "coverband": { "command": "npx", "args": ["mcp-remote", "http://#{host}:#{port}"] } } } Press Ctrl+C to stop the server MESSAGE Rackup::Handler.get("puma").run(app, Port: port, Host: host, Silent: true) end |
#run_stdio ⇒ Object
36 37 38 39 |
# File 'lib/coverband/mcp/server.rb', line 36 def run_stdio transport = ::MCP::Server::Transports::StdioTransport.new(@mcp_server) transport.open end |