Skip to content

Commit 37ed555

Browse files
committed
refactor: remove list callback implementation for entry resource template
1 parent 121f7a5 commit 37ed555

File tree

15 files changed

+19
-143
lines changed

15 files changed

+19
-143
lines changed

exercises/03.resources/03.problem.list/README.mdx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Resource Templates List
22

3-
👨‍💼 Our users want to be able to see a list of all entries and tags. So let's
4-
implement the `list` callback for our resource templates.
3+
👨‍💼 Our users want to be able to see a list of all tags. So let's implement the
4+
`list` callback for our resource templates.
55

66
```ts
77
import { ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js'
@@ -27,8 +27,8 @@ agent.server.registerResource(
2727
```
2828

2929
Notice how the `list` callback queries the database and returns a resource
30-
listing for each name. This pattern is exactly what you'll use to expose entries
31-
and tags from your own database.
30+
listing for each name. This pattern is exactly what you'll use to expose tags
31+
from your own database.
3232

3333
<callout-success>
3434
The reason for the `list` callback is to make it easy for clients to get a
@@ -37,11 +37,4 @@ and tags from your own database.
3737
and type in the `list` callback).
3838
</callout-success>
3939

40-
Your goal in this step:
41-
42-
- Use resource templates to expose entries and tags from your database, each
43-
accessible by a unique URI.
44-
- Make sure clients can list all available entries and tags (using the `list`
45-
callback), and read the details for any specific one.
46-
4740
To test this out, click the "List Resources" button in the MCP Inspector.

