Skip to content

Commit 69212f3

Browse files
committed
Update resources.mdx
1 parent a2e6868 commit 69212f3

File tree

1 file changed

+70
-51
lines changed

1 file changed

+70
-51
lines changed

docs/concepts/resources.mdx

Lines changed: 70 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Each resource is identified by a unique URI and can contain either text or binar
2424
Resources are identified using URIs that follow this format:
2525

2626
```
27-
[protocol]://[path]
27+
[protocol]://[host]/[path]
2828
```
2929

3030
For example:
@@ -42,7 +42,7 @@ Resources can contain two types of content:
4242

4343
Text resources contain UTF-8 encoded text data. These are suitable for:
4444
- Source code
45-
- Configuration files
45+
- Configuration files
4646
- Log files
4747
- JSON/XML data
4848
- Plain text
@@ -66,37 +66,39 @@ Servers expose a list of concrete resources via the `resources/list` endpoint. E
6666

6767
```typescript
6868
{
69-
uri: string; // Unique identifier for the resource
70-
name: string; // Human-readable name
69+
uri: string; // Unique identifier for the resource
70+
name: string; // Human-readable name
7171
description?: string; // Optional description
72-
mimeType?: string; // Optional MIME type
72+
mimeType?: string; // Optional MIME type
7373
}
7474
```
7575

76-
### Resource templates
76+
### Resource templates
7777

78-
For dynamic resources, servers can expose URI templates that clients can use to construct valid resource URIs:
78+
For dynamic resources, servers can expose [URI templates](https://datatracker.ietf.org/doc/html/rfc6570) that clients can use to construct valid resource URIs:
7979

8080
```typescript
8181
{
8282
uriTemplate: string; // URI template following RFC 6570
8383
name: string; // Human-readable name for this type
8484
description?: string; // Optional description
85-
mimeType?: string; // Optional MIME type for all matching resources
85+
mimeType?: string; // Optional MIME type for all matching resources
8686
}
8787
```
8888

8989
## Reading resources
9090

91-
To read a resource, clients make a `resources/read` request with the resource URI. The server responds with:
91+
To read a resource, clients make a `resources/read` request with the resource URI.
92+
93+
The server responds with a list of resource contents:
9294

9395
```typescript
9496
{
9597
contents: [
9698
{
97-
uri: string; // The requested URI
99+
uri: string; // The URI of the resource
98100
mimeType?: string; // Optional MIME type
99-
101+
100102
// One of:
101103
text?: string; // For text resources
102104
blob?: string; // For binary resources (base64 encoded)
@@ -105,6 +107,10 @@ To read a resource, clients make a `resources/read` request with the resource UR
105107
}
106108
```
107109

110+
<Tip>
111+
Servers may return multiple resources in response to one `resources/read` request. This could be used, for example, to return a list of files inside a directory when the directory is read.
112+
</Tip>
113+
108114
## Resource updates
109115

110116
MCP supports real-time updates for resources through two mechanisms:
@@ -113,7 +119,7 @@ MCP supports real-time updates for resources through two mechanisms:
113119

114120
Servers can notify clients when their list of available resources changes via the `notifications/resources/list_changed` notification.
115121

116-
### Content changes
122+
### Content changes
117123

118124
Clients can subscribe to updates for specific resources:
119125

@@ -126,45 +132,58 @@ Clients can subscribe to updates for specific resources:
126132

127133
Here's a simple example of implementing resource support in an MCP server:
128134

129-
```typescript
130-
const server = new Server({
131-
name: "example-server",
132-
version: "1.0.0"
133-
});
134-
135-
// List available resources
136-
server.setRequestHandler(ListResourcesRequestSchema, async () => {
137-
return {
138-
resources: [
139-
{
140-
uri: "file:///logs/app.log",
141-
name: "Application Logs",
142-
mimeType: "text/plain"
135+
<Tabs>
136+
<Tab title="TypeScript">
137+
```typescript
138+
const server = new Server({
139+
name: "example-server",
140+
version: "1.0.0"
141+
}, {
142+
capabilities: {
143+
resources: {}
143144
}
144-
]
145-
};
146-
});
147-
148-
// Read resource contents
149-
server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
150-
const uri = request.params.uri;
151-
152-
if (uri === "file:///logs/app.log") {
153-
const logContents = await readLogFile();
154-
return {
155-
contents: [
156-
{
157-
uri,
158-
mimeType: "text/plain",
159-
text: logContents
160-
}
161-
]
162-
};
163-
}
164-
165-
throw new Error("Resource not found");
166-
});
167-
```
145+
});
146+
147+
// List available resources
148+
server.setRequestHandler(ListResourcesRequestSchema, async () => {
149+
return {
150+
resources: [
151+
{
152+
uri: "file:///logs/app.log",
153+
name: "Application Logs",
154+
mimeType: "text/plain"
155+
}
156+
]
157+
};
158+
});
159+
160+
// Read resource contents
161+
server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
162+
const uri = request.params.uri;
163+
164+
if (uri === "file:///logs/app.log") {
165+
const logContents = await readLogFile();
166+
return {
167+
contents: [
168+
{
169+
uri,
170+
mimeType: "text/plain",
171+
text: logContents
172+
}
173+
]
174+
};
175+
}
176+
177+
throw new Error("Resource not found");
178+
});
179+
```
180+
</Tab>
181+
<Tab title="Python">
182+
```python
183+
# Python implementation coming soon
184+
```
185+
</Tab>
186+
</Tabs>
168187

169188
## Best practices
170189

@@ -194,4 +213,4 @@ When exposing resources:
194213
- Encrypt sensitive data in transit
195214
- Validate MIME types
196215
- Implement timeouts for long-running reads
197-
- Handle resource cleanup appropriately
216+
- Handle resource cleanup appropriately

0 commit comments

Comments
 (0)