SOLFIND
Web Lens
Portal home

GitHub - modelcontextprotocol/ruby-sdk: The official Ruby SDK for the Model Context Protocol servers and clients. · GitHub

https://github.com/modelcontextprotocol/ruby-sdk • 344 KB fetched
Open original page


GitHub - modelcontextprotocol/ruby-sdk: The official Ruby SDK for the Model Context Protocol servers and clients. · GitHub Skip to content Navigation Menu Sign in Appearance settings * Platform * AI CODE CREATION * GitHub Copilot Write better code with AI * GitHub Copilot app Direct agents from issue to merge * MCP Registry Integrate external tools * DEVELOPER WORKFLOWS * Actions Automate any workflow * Codespaces Instant dev environments * Issues Plan and track work * Code Review Manage code changes * Code Quality Enforce quality at merge * APPLICATION SECURITY * GitHub Advanced Security Find and fix vulnerabilities * Code security Secure your code as you build * Secret protection Stop leaks before they start * EXPLORE * Why GitHub * Documentation * Blog * Changelog * Marketplace View all features * Solutions * BY COMPANY SIZE * Enterprises * Small and medium teams * Startups * Nonprofits * BY USE CASE * App Modernization * DevSecOps * DevOps * CI/CD * View all use cases * BY INDUSTRY * Healthcare * Financial services * Manufacturing * Government * View all industries View all solutions * Resources * EXPLORE BY TOPIC * AI * Software Development * DevOps * Security * View all topics * EXPLORE BY TYPE * Customer stories * Events & webinars * Ebooks & reports * Business insights * GitHub Skills * SUPPORT & SERVICES * Documentation * Customer support * Community forum * Trust center * Partners View all resources * Open Source * COMMUNITY * GitHub Sponsors Fund open source developers * PROGRAMS * Security Lab * Maintainer Community * GitHub Stars * Archive Program * REPOSITORIES * Topics * Trending * Collections * Enterprise * ENTERPRISE SOLUTIONS * Enterprise platform AI-powered developer platform * AVAILABLE ADD-ONS * GitHub Advanced Security Enterprise-grade security features * Copilot for Business Enterprise-grade AI features * Premium Support Enterprise-grade 24/7 support * Pricing Search / Sign in Sign up Appearance settings You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert Uh oh! There was an error while loading. Please reload this page . modelcontextprotocol / ruby-sdk Public * Notifications You must be signed in to change notification settings * Fork 132 * Star 906 * Code * Issues 1 * Pull requests 1 * Discussions * Actions * Projects * Security and quality 7 * Insights Additional navigation options * Code * Issues * Pull requests * Discussions * Actions * Projects * Security and quality * Insights main Branches Tags Go to file Code Open more actions menu Latest commit   History 929 Commits 929 Commits Folders and files Name Name Last commit message Last commit date .github .github     bin bin     conformance conformance     docs docs     examples examples     lib lib     test test     .gitattributes .gitattributes     .gitignore .gitignore     .rubocop.yml .rubocop.yml     AGENTS.md AGENTS.md     CHANGELOG.md CHANGELOG.md     CLAUDE.md CLAUDE.md     CODE_OF_CONDUCT.md CODE_OF_CONDUCT.md     Gemfile Gemfile     LICENSE LICENSE     README.md README.md     RELEASE.md RELEASE.md     ROADMAP.md ROADMAP.md     Rakefile Rakefile     SECURITY.md SECURITY.md     VERSIONING.md VERSIONING.md     dev.yml dev.yml     mcp.gemspec mcp.gemspec     View all files Repository files navigation * * README * Code of conduct * Contributing * License * Security More items MCP Ruby SDK The official Ruby SDK for Model Context Protocol servers and clients. Detailed guides are available at https://ruby.sdk.modelcontextprotocol.io . Features * Build MCP servers that expose tools, prompts, and resources to any MCP host * Build MCP clients that connect to any MCP server, with automatic lifecycle negotiation and OAuth 2.1 authorization * Speak every standard transport: stdio and Streamable HTTP (including SSE), with a Rails integration * Cover the full protocol surface: server-to-client requests, multi round-trip requests, notifications, progress, logging, cancellation, completions, and pagination Installation Add this line to your application's Gemfile: gem "mcp" And then execute: $ bundle install Or install it yourself as: $ gem install mcp You may need to add additional dependencies depending on which features you wish to access. Quick Start The following minimal programs show both sides of the protocol: a server that exposes a single tool, and a client that spawns such a server and drives it over stdio. MCP Server A minimal server defines a tool and serves it over the stdio transport: require "mcp" # Create a simple tool class ExampleTool < MCP :: Tool description "A simple example tool that echoes back its arguments" input_schema ( properties : { message : { type : "string" } , } , required : [ "message" ] ) class << self def call ( message : , server_context : ) MCP :: Tool :: Response . new ( [ { type : "text" , text : "Hello from example tool! Message: #{ message } " , } ] ) end end end # Set up the server server = MCP :: Server . new ( name : "example_server" , tools : [ ExampleTool ] , ) # Create and start the transport transport = MCP :: Server :: Transports :: StdioTransport . new ( server ) transport . open Save the script as server.rb , run it, and send JSON-RPC requests via stdin: $ ruby server.rb {"jsonrpc":"2.0","id":"1","method":"ping"} {"jsonrpc":"2.0","id":"2","method":"tools/list"} {"jsonrpc":"2.0","id":"3","method":"tools/call","params":{"name":"example_tool","arguments":{"message":"Hello"}}} The same server can also run over Streamable HTTP, including mounted inside a Rails application; see Server Transports . MCP Client A minimal client spawns a stdio server as a subprocess, connects, and lists and calls its tools: stdio_transport = MCP :: Client :: Stdio . new ( command : "bundle" , args : [ "exec" , "ruby" , "path/to/server.rb" ] , env : { "API_KEY" => "my_secret_key" } , read_timeout : 30 ) client = MCP :: Client . new ( transport : stdio_transport ) # Perform the MCP initialization handshake before sending any requests. client . connect # List available tools. tools = client . tools tools . each do | tool | puts "Tool: #{ tool . name } - #{ tool . description } " end # Call a specific tool. response = client . call_tool ( tool : tools . first , arguments : { message : "Hello, world!" } ) # Close the transport when done. stdio_transport . close The same client can connect to Streamable HTTP servers with MCP::Client::HTTP ; see Client Transports . Examples Runnable examples are available in examples/ , including a complete Rails application in examples/rails . Documentation * SDK guides * SDK API documentation * Model Context Protocol documentation License This project is licensed under the Apache License 2.0 for new contributions, with existing code under MIT. See the LICENSE file for details. About The official Ruby SDK for the Model Context Protocol servers and clients. ruby.sdk.modelcontextprotocol.io Topics mcp mcp-client mcp-server ruby Resources Readme License Code of conduct Code of conduct Contributing Contributing Security policy Security policy Activity Custom properties Stars 906 stars Watchers 16 watching Forks 132 forks Report repository Releases Used by Contributors Languages Footer (c) 2026 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Community * Docs * Contact * Manage cookies * Do not share my personal information You can’t perform that action at this time.

