Update resources.mdx
This commit is contained in:
parent
a2e6868c40
commit
69212f30b0
1 changed files with 70 additions and 51 deletions
|
|
@ -24,7 +24,7 @@ Each resource is identified by a unique URI and can contain either text or binar
|
||||||
Resources are identified using URIs that follow this format:
|
Resources are identified using URIs that follow this format:
|
||||||
|
|
||||||
```
|
```
|
||||||
[protocol]://[path]
|
[protocol]://[host]/[path]
|
||||||
```
|
```
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
@ -75,7 +75,7 @@ Servers expose a list of concrete resources via the `resources/list` endpoint. E
|
||||||
|
|
||||||
### Resource templates
|
### Resource templates
|
||||||
|
|
||||||
For dynamic resources, servers can expose URI templates that clients can use to construct valid resource URIs:
|
For dynamic resources, servers can expose [URI templates](https://datatracker.ietf.org/doc/html/rfc6570) that clients can use to construct valid resource URIs:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
{
|
{
|
||||||
|
|
@ -88,13 +88,15 @@ For dynamic resources, servers can expose URI templates that clients can use to
|
||||||
|
|
||||||
## Reading resources
|
## Reading resources
|
||||||
|
|
||||||
To read a resource, clients make a `resources/read` request with the resource URI. The server responds with:
|
To read a resource, clients make a `resources/read` request with the resource URI.
|
||||||
|
|
||||||
|
The server responds with a list of resource contents:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
{
|
{
|
||||||
contents: [
|
contents: [
|
||||||
{
|
{
|
||||||
uri: string; // The requested URI
|
uri: string; // The URI of the resource
|
||||||
mimeType?: string; // Optional MIME type
|
mimeType?: string; // Optional MIME type
|
||||||
|
|
||||||
// One of:
|
// One of:
|
||||||
|
|
@ -105,6 +107,10 @@ To read a resource, clients make a `resources/read` request with the resource UR
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
<Tip>
|
||||||
|
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.
|
||||||
|
</Tip>
|
||||||
|
|
||||||
## Resource updates
|
## Resource updates
|
||||||
|
|
||||||
MCP supports real-time updates for resources through two mechanisms:
|
MCP supports real-time updates for resources through two mechanisms:
|
||||||
|
|
@ -126,10 +132,16 @@ Clients can subscribe to updates for specific resources:
|
||||||
|
|
||||||
Here's a simple example of implementing resource support in an MCP server:
|
Here's a simple example of implementing resource support in an MCP server:
|
||||||
|
|
||||||
|
<Tabs>
|
||||||
|
<Tab title="TypeScript">
|
||||||
```typescript
|
```typescript
|
||||||
const server = new Server({
|
const server = new Server({
|
||||||
name: "example-server",
|
name: "example-server",
|
||||||
version: "1.0.0"
|
version: "1.0.0"
|
||||||
|
}, {
|
||||||
|
capabilities: {
|
||||||
|
resources: {}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// List available resources
|
// List available resources
|
||||||
|
|
@ -165,6 +177,13 @@ server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
|
||||||
throw new Error("Resource not found");
|
throw new Error("Resource not found");
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
</Tab>
|
||||||
|
<Tab title="Python">
|
||||||
|
```python
|
||||||
|
# Python implementation coming soon
|
||||||
|
```
|
||||||
|
</Tab>
|
||||||
|
</Tabs>
|
||||||
|
|
||||||
## Best practices
|
## Best practices
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue