Summary audio
Spoken summary — press play to read along: the line being spoken stays near the top.
Study notes
MCP Resources: Document Mention Feature
**I. Core Concept & Purpose**
- Goal: To allow users to mention documents (e. g. , @report. pdf) within a message, enabling the system to automatically fetch and insert the document's content into the prompt sent to the LLM (Claude).
- Function: Resources allow the MCP server to expose specific data or read operations to the client.
- Feature Breakdown:
- Autocomplete: When the user types @, the MCP server must provide a list of all available document names.
- Content Fetch: When the user submits a message containing a mention, the MCP server must retrieve the content of that specific document.
**II. Resource Types**
- Direct (Static) Resources:
- Have a fixed, unchanging URI (e. g. , docs://documents).
- Used for operations that do not require user input parameters.
- Templated Resources:
- Contain one or more parameters or wildcards within the URI (e. g. , docs://documents/{doc_id}).
- The MCP Python SDK automatically parses these URI parameters and passes them as keyword arguments to the associated server function.
- Used for operations requiring selection or customization (e. g. , fetching a specific document).
**III. Implementation Workflow**
- Client Request: The client initiates a "Read Resource Request" by sending the defined URI to the MCP server.
- Server Execution: The MCP server uses the URI to locate and execute the corresponding function.
- Response: The server returns the data within a "Read Resource Result Message. "
- Data Handling: The client receives the result and handles the data based on the specified MIME type (e. g. , JSON or plain text).
**IV. Example Resource Definitions**
- Resource 1: List Documents (Static)
- URI: docs://documents
- MIME Type: application/json
- Function: Returns a list of all document IDs (keys) from the server's data structure.
- Resource 2: Fetch Document (Templated)
- URI: docs://documents/{doc_id}
- MIME Type: text/plain
- Function: Accepts doc_id as a keyword argument, verifies its existence, and returns the document's content as a string.
Takeaways
- MCP Resources allow users to mention documents (e. g. , @report. pdf) in messages, enabling the system to automatically fetch and insert the document's content into the LLM prompt.
- Resources are categorized as Direct (Static, fixed URI) or Templated (Parameterized, requires user input).
- Templated resources use URI parameters (e. g. , {doc_id}), which the MCP SDK automatically parses and passes as keyword arguments to the server function.
- The implementation workflow involves the client initiating a "Read Resource Request" and the MCP server responding with a "Read Resource Result Message. "
Flashcards 10 cards
Question
click to reveal · ←/→
Answer
click to flip back
Knowledge check 6 questions