-
Book Overview & Buying
-
Table Of Contents
Model Context Protocol for LLMs
By :
Now that we understand what makes a good server – anticipating needs, handling complexity gracefully, and remaining invisible to the user – let's see those principles in action. The following code implements a basic MCP server that lists resources and calls tools based on context. Notice how it filters resources by user role and adapts search results to the user's context, illustrating the ideas of discoverable capabilities and contextual awareness we discussed earlier.
Here's a minimal example that illustrates the key concepts we've discussed:
This example demonstrates contextual awareness (filtering documents based on user role), discoverability (listing available resources), and adaptivity (modifying search results using the user's context).
DocumentMCPServer class:
class DocumentMCPServer:
"""A simple MCP server demonstrating core concepts."...