{"jsonrpc": "2.0","id": 2,"method": "resources/read","params": {"uri": "taco://menu/items/carne-asada"}
}
{"jsonrpc": "2.0","id": 2,"result": {"contents": [{"uri": "taco://menu/items/carne-asada","mimeType": "application/json","text": "{\"name\":\"Carne Asada Taco\",\"ingredients\":[\"steak\",\"tortilla\",\"onion\",\"cilantro\"],\"instructions\":\"Grill the steak, chop into small pieces, serve on warm tortillas\"}"}]}
}
ResourceTemplate: you can assign each resoure a uri to load a single resource.
Resource templates let you define parameterized resources, like epicme://entries/{id} or epicme://tags/{id}. This means clients can discover and read individual entries or tags by their unique identifiers, just like accessing a file by its path.
import { invariant } from '@epic-web/invariant'
import { ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js'
import { type EpicMeMCP } from './index.ts'export async function initializeResources(agent: EpicMeMCP) {agent.server.registerResource('tags','epicme://tags',{title: 'Tags',description: 'All tags currently in the database',},async (uri) => {const tags = await agent.db.getTags()return {contents: [{mimeType: 'application/json',text: JSON.stringify(tags),uri: uri.toString(),},],}},)agent.server.registerResource('tag',new ResourceTemplate('epicme://tags/{id}', {// 🐨 implement this list callback to get all tags (💰 agent.db.getTags())// 🐨 return an object with a "resources" property that is an array of resource listings (💰 each object has a name, uri, and mimeType).complete: {async id(value) {const tags = await agent.db.getTags()return tags.map((tag) => tag.id.toString()).filter((id) => id.includes(value)).slice(0, 100)},},list: async () => {const tags = await agent.db.getTags()return {resources: tags.map((tag) => ({name: tag.name,uri: `epicme://tags/${tag.id}`,mimeType: 'application/json',})),}},}),{title: 'Tag',description: 'A single tag with the given ID',},async (uri, { id }) => {const tag = await agent.db.getTag(Number(id))invariant(tag, `Tag with ID "${id}" not found`)return {contents: [{mimeType: 'application/json',text: JSON.stringify(tag),uri: uri.toString(),},],}},)agent.server.registerResource('entry',new ResourceTemplate('epicme://entries/{id}', {complete: {async id(value) {const entries = await agent.db.getEntries()return entries.map((entry) => entry.id.toString()).filter((id) => id.includes(value)).slice(0, 100)},},list: undefined,}),{title: 'Journal Entry',description: 'A single journal entry with the given ID',},async (uri, { id }) => {const entry = await agent.db.getEntry(Number(id))invariant(entry, `Entry with ID "${id}" not found`)return {contents: [{mimeType: 'application/json',text: JSON.stringify(entry),uri: uri.toString(),},],}},)
}