|
|
MCP Server with Resources and Prompts
Author: Venkata Sudhakar
MCP defines three primitives: Tools (executable functions), Resources (readable data), and Prompts (reusable prompt templates). Most tutorials focus on tools, but Resources and Prompts unlock powerful patterns. Resources let the MCP server expose live data - like a product catalogue or policy document - that the agent reads as context. Prompts let the server provide pre-built instruction templates that ensure consistent agent behaviour across different sessions.
FastMCP exposes resources with @mcp.resource() and prompts with @mcp.prompt(). Resources have a URI scheme (e.g. shopmax://policies/returns) and return text content. Prompts accept parameters and return formatted message strings. Both are loaded by the ADK agent client and can be injected into the agent instruction or used as context before a query.
The below example shows a ShopMax India MCP server that exposes a returns policy resource and a complaint response prompt template.
Connect an ADK agent to use the resources and prompt templates,
It gives the following output,
Q: What is the return policy for electronics?...
A: Electronics at ShopMax India are returnable within 7 days from delivery
if defective. Refunds are credited within 3-5 business days to the original
payment method.
Q: Generate a complaint response for Meera Singh about a delayed...
A: Dear Meera Singh,
Thank you for reaching out to ShopMax India regarding: delayed TV delivery.
We sincerely apologise for the inconvenience caused.
Resolution: full refund of Rs 35000
We value your loyalty and hope to serve you better.
Warm regards,
ShopMax India Customer Care
Resources are ideal for content that changes infrequently - policy documents, pricing tiers, or configuration. Update the resource implementation when the underlying data changes and all agents get the new content automatically without any agent code changes. Prompts standardise communication tone across your entire agent fleet: whether 10 or 100 agents are running, they all use the same complaint_response_prompt template, ensuring brand-consistent customer communications. Version your prompt templates using the prompt name (e.g. complaint_response_v2) to allow gradual rollout of tone changes.
|
|