Class: MCP::Server::Capabilities

Inherits:
Object
  • Object
show all
Defined in:
lib/mcp/server/capabilities.rb

Instance Method Summary collapse

Constructor Details

#initialize(capabilities_hash = nil) ⇒ Capabilities

Returns a new instance of Capabilities.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mcp/server/capabilities.rb', line 6

def initialize(capabilities_hash = nil)
  @completions = nil
  @experimental = nil
  @extensions = nil
  @logging = nil
  @prompts = nil
  @resources = nil
  @tools = nil

  if capabilities_hash
    support_completions if capabilities_hash.key?(:completions)
    support_experimental(capabilities_hash[:experimental]) if capabilities_hash.key?(:experimental)
    support_extensions(capabilities_hash[:extensions]) if capabilities_hash.key?(:extensions)
    support_logging if capabilities_hash.key?(:logging)

    if capabilities_hash.key?(:prompts)
      support_prompts
      prompts_config = capabilities_hash[:prompts] || {}
      support_prompts_list_changed if prompts_config[:listChanged]
    end

    if capabilities_hash.key?(:resources)
      support_resources
      resources_config = capabilities_hash[:resources] || {}
      support_resources_list_changed if resources_config[:listChanged]
      support_resources_subscribe if resources_config[:subscribe]
    end

    if capabilities_hash.key?(:tools)
      support_tools
      tools_config = capabilities_hash[:tools] || {}
      support_tools_list_changed if tools_config[:listChanged]
    end
  end
end

Instance Method Details

#support_completionsObject



42
43
44
# File 'lib/mcp/server/capabilities.rb', line 42

def support_completions
  @completions ||= {}
end

#support_experimental(config = {}) ⇒ Object



46
47
48
# File 'lib/mcp/server/capabilities.rb', line 46

def support_experimental(config = {})
  @experimental = config || {}
end

#support_extensions(extensions = {}) ⇒ Object

Declares support for capability extensions per SEP-2133. Keys are extension identifiers using the reverse-DNS prefix convention (e.g. ‘“io.modelcontextprotocol/tasks”`, `“com.example/feature”`); values are arbitrary extension-defined configuration objects, with an empty hash meaning “supported with no settings”. Repeated calls merge, so several extensions can be declared independently. github.com/modelcontextprotocol/modelcontextprotocol/pull/2133



57
58
59
# File 'lib/mcp/server/capabilities.rb', line 57

def support_extensions(extensions = {})
  @extensions = (@extensions || {}).merge(extensions || {})
end

#support_loggingObject



61
62
63
# File 'lib/mcp/server/capabilities.rb', line 61

def support_logging
  @logging ||= {}
end

#support_promptsObject



65
66
67
# File 'lib/mcp/server/capabilities.rb', line 65

def support_prompts
  @prompts ||= {}
end

#support_prompts_list_changedObject



69
70
71
72
# File 'lib/mcp/server/capabilities.rb', line 69

def support_prompts_list_changed
  support_prompts
  @prompts[:listChanged] = true
end

#support_resourcesObject



74
75
76
# File 'lib/mcp/server/capabilities.rb', line 74

def support_resources
  @resources ||= {}
end

#support_resources_list_changedObject



78
79
80
81
# File 'lib/mcp/server/capabilities.rb', line 78

def support_resources_list_changed
  support_resources
  @resources[:listChanged] = true
end

#support_resources_subscribeObject



83
84
85
86
# File 'lib/mcp/server/capabilities.rb', line 83

def support_resources_subscribe
  support_resources
  @resources[:subscribe] = true
end

#support_toolsObject



88
89
90
# File 'lib/mcp/server/capabilities.rb', line 88

def support_tools
  @tools ||= {}
end

#support_tools_list_changedObject



92
93
94
95
# File 'lib/mcp/server/capabilities.rb', line 92

def support_tools_list_changed
  support_tools
  @tools[:listChanged] = true
end

#to_hObject



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/mcp/server/capabilities.rb', line 97

def to_h
  {
    completions: @completions,
    experimental: @experimental,
    extensions: @extensions,
    logging: @logging,
    prompts: @prompts,
    resources: @resources,
    tools: @tools,
  }.compact
end