Skip to content

Commit 4e2f8eb

Browse files
committed
fix tests and remove mimeType references
1 parent 261e5e2 commit 4e2f8eb

File tree

10 files changed

+38
-85
lines changed

10 files changed

+38
-85
lines changed

exercises/03.sampling/01.solution.simple/src/index.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,7 @@ test('Simple Sampling', async () => {
229229
await using setup = await setupClient({ capabilities: { sampling: {} } })
230230
const { client } = setup
231231
const messageResultDeferred = await deferred<CreateMessageResult>()
232-
const messageRequestDeferred =
233-
await deferred<CreateMessageRequest>()
232+
const messageRequestDeferred = await deferred<CreateMessageRequest>()
234233

235234
client.setRequestHandler(CreateMessageRequestSchema, (r) => {
236235
messageRequestDeferred.resolve(r)
@@ -276,7 +275,6 @@ test('Simple Sampling', async () => {
276275
content: expect.objectContaining({
277276
type: 'text',
278277
text: expect.any(String),
279-
mimeType: expect.any(String),
280278
}),
281279
}),
282280
]),

exercises/03.sampling/01.solution.simple/src/sampling.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ We'll put more in here later...
1818
role: 'user',
1919
content: {
2020
type: 'text',
21-
mimeType: 'text/plain',
2221
text: `
2322
You just created a new journal entry with the id ${entryId}.
2423

exercises/03.sampling/02.problem.advanced/README.mdx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ for a new journal entry.
1111

1212
- Update your sampling request to provide the LLM with structured information:
1313
the new journal entry, its current tags, and all existing tags in the system.
14-
- Change the user message to send this data as JSON (`application/json`), not
15-
plain text.
14+
- Change the user message to send this data as JSON (the `text` field should
15+
contain a JSON string), not plain text.
16+
🦉 Note: At the time of the video recordings, a `mimeType` of
17+
`application/json` was allowed for text content, but that requirement has
18+
since been removed from the MCP specification. The SDK will strip `mimeType`
19+
from text content, so you should not include it.
1620
- Write a clear, detailed system prompt that instructs the LLM to make a list of
1721
suggested tags that are relevant to the entry and not already applied. Make
1822
certain it's instructed on the format of the response.

exercises/03.sampling/02.problem.advanced/src/sampling.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ We'll put more in here later...
4242
role: 'user',
4343
content: {
4444
type: 'text',
45-
// 🐨 change this to application/json
46-
mimeType: 'text/plain',
45+
// 🦉 NOTE: at the time of the video recording, a mimeType of text/plain was required. That requirement has since been removed!
46+
4747
// 🐨 Stringify JSON with the entry, currentTags, and existingTags
4848
text: `
4949
You just created a new journal entry with the id ${entryId}.

exercises/03.sampling/02.solution.advanced/src/index.test.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,7 @@ test('Advanced Sampling', async () => {
229229
await using setup = await setupClient({ capabilities: { sampling: {} } })
230230
const { client } = setup
231231
const messageResultDeferred = await deferred<CreateMessageResult>()
232-
const messageRequestDeferred =
233-
await deferred<CreateMessageRequest>()
232+
const messageRequestDeferred = await deferred<CreateMessageRequest>()
234233

235234
client.setRequestHandler(CreateMessageRequestSchema, (r) => {
236235
messageRequestDeferred.resolve(r)
@@ -280,7 +279,6 @@ test('Advanced Sampling', async () => {
280279
content: expect.objectContaining({
281280
type: 'text',
282281
text: expect.stringMatching(/entry/i),
283-
mimeType: 'application/json',
284282
}),
285283
}),
286284
]),
@@ -309,12 +307,10 @@ test('Advanced Sampling', async () => {
309307
params && 'messages' in params && Array.isArray(params.messages),
310308
'🚨 messages array is required',
311309
)
312-
const userMessage = params.messages.find((m) => m.role === 'user') as unknown as { content: { mimeType: string, text: string } }
310+
const userMessage = params.messages.find(
311+
(m) => m.role === 'user',
312+
) as unknown as { content: { text: string } }
313313
invariant(userMessage, '🚨 User message is required')
314-
invariant(
315-
userMessage.content.mimeType === 'application/json',
316-
'🚨 Content should be JSON for structured data',
317-
)
318314

319315
// 🚨 Validate the JSON structure contains required fields
320316
invariant(
@@ -350,7 +346,7 @@ test('Advanced Sampling', async () => {
350346
'🚨 2. Create a meaningful systemPrompt that includes examples of the expected output format (array of tag objects, with examples for existing and new tags).',
351347
)
352348
console.error(
353-
'🚨 3. Structure the user message as JSON with mimeType: "application/json".',
349+
'🚨 3. Structure the user message as JSON (the text field should contain valid JSON).',
354350
)
355351
console.error(
356352
'🚨 4. Include both entry data AND existingTags context in the JSON (e.g., { entry: {...}, existingTags: [...] }).',
@@ -368,10 +364,6 @@ test('Advanced Sampling', async () => {
368364
const params = request.params
369365
if (params) {
370366
console.error(`🚨 Current maxTokens: ${params.maxTokens} (should be >50)`)
371-
console.error(
372-
// @ts-ignore 🤷‍♂️ pretty sure this is correct
373-
`🚨 Current mimeType: ${params.messages?.[0]?.content?.mimeType} (should be "application/json")`,
374-
)
375367
console.error(
376368
`🚨 SystemPrompt contains "example": ${typeof params.systemPrompt === 'string' && params.systemPrompt.toLowerCase().includes('example')}`,
377369
)

exercises/04.long-running-tasks/01.solution.progress/src/index.test.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ test('Advanced Sampling', async () => {
230230
await using setup = await setupClient({ capabilities: { sampling: {} } })
231231
const { client } = setup
232232
const messageResultDeferred = await deferred<CreateMessageResult>()
233-
const messageRequestDeferred =
234-
await deferred<CreateMessageRequest>()
233+
const messageRequestDeferred = await deferred<CreateMessageRequest>()
235234

236235
client.setRequestHandler(CreateMessageRequestSchema, (r) => {
237236
messageRequestDeferred.resolve(r)
@@ -281,7 +280,6 @@ test('Advanced Sampling', async () => {
281280
content: expect.objectContaining({
282281
type: 'text',
283282
text: expect.stringMatching(/entry/i),
284-
mimeType: 'application/json',
285283
}),
286284
}),
287285
]),
@@ -310,12 +308,10 @@ test('Advanced Sampling', async () => {
310308
params && 'messages' in params && Array.isArray(params.messages),
311309
'🚨 messages array is required',
312310
)
313-
const userMessage = params.messages.find((m) => m.role === 'user') as unknown as { content: { mimeType: string, text: string } }
311+
const userMessage = params.messages.find(
312+
(m) => m.role === 'user',
313+
) as unknown as { content: { text: string } }
314314
invariant(userMessage, '🚨 User message is required')
315-
invariant(
316-
userMessage.content.mimeType === 'application/json',
317-
'🚨 Content should be JSON for structured data',
318-
)
319315

320316
// 🚨 Validate the JSON structure contains required fields
321317
invariant(
@@ -351,7 +347,7 @@ test('Advanced Sampling', async () => {
351347
'🚨 2. Create a meaningful systemPrompt that includes examples of the expected output format (array of tag objects, with examples for existing and new tags).',
352348
)
353349
console.error(
354-
'🚨 3. Structure the user message as JSON with mimeType: "application/json".',
350+
'🚨 3. Structure the user message as JSON (the text field should contain valid JSON).',
355351
)
356352
console.error(
357353
'🚨 4. Include both entry data AND existingTags context in the JSON (e.g., { entry: {...}, existingTags: [...] }).',
@@ -369,10 +365,6 @@ test('Advanced Sampling', async () => {
369365
const params = request.params
370366
if (params) {
371367
console.error(`🚨 Current maxTokens: ${params.maxTokens} (should be >50)`)
372-
console.error(
373-
// @ts-ignore 🤷‍♂️ pretty sure this is correct
374-
`🚨 Current mimeType: ${params.messages?.[0]?.content?.mimeType} (should be "application/json")`,
375-
)
376368
console.error(
377369
`🚨 SystemPrompt contains "example": ${typeof params.systemPrompt === 'string' && params.systemPrompt.toLowerCase().includes('example')}`,
378370
)

exercises/04.long-running-tasks/02.solution.cancellation/src/index.test.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ test('Advanced Sampling', async () => {
230230
await using setup = await setupClient({ capabilities: { sampling: {} } })
231231
const { client } = setup
232232
const messageResultDeferred = await deferred<CreateMessageResult>()
233-
const messageRequestDeferred =
234-
await deferred<CreateMessageRequest>()
233+
const messageRequestDeferred = await deferred<CreateMessageRequest>()
235234

236235
client.setRequestHandler(CreateMessageRequestSchema, (r) => {
237236
messageRequestDeferred.resolve(r)
@@ -281,7 +280,6 @@ test('Advanced Sampling', async () => {
281280
content: expect.objectContaining({
282281
type: 'text',
283282
text: expect.stringMatching(/entry/i),
284-
mimeType: 'application/json',
285283
}),
286284
}),
287285
]),
@@ -310,12 +308,10 @@ test('Advanced Sampling', async () => {
310308
params && 'messages' in params && Array.isArray(params.messages),
311309
'🚨 messages array is required',
312310
)
313-
const userMessage = params.messages.find((m) => m.role === 'user') as unknown as { content: { mimeType: string, text: string } }
311+
const userMessage = params.messages.find(
312+
(m) => m.role === 'user',
313+
) as unknown as { content: { text: string } }
314314
invariant(userMessage, '🚨 User message is required')
315-
invariant(
316-
userMessage.content.mimeType === 'application/json',
317-
'🚨 Content should be JSON for structured data',
318-
)
319315

320316
// 🚨 Validate the JSON structure contains required fields
321317
invariant(
@@ -351,7 +347,7 @@ test('Advanced Sampling', async () => {
351347
'🚨 2. Create a meaningful systemPrompt that includes examples of the expected output format (array of tag objects, with examples for existing and new tags).',
352348
)
353349
console.error(
354-
'🚨 3. Structure the user message as JSON with mimeType: "application/json".',
350+
'🚨 3. Structure the user message as JSON (the text field should contain valid JSON).',
355351
)
356352
console.error(
357353
'🚨 4. Include both entry data AND existingTags context in the JSON (e.g., { entry: {...}, existingTags: [...] }).',
@@ -369,10 +365,6 @@ test('Advanced Sampling', async () => {
369365
const params = request.params
370366
if (params) {
371367
console.error(`🚨 Current maxTokens: ${params.maxTokens} (should be >50)`)
372-
console.error(
373-
// @ts-ignore 🤷‍♂️ pretty sure this is correct
374-
`🚨 Current mimeType: ${params.messages?.[0]?.content?.mimeType} (should be "application/json")`,
375-
)
376368
console.error(
377369
`🚨 SystemPrompt contains "example": ${typeof params.systemPrompt === 'string' && params.systemPrompt.toLowerCase().includes('example')}`,
378370
)

exercises/05.changes/01.solution.list-changed/src/index.test.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,7 @@ test('Advanced Sampling', async () => {
231231
await using setup = await setupClient({ capabilities: { sampling: {} } })
232232
const { client } = setup
233233
const messageResultDeferred = await deferred<CreateMessageResult>()
234-
const messageRequestDeferred =
235-
await deferred<CreateMessageRequest>()
234+
const messageRequestDeferred = await deferred<CreateMessageRequest>()
236235

237236
client.setRequestHandler(CreateMessageRequestSchema, (r) => {
238237
messageRequestDeferred.resolve(r)
@@ -282,7 +281,6 @@ test('Advanced Sampling', async () => {
282281
content: expect.objectContaining({
283282
type: 'text',
284283
text: expect.stringMatching(/entry/i),
285-
mimeType: 'application/json',
286284
}),
287285
}),
288286
]),
@@ -311,12 +309,10 @@ test('Advanced Sampling', async () => {
311309
params && 'messages' in params && Array.isArray(params.messages),
312310
'🚨 messages array is required',
313311
)
314-
const userMessage = params.messages.find((m) => m.role === 'user') as unknown as { content: { mimeType: string, text: string } }
312+
const userMessage = params.messages.find(
313+
(m) => m.role === 'user',
314+
) as unknown as { content: { text: string } }
315315
invariant(userMessage, '🚨 User message is required')
316-
invariant(
317-
userMessage.content.mimeType === 'application/json',
318-
'🚨 Content should be JSON for structured data',
319-
)
320316

321317
// 🚨 Validate the JSON structure contains required fields
322318
invariant(
@@ -352,7 +348,7 @@ test('Advanced Sampling', async () => {
352348
'🚨 2. Create a meaningful systemPrompt that includes examples of the expected output format (array of tag objects, with examples for existing and new tags).',
353349
)
354350
console.error(
355-
'🚨 3. Structure the user message as JSON with mimeType: "application/json".',
351+
'🚨 3. Structure the user message as JSON (the text field should contain valid JSON).',
356352
)
357353
console.error(
358354
'🚨 4. Include both entry data AND existingTags context in the JSON (e.g., { entry: {...}, existingTags: [...] }).',
@@ -370,10 +366,6 @@ test('Advanced Sampling', async () => {
370366
const params = request.params
371367
if (params) {
372368
console.error(`🚨 Current maxTokens: ${params.maxTokens} (should be >50)`)
373-
console.error(
374-
// @ts-ignore 🤷‍♂️ pretty sure this is correct
375-
`🚨 Current mimeType: ${params.messages?.[0]?.content?.mimeType} (should be "application/json")`,
376-
)
377369
console.error(
378370
`🚨 SystemPrompt contains "example": ${typeof params.systemPrompt === 'string' && params.systemPrompt.toLowerCase().includes('example')}`,
379371
)

exercises/05.changes/02.solution.resources-list-changed/src/index.test.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,7 @@ test('Advanced Sampling', async () => {
233233
await using setup = await setupClient({ capabilities: { sampling: {} } })
234234
const { client } = setup
235235
const messageResultDeferred = await deferred<CreateMessageResult>()
236-
const messageRequestDeferred =
237-
await deferred<CreateMessageRequest>()
236+
const messageRequestDeferred = await deferred<CreateMessageRequest>()
238237

239238
client.setRequestHandler(CreateMessageRequestSchema, (r) => {
240239
messageRequestDeferred.resolve(r)
@@ -284,7 +283,6 @@ test('Advanced Sampling', async () => {
284283
content: expect.objectContaining({
285284
type: 'text',
286285
text: expect.stringMatching(/entry/i),
287-
mimeType: 'application/json',
288286
}),
289287
}),
290288
]),
@@ -313,12 +311,10 @@ test('Advanced Sampling', async () => {
313311
params && 'messages' in params && Array.isArray(params.messages),
314312
'🚨 messages array is required',
315313
)
316-
const userMessage = params.messages.find((m) => m.role === 'user') as unknown as { content: { mimeType: string, text: string } }
314+
const userMessage = params.messages.find(
315+
(m) => m.role === 'user',
316+
) as unknown as { content: { text: string } }
317317
invariant(userMessage, '🚨 User message is required')
318-
invariant(
319-
userMessage.content.mimeType === 'application/json',
320-
'🚨 Content should be JSON for structured data',
321-
)
322318

323319
// 🚨 Validate the JSON structure contains required fields
324320
invariant(
@@ -354,7 +350,7 @@ test('Advanced Sampling', async () => {
354350
'🚨 2. Create a meaningful systemPrompt that includes examples of the expected output format (array of tag objects, with examples for existing and new tags).',
355351
)
356352
console.error(
357-
'🚨 3. Structure the user message as JSON with mimeType: "application/json".',
353+
'🚨 3. Structure the user message as JSON (the text field should contain valid JSON).',
358354
)
359355
console.error(
360356
'🚨 4. Include both entry data AND existingTags context in the JSON (e.g., { entry: {...}, existingTags: [...] }).',
@@ -372,10 +368,6 @@ test('Advanced Sampling', async () => {
372368
const params = request.params
373369
if (params) {
374370
console.error(`🚨 Current maxTokens: ${params.maxTokens} (should be >50)`)
375-
console.error(
376-
// @ts-ignore 🤷‍♂️ pretty sure this is correct
377-
`🚨 Current mimeType: ${params.messages?.[0]?.content?.mimeType} (should be "application/json")`,
378-
)
379371
console.error(
380372
`🚨 SystemPrompt contains "example": ${typeof params.systemPrompt === 'string' && params.systemPrompt.toLowerCase().includes('example')}`,
381373
)

exercises/05.changes/03.solution.subscriptions/src/index.test.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,7 @@ test('Advanced Sampling', async () => {
234234
await using setup = await setupClient({ capabilities: { sampling: {} } })
235235
const { client } = setup
236236
const messageResultDeferred = await deferred<CreateMessageResult>()
237-
const messageRequestDeferred =
238-
await deferred<CreateMessageRequest>()
237+
const messageRequestDeferred = await deferred<CreateMessageRequest>()
239238

240239
client.setRequestHandler(CreateMessageRequestSchema, (r) => {
241240
messageRequestDeferred.resolve(r)
@@ -285,7 +284,6 @@ test('Advanced Sampling', async () => {
285284
content: expect.objectContaining({
286285
type: 'text',
287286
text: expect.stringMatching(/entry/i),
288-
mimeType: 'application/json',
289287
}),
290288
}),
291289
]),
@@ -314,12 +312,10 @@ test('Advanced Sampling', async () => {
314312
params && 'messages' in params && Array.isArray(params.messages),
315313
'🚨 messages array is required',
316314
)
317-
const userMessage = params.messages.find((m) => m.role === 'user') as unknown as { content: { mimeType: string, text: string } }
315+
const userMessage = params.messages.find(
316+
(m) => m.role === 'user',
317+
) as unknown as { content: { text: string } }
318318
invariant(userMessage, '🚨 User message is required')
319-
invariant(
320-
userMessage.content.mimeType === 'application/json',
321-
'🚨 Content should be JSON for structured data',
322-
)
323319

324320
// 🚨 Validate the JSON structure contains required fields
325321
invariant(
@@ -373,10 +369,6 @@ test('Advanced Sampling', async () => {
373369
const params = request.params
374370
if (params) {
375371
console.error(`🚨 Current maxTokens: ${params.maxTokens} (should be >50)`)
376-
console.error(
377-
// @ts-ignore 🤷‍♂️ pretty sure this is correct
378-
`🚨 Current mimeType: ${params.messages?.[0]?.content?.mimeType} (should be "application/json")`,
379-
)
380372
console.error(
381373
`🚨 SystemPrompt contains "example": ${typeof params.systemPrompt === 'string' && params.systemPrompt.toLowerCase().includes('example')}`,
382374
)

0 commit comments

Comments
 (0)