From 0534ff1651ccc01361cdc5f75304dfd07af1f984 Mon Sep 17 00:00:00 2001 From: Topher Bullock Date: Mon, 6 Oct 2025 09:07:25 -0400 Subject: [PATCH] spec compliance of resources --- README.md | 5 +++++ lib/mcp/resource.rb | 14 ++++++++++---- lib/mcp/resource_template.rb | 12 ++++++++---- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index ba66f1c..2a7646f 100644 --- a/README.md +++ b/README.md @@ -780,6 +780,9 @@ resource = MCP::Resource.new( title: "My Resource", # WARNING: This is a `Draft` and is not supported in the `Version 2025-06-18 (latest)` specification. description: "Lorem ipsum dolor sit amet", mime_type: "text/html", + annotations: { category: "documentation" }, + size: 1024, + meta: { version: "1.0", last_updated: "2024-01-01" } ) server = MCP::Server.new( @@ -813,6 +816,8 @@ resource_template = MCP::ResourceTemplate.new( title: "My Resource Template", # WARNING: This is a `Draft` and is not supported in the `Version 2025-06-18 (latest)` specification. description: "Lorem ipsum dolor sit amet", mime_type: "text/html", + annotations: { category: "template" }, + meta: { version: "1.0", template_type: "dynamic" } ) server = MCP::Server.new( diff --git a/lib/mcp/resource.rb b/lib/mcp/resource.rb index 5086a8e..9e94adb 100644 --- a/lib/mcp/resource.rb +++ b/lib/mcp/resource.rb @@ -2,23 +2,29 @@ module MCP class Resource - attr_reader :uri, :name, :title, :description, :mime_type + attr_reader :name, :title, :uri, :description, :mime_type, :annotations, :size, :meta - def initialize(uri:, name:, title: nil, description: nil, mime_type: nil) - @uri = uri + def initialize(uri:, name:, title: nil, description: nil, mime_type: nil, annotations: nil, size: nil, meta: {}) @name = name @title = title + @uri = uri @description = description @mime_type = mime_type + @annotations = annotations + @size = size + @meta = meta end def to_h { - uri: uri, name: name, title: title, + uri: uri, description: description, mimeType: mime_type, + annotations: annotations&.to_h, + size: size, + _meta: meta, }.compact end end diff --git a/lib/mcp/resource_template.rb b/lib/mcp/resource_template.rb index 9134c22..de3d7c2 100644 --- a/lib/mcp/resource_template.rb +++ b/lib/mcp/resource_template.rb @@ -2,23 +2,27 @@ module MCP class ResourceTemplate - attr_reader :uri_template, :name, :title, :description, :mime_type + attr_reader :name, :title, :uri_template, :description, :mime_type, :annotations, :meta - def initialize(uri_template:, name:, title: nil, description: nil, mime_type: nil) - @uri_template = uri_template + def initialize(uri_template:, name:, title: nil, description: nil, mime_type: nil, annotations: nil, meta: nil) @name = name @title = title + @uri_template = uri_template @description = description @mime_type = mime_type + @annotations = annotations + @meta = meta || {} end def to_h { - uriTemplate: uri_template, name: name, title: title, + uriTemplate: uri_template, description: description, mimeType: mime_type, + annotations: annotations&.to_h, + _meta: meta.empty? ? nil : meta, }.compact end end