$npx -y skills add github/awesome-copilot --skill ruby-mcp-server-generatorGenerate a complete Model Context Protocol server project in Ruby using the official MCP Ruby SDK gem.
| 1 | # Ruby MCP Server Generator |
| 2 | |
| 3 | Generate a complete, production-ready MCP server in Ruby using the official Ruby SDK. |
| 4 | |
| 5 | ## Project Generation |
| 6 | |
| 7 | When asked to create a Ruby MCP server, generate a complete project with this structure: |
| 8 | |
| 9 | ``` |
| 10 | my-mcp-server/ |
| 11 | ├── Gemfile |
| 12 | ├── Rakefile |
| 13 | ├── lib/ |
| 14 | │ ├── my_mcp_server.rb |
| 15 | │ ├── my_mcp_server/ |
| 16 | │ │ ├── server.rb |
| 17 | │ │ ├── tools/ |
| 18 | │ │ │ ├── greet_tool.rb |
| 19 | │ │ │ └── calculate_tool.rb |
| 20 | │ │ ├── prompts/ |
| 21 | │ │ │ └── code_review_prompt.rb |
| 22 | │ │ └── resources/ |
| 23 | │ │ └── example_resource.rb |
| 24 | ├── bin/ |
| 25 | │ └── mcp-server |
| 26 | ├── test/ |
| 27 | │ ├── test_helper.rb |
| 28 | │ └── tools/ |
| 29 | │ ├── greet_tool_test.rb |
| 30 | │ └── calculate_tool_test.rb |
| 31 | └── README.md |
| 32 | ``` |
| 33 | |
| 34 | ## Gemfile Template |
| 35 | |
| 36 | ```ruby |
| 37 | source 'https://rubygems.org' |
| 38 | |
| 39 | gem 'mcp', '~> 0.4.0' |
| 40 | |
| 41 | group :development, :test do |
| 42 | gem 'minitest', '~> 5.0' |
| 43 | gem 'rake', '~> 13.0' |
| 44 | gem 'rubocop', '~> 1.50' |
| 45 | end |
| 46 | ``` |
| 47 | |
| 48 | ## Rakefile Template |
| 49 | |
| 50 | ```ruby |
| 51 | require 'rake/testtask' |
| 52 | require 'rubocop/rake_task' |
| 53 | |
| 54 | Rake::TestTask.new(:test) do |t| |
| 55 | t.libs << 'test' |
| 56 | t.libs << 'lib' |
| 57 | t.test_files = FileList['test/**/*_test.rb'] |
| 58 | end |
| 59 | |
| 60 | RuboCop::RakeTask.new |
| 61 | |
| 62 | task default: %i[test rubocop] |
| 63 | ``` |
| 64 | |
| 65 | ## lib/my_mcp_server.rb Template |
| 66 | |
| 67 | ```ruby |
| 68 | # frozen_string_literal: true |
| 69 | |
| 70 | require 'mcp' |
| 71 | require_relative 'my_mcp_server/server' |
| 72 | require_relative 'my_mcp_server/tools/greet_tool' |
| 73 | require_relative 'my_mcp_server/tools/calculate_tool' |
| 74 | require_relative 'my_mcp_server/prompts/code_review_prompt' |
| 75 | require_relative 'my_mcp_server/resources/example_resource' |
| 76 | |
| 77 | module MyMcpServer |
| 78 | VERSION = '1.0.0' |
| 79 | end |
| 80 | ``` |
| 81 | |
| 82 | ## lib/my_mcp_server/server.rb Template |
| 83 | |
| 84 | ```ruby |
| 85 | # frozen_string_literal: true |
| 86 | |
| 87 | module MyMcpServer |
| 88 | class Server |
| 89 | attr_reader :mcp_server |
| 90 | |
| 91 | def initialize(server_context: {}) |
| 92 | @mcp_server = MCP::Server.new( |
| 93 | name: 'my_mcp_server', |
| 94 | version: MyMcpServer::VERSION, |
| 95 | tools: [ |
| 96 | Tools::GreetTool, |
| 97 | Tools::CalculateTool |
| 98 | ], |
| 99 | prompts: [ |
| 100 | Prompts::CodeReviewPrompt |
| 101 | ], |
| 102 | resources: [ |
| 103 | Resources::ExampleResource.resource |
| 104 | ], |
| 105 | server_context: server_context |
| 106 | ) |
| 107 | |
| 108 | setup_resource_handler |
| 109 | end |
| 110 | |
| 111 | def handle_json(json_string) |
| 112 | mcp_server.handle_json(json_string) |
| 113 | end |
| 114 | |
| 115 | def start_stdio |
| 116 | transport = MCP::Server::Transports::StdioTransport.new(mcp_server) |
| 117 | transport.open |
| 118 | end |
| 119 | |
| 120 | private |
| 121 | |
| 122 | def setup_resource_handler |
| 123 | mcp_server.resources_read_handler do |params| |
| 124 | Resources::ExampleResource.read(params[:uri]) |
| 125 | end |
| 126 | end |
| 127 | end |
| 128 | end |
| 129 | ``` |
| 130 | |
| 131 | ## lib/my_mcp_server/tools/greet_tool.rb Template |
| 132 | |
| 133 | ```ruby |
| 134 | # frozen_string_literal: true |
| 135 | |
| 136 | module MyMcpServer |
| 137 | module Tools |
| 138 | class GreetTool < MCP::Tool |
| 139 | tool_name 'greet' |
| 140 | description 'Generate a greeting message' |
| 141 | |
| 142 | input_schema( |
| 143 | properties: { |
| 144 | name: { |
| 145 | type: 'string', |
| 146 | description: 'Name to greet' |
| 147 | } |
| 148 | }, |
| 149 | required: ['name'] |
| 150 | ) |
| 151 | |
| 152 | output_schema( |
| 153 | properties: { |
| 154 | message: { type: 'string' }, |
| 155 | timestamp: { type: 'string', format: 'date-time' } |
| 156 | }, |
| 157 | required: ['message', 'timestamp'] |
| 158 | ) |
| 159 | |
| 160 | annotations( |
| 161 | read_only_hint: true, |
| 162 | idempotent_hint: true |
| 163 | ) |
| 164 | |
| 165 | def self.call(name:, server_context:) |
| 166 | timestamp = Time.now.iso8601 |
| 167 | message = "Hello, #{name}! Welcome to MCP." |
| 168 | |
| 169 | structured_data = { |
| 170 | message: message, |
| 171 | timestamp: timestamp |
| 172 | } |
| 173 | |
| 174 | MCP::Tool::Response.new( |
| 175 | [{ type: 'text', text: message }], |
| 176 | structured_content: structured_data |
| 177 | ) |
| 178 | end |
| 179 | end |
| 180 | end |
| 181 | end |
| 182 | ``` |
| 183 | |
| 184 | ## lib/my_mcp_server/tools/calculate_tool.rb Template |
| 185 | |
| 186 | ```ruby |
| 187 | # frozen_string_literal: true |
| 188 | |
| 189 | module MyMcpServer |
| 190 | module Tools |
| 191 | class CalculateTool < MCP::Tool |
| 192 | tool_name 'calculate' |
| 193 | description 'Perform mathematical calculations' |
| 194 | |
| 195 | input_schema( |
| 196 | properties: { |
| 197 | operation: { |
| 198 | type: 'string', |
| 199 | description: 'Operation to perform', |
| 200 | enum: ['add', 'subtract', 'multiply', 'divide'] |
| 201 | }, |
| 202 | a: { |
| 203 | type: 'number', |
| 204 | description: 'First operand' |
| 205 | }, |
| 206 | b: { |
| 207 | type: 'number', |
| 208 | description: 'Second operand' |
| 209 | } |
| 210 | }, |
| 211 | required: ['operation', 'a', 'b'] |
| 212 | ) |
| 213 | |
| 214 | output_schema( |
| 215 | properties: { |
| 216 | result: { type: 'number' }, |
| 217 | operation: { type: 'string' } |
| 218 | }, |
| 219 | required: ['result', 'operation'] |
| 220 | ) |
| 221 | |
| 222 | annotations( |
| 223 | read_only_hint: true, |
| 224 | idempotent_hint: true |
| 225 | ) |
| 226 | |
| 227 | def self.call(operation:, a:, b:, server_context:) |
| 228 | result = case |