Skip to content

Commit a7d681a

Browse files
committed
log level is handled
1 parent 29b9b66 commit a7d681a

File tree

16 files changed

+3
-123
lines changed

16 files changed

+3
-123
lines changed

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,8 @@ void agent.server.server.sendLoggingMessage({
8585
Check the specification for more info:
8686
https://modelcontextprotocol.io/specification/2025-06-18/server/utilities/logging#log-message-notifications
8787

88-
To be able to send a logging message, you need to first advertise that we support logging and add support for the `SetLevelRequestSchema` request. You'll do this in <InlineFile file="./src/index.ts" />. As a general reminder, here's how you add request handlers:
89-
90-
```ts
91-
// this.server.server to access the underlying server instance
92-
this.server.server.setRequestHandler(
93-
RequestSchema, // this is the request schema you're adding support for
94-
async (request) => {
95-
// do something with the request
96-
return // return the appropriate response
97-
},
98-
)
99-
```
88+
The SDK handles keeping track of the logging level and only sending messages if
89+
they are within the set logging level.
10090

10191
---
10292

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
22
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
3-
// 💰 you'll need this:
4-
// import { SetLevelRequestSchema } from '@modelcontextprotocol/sdk/types.js'
53
import { DB } from './db/index.ts'
64
import { initializePrompts } from './prompts.ts'
75
import { initializeResources } from './resources.ts'
@@ -38,9 +36,6 @@ You can also help users add tags to their entries and get all tags for an entry.
3836
this.db = DB.getInstance(path)
3937
}
4038
async init() {
41-
// 🐨 add logging handler with this.server.server.setRequestHandler and the SetLevelRequestSchema
42-
// 🐨 the callback should set the loggingLevel in the state from request.params.level and return an empty object
43-
// 🦉 this is annoying, and hopefully can be managed by the SDK in the future: https://github.com/modelcontextprotocol/typescript-sdk/issues/871
4439
await initializeTools(this)
4540
await initializeResources(this)
4641
await initializePrompts(this)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@ export async function suggestTagsSampling(agent: EpicMeMCP, entryId: number) {
1313
// 🐨 logging message to send the model response to the client
1414
// 📜 https://modelcontextprotocol.io/specification/2025-06-18/server/utilities/logging#log-message-notifications
1515
// 💰 agent.server.server.sendLoggingMessage (with level of 'info', logger of 'sampling', and data with the model response)
16-
// 💰 only send the logging message if the agent.state.loggingLevel is 'debug' or 'info'
17-
// 🦉 This is kind of annoying, and hopefully can be managed by the SDK in the future: https://github.com/modelcontextprotocol/typescript-sdk/issues/871
16+
// 🦉 The SDK will make sure to only send messages if the logging level is 'debug' or 'info'
1817
}

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
22
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
3-
import { SetLevelRequestSchema } from '@modelcontextprotocol/sdk/types.js'
43
import { DB } from './db/index.ts'
54
import { initializePrompts } from './prompts.ts'
65
import { initializeResources } from './resources.ts'
@@ -37,13 +36,6 @@ You can also help users add tags to their entries and get all tags for an entry.
3736
this.db = DB.getInstance(path)
3837
}
3938
async init() {
40-
this.server.server.setRequestHandler(
41-
SetLevelRequestSchema,
42-
async (request) => {
43-
this.state.loggingLevel = request.params.level
44-
return {}
45-
},
46-
)
4739
await initializeTools(this)
4840
await initializeResources(this)
4941
await initializePrompts(this)

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
22
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
3-
import { SetLevelRequestSchema } from '@modelcontextprotocol/sdk/types.js'
43
import { DB } from './db/index.ts'
54
import { initializePrompts } from './prompts.ts'
65
import { initializeResources } from './resources.ts'
@@ -37,13 +36,6 @@ You can also help users add tags to their entries and get all tags for an entry.
3736
this.db = DB.getInstance(path)
3837
}
3938
async init() {
40-
this.server.server.setRequestHandler(
41-
SetLevelRequestSchema,
42-
async (request) => {
43-
this.state.loggingLevel = request.params.level
44-
return {}
45-
},
46-
)
4739
await initializeTools(this)
4840
await initializeResources(this)
4941
await initializePrompts(this)

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
22
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
3-
import { SetLevelRequestSchema } from '@modelcontextprotocol/sdk/types.js'
43
import { DB } from './db/index.ts'
54
import { initializePrompts } from './prompts.ts'
65
import { initializeResources } from './resources.ts'
@@ -37,13 +36,6 @@ You can also help users add tags to their entries and get all tags for an entry.
3736
this.db = DB.getInstance(path)
3837
}
3938
async init() {
40-
this.server.server.setRequestHandler(
41-
SetLevelRequestSchema,
42-
async (request) => {
43-
this.state.loggingLevel = request.params.level
44-
return {}
45-
},
46-
)
4739
await initializeTools(this)
4840
await initializeResources(this)
4941
await initializePrompts(this)

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
22
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
3-
import { SetLevelRequestSchema } from '@modelcontextprotocol/sdk/types.js'
43
import { DB } from './db/index.ts'
54
import { initializePrompts } from './prompts.ts'
65
import { initializeResources } from './resources.ts'
@@ -37,13 +36,6 @@ You can also help users add tags to their entries and get all tags for an entry.
3736
this.db = DB.getInstance(path)
3837
}
3938
async init() {
40-
this.server.server.setRequestHandler(
41-
SetLevelRequestSchema,
42-
async (request) => {
43-
this.state.loggingLevel = request.params.level
44-
return {}
45-
},
46-
)
4739
await initializeTools(this)
4840
await initializeResources(this)
4941
await initializePrompts(this)

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
22
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
3-
import { SetLevelRequestSchema } from '@modelcontextprotocol/sdk/types.js'
43
import { DB } from './db/index.ts'
54
import { initializePrompts } from './prompts.ts'
65
import { initializeResources } from './resources.ts'
@@ -37,13 +36,6 @@ You can also help users add tags to their entries and get all tags for an entry.
3736
this.db = DB.getInstance(path)
3837
}
3938
async init() {
40-
this.server.server.setRequestHandler(
41-
SetLevelRequestSchema,
42-
async (request) => {
43-
this.state.loggingLevel = request.params.level
44-
return {}
45-
},
46-
)
4739
await initializeTools(this)
4840
await initializeResources(this)
4941
await initializePrompts(this)

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
22
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
3-
import { SetLevelRequestSchema } from '@modelcontextprotocol/sdk/types.js'
43
import { DB } from './db/index.ts'
54
import { initializePrompts } from './prompts.ts'
65
import { initializeResources } from './resources.ts'
@@ -37,13 +36,6 @@ You can also help users add tags to their entries and get all tags for an entry.
3736
this.db = DB.getInstance(path)
3837
}
3938
async init() {
40-
this.server.server.setRequestHandler(
41-
SetLevelRequestSchema,
42-
async (request) => {
43-
this.state.loggingLevel = request.params.level
44-
return {}
45-
},
46-
)
4739
await initializeTools(this)
4840
await initializeResources(this)
4941
await initializePrompts(this)

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
22
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
3-
import { SetLevelRequestSchema } from '@modelcontextprotocol/sdk/types.js'
43
import { DB } from './db/index.ts'
54
import { initializePrompts } from './prompts.ts'
65
import { initializeResources } from './resources.ts'
@@ -37,13 +36,6 @@ You can also help users add tags to their entries and get all tags for an entry.
3736
this.db = DB.getInstance(path)
3837
}
3938
async init() {
40-
this.server.server.setRequestHandler(
41-
SetLevelRequestSchema,
42-
async (request) => {
43-
this.state.loggingLevel = request.params.level
44-
return {}
45-
},
46-
)
4739
await initializeTools(this)
4840
await initializeResources(this)
4941
await initializePrompts(this)

0 commit comments

Comments
 (0)