Links found on this page

  1. Skip to content [direct]
  2. Sign in [direct]
  3. GitHub Copilot Write better code with AI [direct]
  4. GitHub Copilot app Direct agents from issue to merge [direct]
  5. MCP Registry Integrate external tools [direct]
  6. Actions Automate any workflow [direct]
  7. Codespaces Instant dev environments [direct]
  8. Issues Plan and track work [direct]
  9. Code Review Manage code changes [direct]
  10. Code Quality Enforce quality at merge [direct]
  11. GitHub Advanced Security Find and fix vulnerabilities [direct]
  12. Code security Secure your code as you build [direct]
  13. Secret protection Stop leaks before they start [direct]
  14. Why GitHub [direct]
  15. Documentation [direct]
  16. Blog [direct]
  17. Changelog [direct]
  18. Marketplace [direct]
  19. View all features [direct]
  20. Enterprises [direct]
  21. Small and medium teams [direct]
  22. Startups [direct]
  23. Nonprofits [direct]
  24. App Modernization [direct]
  25. DevSecOps [direct]
  26. DevOps [direct]
  27. CI/CD [direct]
  28. View all use cases [direct]
  29. Healthcare [direct]
  30. Financial services [direct]
  31. Manufacturing [direct]
  32. Government [direct]
  33. View all industries [direct]
  34. View all solutions [direct]
  35. AI [direct]
  36. Software Development [direct]
  37. DevOps [direct]
  38. Security [direct]
  39. View all topics [direct]
  40. Customer stories [direct]
  41. Events & webinars [direct]
  42. Ebooks & reports [direct]
  43. Business insights [direct]
  44. GitHub Skills [direct]
  45. Customer support [direct]
  46. Community forum [direct]
  47. Trust center [direct]
  48. Partners [direct]
  49. View all resources [direct]
  50. GitHub Sponsors Fund open source developers [direct]
  51. Security Lab [direct]
  52. Maintainer Community [direct]
  53. GitHub Stars [direct]
  54. Archive Program [direct]
  55. Topics [direct]
  56. Trending [direct]
  57. Collections [direct]
  58. Copilot for Business Enterprise-grade AI features [direct]
  59. Premium Support Enterprise-grade 24/7 support [direct]
  60. Pricing [direct]
  61. Sign up [direct]
  62. modelcontextprotocol [direct]
  63. Notifications [direct]
  64. Issues 1 [direct]
  65. Pull requests 1 [direct]
  66. Discussions [direct]
  67. Actions [direct]
  68. Projects [direct]
  69. Security and quality 7 [direct]
  70. Insights [direct]
  71. Branches [direct]
  72. Tags [direct]
  73. 929 Commits [direct]
  74. .github [direct]
  75. bin [direct]
  76. conformance [direct]
  77. docs [direct]
  78. examples [direct]
  79. lib [direct]
  80. test [direct]