Class: ClaudeAgentSDK::SdkMcpServer
- Inherits:
-
Object
- Object
- ClaudeAgentSDK::SdkMcpServer
- Defined in:
- lib/claude_agent_sdk/sdk_mcp_server.rb
Overview
SDK MCP Server - runs in-process within your Ruby application
Unlike external MCP servers that run as separate processes, SDK MCP servers run directly in your application’s process, providing better performance and simpler deployment.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#tools ⇒ Object
readonly
Returns the value of attribute tools.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#call_tool(name, arguments) ⇒ Hash
Execute a tool by name.
-
#initialize(name:, version: '1.0.0', tools: []) ⇒ SdkMcpServer
constructor
A new instance of SdkMcpServer.
-
#list_tools ⇒ Array<Hash>
List all available tools.
Constructor Details
#initialize(name:, version: '1.0.0', tools: []) ⇒ SdkMcpServer
Returns a new instance of SdkMcpServer.
12 13 14 15 16 17 |
# File 'lib/claude_agent_sdk/sdk_mcp_server.rb', line 12 def initialize(name:, version: '1.0.0', tools: []) @name = name @version = version @tools = tools @tool_map = tools.each_with_object({}) { |tool, hash| hash[tool.name] = tool } end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/claude_agent_sdk/sdk_mcp_server.rb', line 10 def name @name end |
#tools ⇒ Object (readonly)
Returns the value of attribute tools.
10 11 12 |
# File 'lib/claude_agent_sdk/sdk_mcp_server.rb', line 10 def tools @tools end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
10 11 12 |
# File 'lib/claude_agent_sdk/sdk_mcp_server.rb', line 10 def version @version end |
Instance Method Details
#call_tool(name, arguments) ⇒ Hash
Execute a tool by name
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/claude_agent_sdk/sdk_mcp_server.rb', line 35 def call_tool(name, arguments) tool = @tool_map[name] raise "Tool '#{name}' not found" unless tool # Call the tool's handler result = tool.handler.call(arguments) # Ensure result has the expected format unless result.is_a?(Hash) && result[:content] raise "Tool '#{name}' must return a hash with :content key" end result end |
#list_tools ⇒ Array<Hash>
List all available tools
21 22 23 24 25 26 27 28 29 |
# File 'lib/claude_agent_sdk/sdk_mcp_server.rb', line 21 def list_tools @tools.map do |tool| { name: tool.name, description: tool.description, inputSchema: convert_input_schema(tool.input_schema) } end end |