Skip to content

Commit 109f881

Browse files
fix: Use _meta field instead of meta in ResourceContents examples
Corrected the examples to use the proper _meta field name as specified in the MCP protocol, rather than the constructor parameter name 'meta'. This ensures the metadata appears correctly when viewed in MCP Inspector. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent a6e8950 commit 109f881

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

examples/snippets/servers/lowlevel/resource_contents_direct.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async def read_resource(uri: AnyUrl) -> Iterable[types.TextResourceContents | ty
3737
uri=uri,
3838
text="# README\n\nThis is a sample readme file.",
3939
mimeType="text/markdown",
40-
meta={
40+
_meta={
4141
"title": "Project README",
4242
"author": "Development Team",
4343
"lastModified": "2024-01-15T10:00:00Z",
@@ -55,7 +55,7 @@ async def read_resource(uri: AnyUrl) -> Iterable[types.TextResourceContents | ty
5555
uri=uri,
5656
text='{\n "version": "1.0.0",\n "debug": false\n}',
5757
mimeType="application/json",
58-
meta={
58+
_meta={
5959
"schema": "https://example.com/schemas/config/v1.0",
6060
"validated": True,
6161
"environment": "production",
@@ -77,7 +77,7 @@ async def read_resource(uri: AnyUrl) -> Iterable[types.TextResourceContents | ty
7777
uri=uri,
7878
blob=base64.b64encode(png_data).decode(),
7979
mimeType="image/png",
80-
meta={
80+
_meta={
8181
"width": 1,
8282
"height": 1,
8383
"bitDepth": 8,
@@ -100,7 +100,7 @@ async def read_resource(uri: AnyUrl) -> Iterable[types.TextResourceContents | ty
100100
uri=uri,
101101
text="Part 1: Introduction",
102102
mimeType="text/plain",
103-
meta={
103+
_meta={
104104
"part": 1,
105105
"title": "Introduction",
106106
"order": 1,
@@ -111,7 +111,7 @@ async def read_resource(uri: AnyUrl) -> Iterable[types.TextResourceContents | ty
111111
uri=uri,
112112
text="## Part 2: Main Content\n\nThis is the main section.",
113113
mimeType="text/markdown",
114-
meta={
114+
_meta={
115115
"part": 2,
116116
"title": "Main Content",
117117
"order": 2,
@@ -123,7 +123,7 @@ async def read_resource(uri: AnyUrl) -> Iterable[types.TextResourceContents | ty
123123
uri=uri,
124124
blob="UGFydCAzOiBCaW5hcnkgRGF0YQ==", # "Part 3: Binary Data" in base64
125125
mimeType="application/octet-stream",
126-
meta={
126+
_meta={
127127
"part": 3,
128128
"title": "Binary Attachment",
129129
"order": 3,
@@ -149,7 +149,7 @@ async def read_resource(uri: AnyUrl) -> Iterable[types.TextResourceContents | ty
149149
uri=uri,
150150
text=code,
151151
mimeType=mime_type,
152-
meta={
152+
_meta={
153153
"language": language,
154154
"syntaxHighlighting": True,
155155
"lineNumbers": True,

examples/snippets/servers/resource_contents_direct.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Example showing how to return ResourceContents objects directly from resources.
33
44
The main benefit of returning ResourceContents directly is the ability to include
5-
metadata through the _meta field (exposed as 'meta' in the constructor). This allows
5+
metadata through the _meta field. This allows
66
you to attach additional context to your resources such as:
77
88
- Timestamps (created, modified, expires)
@@ -34,7 +34,7 @@ def get_report() -> TextResourceContents:
3434
text="# Monthly Report\n\nThis is the monthly report content.",
3535
mimeType="text/markdown",
3636
# The main benefit: adding metadata to the resource
37-
meta={
37+
_meta={
3838
"created": "2024-01-15T10:30:00Z",
3939
"author": "Analytics Team",
4040
"version": "1.2.0",
@@ -56,7 +56,7 @@ def get_logo() -> BlobResourceContents:
5656
blob=base64.b64encode(image_bytes).decode(),
5757
mimeType="image/png",
5858
# Image-specific metadata
59-
meta={
59+
_meta={
6060
"width": 512,
6161
"height": 512,
6262
"format": "PNG",
@@ -84,7 +84,7 @@ async def get_metrics(metric_type: str) -> TextResourceContents:
8484
uri=AnyUrl(f"data://metrics/{metric_type}"),
8585
text=json.dumps(metrics, indent=2),
8686
mimeType="application/json",
87-
meta={
87+
_meta={
8888
"timestamp": timestamp,
8989
"source": "system_monitor",
9090
"interval": "5s",
@@ -98,7 +98,7 @@ async def get_metrics(metric_type: str) -> TextResourceContents:
9898
uri=AnyUrl(f"data://metrics/{metric_type}"),
9999
text=csv_text,
100100
mimeType="text/csv",
101-
meta={
101+
_meta={
102102
"timestamp": timestamp,
103103
"columns": ["metric", "value"],
104104
"row_count": len(metrics),
@@ -110,7 +110,7 @@ async def get_metrics(metric_type: str) -> TextResourceContents:
110110
uri=AnyUrl(f"data://metrics/{metric_type}"),
111111
text=text,
112112
mimeType="text/plain",
113-
meta={
113+
_meta={
114114
"timestamp": timestamp,
115115
"format": "human-readable",
116116
}
@@ -140,7 +140,7 @@ def get_config() -> TextResourceContents:
140140
uri=AnyUrl("config://app"),
141141
text=json.dumps(config, indent=2),
142142
mimeType="application/json",
143-
meta={
143+
_meta={
144144
"version": "1.0.0",
145145
"lastUpdated": "2024-01-15T14:30:00Z",
146146
"environment": "production",
@@ -170,7 +170,7 @@ async def get_users() -> TextResourceContents:
170170
uri=AnyUrl("db://query/users"),
171171
text=json.dumps(users, indent=2),
172172
mimeType="application/json",
173-
meta={
173+
_meta={
174174
"query": "SELECT * FROM users",
175175
"executionTime": f"{execution_time:.3f}s",
176176
"rowCount": len(users),

0 commit comments

Comments
 (0)