Missed one
This commit is contained in:
parent
16b0cc8ccc
commit
335db056fc
1 changed files with 18 additions and 33 deletions
|
|
@ -145,47 +145,32 @@ Here's a simple example of implementing resource support in an MCP server:
|
||||||
<Tabs>
|
<Tabs>
|
||||||
<Tab title="TypeScript">
|
<Tab title="TypeScript">
|
||||||
```typescript
|
```typescript
|
||||||
const server = new Server({
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
|
|
||||||
|
const server = new McpServer({
|
||||||
name: "example-server",
|
name: "example-server",
|
||||||
version: "1.0.0"
|
version: "1.0.0"
|
||||||
}, {
|
|
||||||
capabilities: {
|
|
||||||
resources: {}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// List available resources
|
// Add static resource
|
||||||
server.setRequestHandler(ListResourcesRequestSchema, async () => {
|
server.resource(
|
||||||
return {
|
"logs",
|
||||||
resources: [
|
"file:///logs/app.log",
|
||||||
{
|
{
|
||||||
uri: "file:///logs/app.log",
|
mimeType: "text/plain",
|
||||||
name: "Application Logs",
|
description: "Application log file"
|
||||||
mimeType: "text/plain"
|
},
|
||||||
}
|
async (uri) => {
|
||||||
]
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
// Read resource contents
|
|
||||||
server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
|
|
||||||
const uri = request.params.uri;
|
|
||||||
|
|
||||||
if (uri === "file:///logs/app.log") {
|
|
||||||
const logContents = await readLogFile();
|
const logContents = await readLogFile();
|
||||||
return {
|
return {
|
||||||
contents: [
|
contents: [{
|
||||||
{
|
uri: uri.href,
|
||||||
uri,
|
mimeType: "text/plain",
|
||||||
mimeType: "text/plain",
|
text: logContents
|
||||||
text: logContents
|
}]
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
);
|
||||||
throw new Error("Resource not found");
|
|
||||||
});
|
|
||||||
```
|
```
|
||||||
</Tab>
|
</Tab>
|
||||||
<Tab title="Python">
|
<Tab title="Python">
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue