Missed one

This commit is contained in:
Justin Spahr-Summers 2025-01-21 14:17:10 +00:00
commit 335db056fc
No known key found for this signature in database

View file

@ -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">