Skip to content

Remove automatic capability determination and add missing capabilities #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions lib/mcp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require "json_rpc_handler"
require_relative "instrumentation"
require_relative "methods"
require_relative "server/capabilities"

module MCP
class Server
Expand All @@ -23,8 +22,7 @@ def initialize(message, request, error_type: :internal_error, original_error: ni

include Instrumentation

attr_writer :capabilities
attr_accessor :name, :version, :tools, :prompts, :resources, :server_context, :configuration, :transport
attr_accessor :name, :version, :tools, :prompts, :resources, :server_context, :configuration, :capabilities, :transport

def initialize(
name: "model_context_protocol",
Expand All @@ -47,10 +45,7 @@ def initialize(
@resource_index = index_resources_by_uri(resources)
@server_context = server_context
@configuration = MCP.configuration.merge(configuration)
@capabilities = Capabilities.new(capabilities)
@capabilities.support_tools if tools.any?
@capabilities.support_prompts if prompts.any?
@capabilities.support_resources if resources.any? || resource_templates.any?
@capabilities = capabilities || default_capabilities

@handlers = {
Methods::RESOURCES_LIST => method(:list_resources),
Expand All @@ -72,10 +67,6 @@ def initialize(
@transport = transport
end

def capabilities
@capabilities.to_h
end

def handle(request)
JsonRpcHandler.handle(request) do |method|
handle_request(request, method)
Expand Down Expand Up @@ -123,7 +114,6 @@ def notify_resources_list_changed
end

def resources_list_handler(&block)
@capabilities.support_resources
@handlers[Methods::RESOURCES_LIST] = block
end

Expand All @@ -132,12 +122,10 @@ def resources_read_handler(&block)
end

def resources_templates_list_handler(&block)
@capabilities.support_resources
@handlers[Methods::RESOURCES_TEMPLATES_LIST] = block
end

def tools_list_handler(&block)
@capabilities.support_tools
@handlers[Methods::TOOLS_LIST] = block
end

Expand All @@ -146,7 +134,6 @@ def tools_call_handler(&block)
end

def prompts_list_handler(&block)
@capabilities.support_prompts
@handlers[Methods::PROMPTS_LIST] = block
end

Expand Down Expand Up @@ -194,6 +181,14 @@ def handle_request(request, method)
}
end

def default_capabilities
{
tools: { listChanged: true },
prompts: { listChanged: true },
resources: { listChanged: true },
}
end

def server_info
@server_info ||= {
name:,
Expand Down
197 changes: 0 additions & 197 deletions test/mcp/server/capabilities_test.rb

This file was deleted.

Loading