Skip to content

Commit 0534ff1

Browse files
committed
spec compliance of resources
1 parent b5e344e commit 0534ff1

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,9 @@ resource = MCP::Resource.new(
780780
title: "My Resource", # WARNING: This is a `Draft` and is not supported in the `Version 2025-06-18 (latest)` specification.
781781
description: "Lorem ipsum dolor sit amet",
782782
mime_type: "text/html",
783+
annotations: { category: "documentation" },
784+
size: 1024,
785+
meta: { version: "1.0", last_updated: "2024-01-01" }
783786
)
784787

785788
server = MCP::Server.new(
@@ -813,6 +816,8 @@ resource_template = MCP::ResourceTemplate.new(
813816
title: "My Resource Template", # WARNING: This is a `Draft` and is not supported in the `Version 2025-06-18 (latest)` specification.
814817
description: "Lorem ipsum dolor sit amet",
815818
mime_type: "text/html",
819+
annotations: { category: "template" },
820+
meta: { version: "1.0", template_type: "dynamic" }
816821
)
817822

818823
server = MCP::Server.new(

lib/mcp/resource.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,29 @@
22

33
module MCP
44
class Resource
5-
attr_reader :uri, :name, :title, :description, :mime_type
5+
attr_reader :name, :title, :uri, :description, :mime_type, :annotations, :size, :meta
66

7-
def initialize(uri:, name:, title: nil, description: nil, mime_type: nil)
8-
@uri = uri
7+
def initialize(uri:, name:, title: nil, description: nil, mime_type: nil, annotations: nil, size: nil, meta: {})
98
@name = name
109
@title = title
10+
@uri = uri
1111
@description = description
1212
@mime_type = mime_type
13+
@annotations = annotations
14+
@size = size
15+
@meta = meta
1316
end
1417

1518
def to_h
1619
{
17-
uri: uri,
1820
name: name,
1921
title: title,
22+
uri: uri,
2023
description: description,
2124
mimeType: mime_type,
25+
annotations: annotations&.to_h,
26+
size: size,
27+
_meta: meta,
2228
}.compact
2329
end
2430
end

lib/mcp/resource_template.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,27 @@
22

33
module MCP
44
class ResourceTemplate
5-
attr_reader :uri_template, :name, :title, :description, :mime_type
5+
attr_reader :name, :title, :uri_template, :description, :mime_type, :annotations, :meta
66

7-
def initialize(uri_template:, name:, title: nil, description: nil, mime_type: nil)
8-
@uri_template = uri_template
7+
def initialize(uri_template:, name:, title: nil, description: nil, mime_type: nil, annotations: nil, meta: nil)
98
@name = name
109
@title = title
10+
@uri_template = uri_template
1111
@description = description
1212
@mime_type = mime_type
13+
@annotations = annotations
14+
@meta = meta || {}
1315
end
1416

1517
def to_h
1618
{
17-
uriTemplate: uri_template,
1819
name: name,
1920
title: title,
21+
uriTemplate: uri_template,
2022
description: description,
2123
mimeType: mime_type,
24+
annotations: annotations&.to_h,
25+
_meta: meta.empty? ? nil : meta,
2226
}.compact
2327
end
2428
end

0 commit comments

Comments
 (0)