From 335db056fc648e8fc0b97caab188b43b78f3139c Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Tue, 21 Jan 2025 14:17:10 +0000 Subject: [PATCH] Missed one --- docs/concepts/resources.mdx | 51 +++++++++++++------------------------ 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/docs/concepts/resources.mdx b/docs/concepts/resources.mdx index 50eb8eb..31aba5e 100644 --- a/docs/concepts/resources.mdx +++ b/docs/concepts/resources.mdx @@ -145,47 +145,32 @@ Here's a simple example of implementing resource support in an MCP server: ```typescript - const server = new Server({ + import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; + + const server = new McpServer({ name: "example-server", version: "1.0.0" - }, { - capabilities: { - resources: {} - } }); - // List available resources - server.setRequestHandler(ListResourcesRequestSchema, async () => { - return { - resources: [ - { - uri: "file:///logs/app.log", - name: "Application Logs", - mimeType: "text/plain" - } - ] - }; - }); - - // Read resource contents - server.setRequestHandler(ReadResourceRequestSchema, async (request) => { - const uri = request.params.uri; - - if (uri === "file:///logs/app.log") { + // Add static resource + server.resource( + "logs", + "file:///logs/app.log", + { + mimeType: "text/plain", + description: "Application log file" + }, + async (uri) => { const logContents = await readLogFile(); return { - contents: [ - { - uri, - mimeType: "text/plain", - text: logContents - } - ] + contents: [{ + uri: uri.href, + mimeType: "text/plain", + text: logContents + }] }; } - - throw new Error("Resource not found"); - }); + ); ```