Class: ClaudeAgentSDK::SdkMcpServer

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#nameObject (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

#toolsObject (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

#versionObject (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

Parameters:

  • name (String)

    Tool name

  • arguments (Hash)

    Tool arguments

Returns:

  • (Hash)

    Tool result



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_toolsArray<Hash>

List all available tools

Returns:

  • (Array<Hash>)

    Array of tool definitions



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