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:
|
||||
|
||||
```
|
||||
[protocol]://[path]
|
||||
[protocol]://[host]/[path]
|
||||
```
|
||||
|
||||
For example:
|
||||
|
|
@ -75,7 +75,7 @@ Servers expose a list of concrete resources via the `resources/list` endpoint. E
|
|||
|
||||
### 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
|
||||
{
|
||||
|
|
@ -88,13 +88,15 @@ For dynamic resources, servers can expose URI templates that clients can use to
|
|||
|
||||
## 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
|
||||
{
|
||||
contents: [
|
||||
{
|
||||
uri: string; // The requested URI
|
||||
uri: string; // The URI of the resource
|
||||
mimeType?: string; // Optional MIME type
|
||||
|
||||
// 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
|
||||
|
||||
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:
|
||||
|
||||
<Tabs>
|
||||
<Tab title="TypeScript">
|
||||
```typescript
|
||||
const server = new Server({
|
||||
name: "example-server",
|
||||
version: "1.0.0"
|
||||
}, {
|
||||
capabilities: {
|
||||
resources: {}
|
||||
}
|
||||
});
|
||||
|
||||
// List available resources
|
||||
|
|
@ -165,6 +177,13 @@ server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
|
|||
throw new Error("Resource not found");
|
||||
});
|
||||
```
|
||||
</Tab>
|
||||
<Tab title="Python">
|
||||
```python
|
||||
# Python implementation coming soon
|
||||
```
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
## Best practices
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue