Skip to content

Commit f84d67e

Browse files
committed
refactor: replace console logging with notification messages in sampling exercises
1 parent d542f9a commit f84d67e

File tree

36 files changed

+1360
-593
lines changed

36 files changed

+1360
-593
lines changed

exercises/01.advanced-tools/01.problem.annotations/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export class EpicMeMCP {
1818
tools: {},
1919
resources: {},
2020
completions: {},
21+
logging: {},
2122
prompts: {},
2223
},
2324
instructions: `

exercises/01.advanced-tools/01.solution.annotations/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export class EpicMeMCP {
1818
tools: {},
1919
resources: {},
2020
completions: {},
21+
logging: {},
2122
prompts: {},
2223
},
2324
instructions: `

exercises/01.advanced-tools/02.problem.structured/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export class EpicMeMCP {
1818
tools: {},
1919
resources: {},
2020
completions: {},
21+
logging: {},
2122
prompts: {},
2223
},
2324
instructions: `

exercises/01.advanced-tools/02.solution.structured/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export class EpicMeMCP {
1818
tools: {},
1919
resources: {},
2020
completions: {},
21+
logging: {},
2122
prompts: {},
2223
},
2324
instructions: `

exercises/02.elicitation/01.problem/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export class EpicMeMCP {
1818
tools: {},
1919
resources: {},
2020
completions: {},
21+
logging: {},
2122
prompts: {},
2223
},
2324
instructions: `

exercises/02.elicitation/01.solution/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export class EpicMeMCP {
1818
tools: {},
1919
resources: {},
2020
completions: {},
21+
logging: {},
2122
prompts: {},
2223
},
2324
instructions: `

exercises/03.sampling/01.problem.simple/README.mdx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ prompt for the LLM in the next step.
2424
message that references the new journal entry's ID (we'll enhance this next).
2525
- Set a reasonable `maxTokens` value for the response.
2626
- Parse the model's response using a provided Zod schema.
27-
- Log the result to the console so you can inspect the model's output.
27+
- Send a notification with the result so you can see the model's output.
2828

2929
And don't forget to call it when the user creates a new journal entry!
3030

@@ -68,6 +68,23 @@ The `maxTokens` option references the max tokens the model should return.
6868
window size of the model you're user is using.
6969
</callout-warning>
7070

71+
Here's an example of how to send a notification:
72+
73+
```ts
74+
// void is to communicate we don't care about the return value. Fire and forget.
75+
void agent.server.server.sendLoggingMessage({
76+
level: 'info', // "error" | "debug" | "info" | "notice" | "warning" | "critical" | "alert" | "emergency"
77+
// data can be any JSON-serializable value
78+
data: {
79+
a: 1,
80+
otherStuff: '...',
81+
},
82+
})
83+
```
84+
85+
Check the specification for more info:
86+
https://modelcontextprotocol.io/specification/2025-06-18/server/utilities/logging#log-message-notifications
87+
7188
This step will help you get comfortable with the basic request/response flow for
7289
sampling in MCP, and set the stage for more advanced prompt engineering in the
7390
next step.

exercises/03.sampling/01.problem.simple/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export class EpicMeMCP {
1818
tools: {},
1919
resources: {},
2020
completions: {},
21+
// 🐨 add the `logging` capability to the `capabilities` object
2122
prompts: {},
2223
},
2324
instructions: `

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ export async function suggestTagsSampling(agent: EpicMeMCP, entryId: number) {
1010
// 🐨 Add a user message with the content "You just created a new journal entry with the id ${entryId}. Please respond with a proper commendation for yourself."
1111
// 🐨 Set the maxTokens what you think is reasonable for the request
1212
//
13-
// 🐨 add a console.error to print the result.content.text (this will show up in the inspector)
13+
// 🐨 logging message to send the model response to the client
14+
// 📜 https://modelcontextprotocol.io/specification/2025-06-18/server/utilities/logging#log-message-notifications
15+
// 💰 agent.server.server.sendLoggingMessage (with level of 'info', logger of 'sampling', and data with the model response)
1416
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export class EpicMeMCP {
1818
tools: {},
1919
resources: {},
2020
completions: {},
21+
logging: {},
2122
prompts: {},
2223
},
2324
instructions: `

0 commit comments

Comments
 (0)