exercises/03.resources/03.problem.list/src/resources.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ export async function initializeResources(agent: EpicMeMCP) {
5353
agent.server.registerResource(
5454
'entry',
5555
new ResourceTemplate('epicme://entries/{id}', {
56-
// 🐨 implement this list callback to get all entries (💰 agent.db.getEntries())
57-
// 🐨 return an object with a "resources" property that is an array of resource listings (💰 each object has a name, uri, and mimeType).
56+
// 🦉 there are probably too many journal entries to list them all, so
57+
// we'll not implement the list callback for this resource template.
5858
list: undefined,
5959
}),
6060
{

exercises/03.resources/03.solution.list/src/resources.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,7 @@ export async function initializeResources(agent: EpicMeMCP) {
6060
agent.server.registerResource(
6161
'entry',
6262
new ResourceTemplate('epicme://entries/{id}', {
63-
list: async () => {
64-
const entries = await agent.db.getEntries()
65-
return {
66-
resources: entries.map((entry) => ({
67-
name: entry.title,
68-
uri: `epicme://entries/${entry.id}`,
69-
mimeType: 'application/json',
70-
})),
71-
}
72-
},
63+
list: undefined,
7364
}),
7465
{
7566
title: 'Journal Entry',

exercises/03.resources/04.problem.completion/src/resources.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,10 @@ export async function initializeResources(agent: EpicMeMCP) {
6363
agent.server.registerResource(
6464
'entry',
6565
new ResourceTemplate('epicme://entries/{id}', {
66+
list: undefined,
6667
// 🐨 add a `complete` callback for the `id` parameter
6768
// 🐨 accept a value and return an array of strings of ids that include the value
6869
// 💰 const entries = await agent.db.getEntries()
69-
list: async () => {
70-
const entries = await agent.db.getEntries()
71-
return {
72-
resources: entries.map((entry) => ({
73-
name: entry.title,
74-
uri: `epicme://entries/${entry.id}`,
75-
mimeType: 'application/json',
76-
})),
77-
}
78-
},
7970
}),
8071
{
8172
title: 'Journal Entry',

exercises/03.resources/04.solution.completion/src/resources.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export async function initializeResources(agent: EpicMeMCP) {
6868
agent.server.registerResource(
6969
'entry',
7070
new ResourceTemplate('epicme://entries/{id}', {
71+
list: undefined,
7172
complete: {
7273
async id(value) {
7374
const entries = await agent.db.getEntries()
@@ -76,16 +77,6 @@ export async function initializeResources(agent: EpicMeMCP) {
7677
.filter((id) => id.includes(value))
7778
},
7879
},
79-
list: async () => {
80-
const entries = await agent.db.getEntries()
81-
return {
82-
resources: entries.map((entry) => ({
83-
name: entry.title,
84-
uri: `epicme://entries/${entry.id}`,
85-
mimeType: 'application/json',
86-
})),
87-
}
88-
},
8980
}),
9081
{
9182
title: 'Journal Entry',

exercises/04.resource-tools/01.problem.embedded/src/resources.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export async function initializeResources(agent: EpicMeMCP) {
6868
agent.server.registerResource(
6969
'entry',
7070
new ResourceTemplate('epicme://entries/{id}', {
71+
list: undefined,
7172
complete: {
7273
async id(value) {
7374
const entries = await agent.db.getEntries()
@@ -76,16 +77,6 @@ export async function initializeResources(agent: EpicMeMCP) {
7677
.filter((id) => id.includes(value))
7778
},
7879
},
79-
list: async () => {
80-
const entries = await agent.db.getEntries()
81-
return {
82-
resources: entries.map((entry) => ({
83-
name: entry.title,
84-
uri: `epicme://entries/${entry.id}`,
85-
mimeType: 'application/json',
86-
})),
87-
}
88-
},
8980
}),
9081
{
9182
title: 'Journal Entry',

exercises/04.resource-tools/01.solution.embedded/src/resources.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export async function initializeResources(agent: EpicMeMCP) {
6868
agent.server.registerResource(
6969
'entry',
7070
new ResourceTemplate('epicme://entries/{id}', {
71+
list: undefined,
7172
complete: {
7273
async id(value) {
7374
const entries = await agent.db.getEntries()
@@ -76,16 +77,6 @@ export async function initializeResources(agent: EpicMeMCP) {
7677
.filter((id) => id.includes(value))
7778
},
7879
},
79-
list: async () => {
80-
const entries = await agent.db.getEntries()
81-
return {
82-
resources: entries.map((entry) => ({
83-
name: entry.title,
84-
uri: `epicme://entries/${entry.id}`,
85-
mimeType: 'application/json',
86-
})),
87-
}
88-
},
8980
}),
9081
{
9182
title: 'Journal Entry',

exercises/04.resource-tools/02.problem.linked/src/resources.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export async function initializeResources(agent: EpicMeMCP) {
6868
agent.server.registerResource(
6969
'entry',
7070
new ResourceTemplate('epicme://entries/{id}', {
71+
list: undefined,
7172
complete: {
7273
async id(value) {
7374
const entries = await agent.db.getEntries()
@@ -76,16 +77,6 @@ export async function initializeResources(agent: EpicMeMCP) {
7677
.filter((id) => id.includes(value))
7778
},
7879
},
79-
list: async () => {
80-
const entries = await agent.db.getEntries()
81-
return {
82-
resources: entries.map((entry) => ({
83-
name: entry.title,
84-
uri: `epicme://entries/${entry.id}`,
85-
mimeType: 'application/json',
86-
})),
87-
}
88-
},
8980
}),
9081
{
9182
title: 'Journal Entry',

exercises/04.resource-tools/02.solution.linked/src/resources.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export async function initializeResources(agent: EpicMeMCP) {
6868
agent.server.registerResource(
6969
'entry',
7070
new ResourceTemplate('epicme://entries/{id}', {
71+
list: undefined,
7172
complete: {
7273
async id(value) {
7374
const entries = await agent.db.getEntries()
@@ -76,16 +77,6 @@ export async function initializeResources(agent: EpicMeMCP) {
7677
.filter((id) => id.includes(value))
7778
},
7879
},
79-
list: async () => {
80-
const entries = await agent.db.getEntries()
81-
return {
82-
resources: entries.map((entry) => ({
83-
name: entry.title,
84-
uri: `epicme://entries/${entry.id}`,
85-
mimeType: 'application/json',
86-
})),
87-
}
88-
},
8980
}),
9081
{
9182
title: 'Journal Entry',

exercises/05.prompts/01.problem.prompts/src/resources.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export async function initializeResources(agent: EpicMeMCP) {
6868
agent.server.registerResource(
6969
'entry',
7070
new ResourceTemplate('epicme://entries/{id}', {
71+
list: undefined,
7172
complete: {
7273
async id(value) {
7374
const entries = await agent.db.getEntries()
@@ -76,16 +77,6 @@ export async function initializeResources(agent: EpicMeMCP) {
7677
.filter((id) => id.includes(value))
7778
},
7879
},
79-
list: async () => {
80-
const entries = await agent.db.getEntries()
81-
return {
82-
resources: entries.map((entry) => ({
83-
name: entry.title,
84-
uri: `epicme://entries/${entry.id}`,
85-
mimeType: 'application/json',
86-
})),
87-
}
88-
},
8980
}),
9081
{
9182
title: 'Journal Entry',

0 commit comments

Comments
 (0)