AI Hints
Home›MCP Tutorial›Using Resources
MCP · Lesson 35 of 120

Files as Resources

A docs folder.

⏱ 2 min read▶ Video at 31:49🎓 Free
Watch this lesson in the MCP courseWatch on YouTube ↗Full MCP course

Northwind's help pages are markdown files. A template can expose the whole folder, one resource per file, with the file name in the URI.

Files as Resources
From the video: Files as Resources
  • Help pages
  • One template
  • File name in the URI

A docs template

Docs is the help folder. The template takes a file name, checks it's a real page in that folder, and returns its text. We read the shipping page. Run it. The page arrives as markdown.

docs_resource.pypython
import asyncio
from pathlib import Path
from mcp import Client
from mcp.server.mcpserver import MCPServer

DOCS = Path("data/rag/northwind").resolve()
mcp = MCPServer("docs")

@mcp.resource("docs://{name}", mime_type="text/markdown")
def help_page(name: str) -> str:
    """One Northwind help page, like shipping.md."""
    path = (DOCS / name).resolve()
    if not path.is_relative_to(DOCS) or not path.is_file(): raise ValueError("no such page")
    return path.read_text()

async def main():
    async with Client(mcp) as client:
        print((await client.read_resource("docs://shipping.md")).contents[0].text[:90])
asyncio.run(main())
Output
# Shipping and delivery

## UK delivery
Standard delivery in the UK takes 3 to 5 working d

Listing files

A template doesn't list every file by itself. To let clients see the pages, also register a fixed resource for each file, or a list resource that returns the names. Always keep the same path checks as file tools.

keyvalue
Templateany file by name
Listingfixed resources too
Checkssame as file tools
Mimetext/markdown

Summary

A template can serve a whole folder of files, with the same path checks as file tools. Next, choosing between resources and tools.

Key takeaways
  • docs://{name}
  • Path checks
  • Markdown
Next up: Resources or Tools — how to choose