Skip to content

Commit 64e95f7

Browse files
committed
fix: downgrade @modelcontextprotocol/inspector to version 0.16.2 and update logging level handling in EpicMeMCP
1 parent 4b8b11e commit 64e95f7

File tree

10 files changed

+78
-33
lines changed

10 files changed

+78
-33
lines changed

exercises/01.start/01.solution/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"@epic-web/config": "^1.21.3",
1919
"@epic-web/mcp-dev": "*",
2020
"@faker-js/faker": "^9.9.0",
21-
"@modelcontextprotocol/inspector": "^0.16.3",
21+
"@modelcontextprotocol/inspector": "0.16.2",
2222
"@types/node": "^24.2.1",
2323
"tsx": "^4.20.3",
2424
"typescript": "^5.9.2",

exercises/01.start/01.solution/src/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { type DBClient } from '@epic-web/epicme-db-client'
22
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
33
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
4+
import { SetLevelRequestSchema } from '@modelcontextprotocol/sdk/types.js'
45
import { getClient } from './client.ts'
56
import { initializePrompts } from './prompts.ts'
67
import { initializeResources } from './resources.ts'
78
import { initializeTools } from './tools.ts'
89

910
export class EpicMeMCP {
1011
db!: DBClient
12+
state = { loggingLevel: 'info' }
1113
server = new McpServer(
1214
{
1315
name: 'epicme',
@@ -34,6 +36,13 @@ You can also help users add tags to their entries and get all tags for an entry.
3436

3537
async init() {
3638
this.db = getClient()
39+
this.server.server.setRequestHandler(
40+
SetLevelRequestSchema,
41+
async (request) => {
42+
this.state.loggingLevel = request.params.level
43+
return {}
44+
},
45+
)
3746
await initializeTools(this)
3847
await initializeResources(this)
3948
await initializePrompts(this)

exercises/01.start/01.solution/src/sampling.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,17 @@ If you have some suggestions, respond with an array of tag objects. Existing tag
8585
.map((id) => allTags.find((t) => t.id === id))
8686
.filter(Boolean)
8787

88-
void agent.server.server.sendLoggingMessage({
89-
level: 'info',
90-
logger: 'tag-generator',
91-
data: {
92-
message: 'Added tags to entry',
93-
addedTags,
94-
entry: updatedEntry,
95-
},
96-
})
88+
if (['debug', 'info'].includes(agent.state.loggingLevel)) {
89+
void agent.server.server.sendLoggingMessage({
90+
level: 'info',
91+
logger: 'tag-generator',
92+
data: {
93+
message: 'Added tags to entry',
94+
addedTags,
95+
entry: updatedEntry,
96+
},
97+
})
98+
}
9799
}
98100

99101
const existingTagSchema = z.object({ id: z.number() })

exercises/02.start/01.solution/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"devDependencies": {
2222
"@epic-web/config": "^1.21.3",
2323
"@faker-js/faker": "^9.9.0",
24-
"@modelcontextprotocol/inspector": "^0.16.3",
24+
"@modelcontextprotocol/inspector": "0.16.2",
2525
"@types/node": "^24.2.1",
2626
"cross-env": "^10.0.0",
2727
"eslint": "^9.33.0",

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
import { type DBClient } from '@epic-web/epicme-db-client'
22
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
3+
import {
4+
SetLevelRequestSchema,
5+
type LoggingLevel,
6+
} from '@modelcontextprotocol/sdk/types.js'
37
import { McpAgent } from 'agents/mcp'
48
import { getClient } from './client.ts'
59
import { initializePrompts } from './prompts.ts'
610
import { initializeResources } from './resources.ts'
711
import { initializeTools } from './tools.ts'
812

9-
export class EpicMeMCP extends McpAgent {
13+
type State = { loggingLevel: LoggingLevel }
14+
export class EpicMeMCP extends McpAgent<Env, State> {
1015
db!: DBClient
16+
initialState: State = { loggingLevel: 'info' }
1117
server = new McpServer(
1218
{
1319
name: 'epicme',
@@ -34,6 +40,13 @@ You can also help users add tags to their entries and get all tags for an entry.
3440

3541
async init() {
3642
this.db = getClient()
43+
this.server.server.setRequestHandler(
44+
SetLevelRequestSchema,
45+
async (request) => {
46+
this.setState({ ...this.state, loggingLevel: request.params.level })
47+
return {}
48+
},
49+
)
3750
await initializeTools(this)
3851
await initializeResources(this)
3952
await initializePrompts(this)

exercises/02.start/01.solution/src/sampling.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,17 @@ If you have some suggestions, respond with an array of tag objects. Existing tag
8585
.map((id) => allTags.find((t) => t.id === id))
8686
.filter(Boolean)
8787

88-
void agent.server.server.sendLoggingMessage({
89-
level: 'info',
90-
logger: 'tag-generator',
91-
data: {
92-
message: 'Added tags to entry',
93-
addedTags,
94-
entry: updatedEntry,
95-
},
96-
})
88+
if (['debug', 'info'].includes(agent.state.loggingLevel)) {
89+
void agent.server.server.sendLoggingMessage({
90+
level: 'info',
91+
logger: 'tag-generator',
92+
data: {
93+
message: 'Added tags to entry',
94+
addedTags,
95+
entry: updatedEntry,
96+
},
97+
})
98+
}
9799
}
98100

99101
const existingTagSchema = z.object({ id: z.number() })

exercises/99.finished/99.solution/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"devDependencies": {
2222
"@epic-web/config": "^1.21.3",
2323
"@faker-js/faker": "^9.9.0",
24-
"@modelcontextprotocol/inspector": "^0.16.3",
24+
"@modelcontextprotocol/inspector": "0.16.2",
2525
"@types/node": "^24.2.1",
2626
"cross-env": "^10.0.0",
2727
"eslint": "^9.33.0",

exercises/99.finished/99.solution/src/index.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { type DBClient } from '@epic-web/epicme-db-client'
22
import { invariant } from '@epic-web/invariant'
33
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
4+
import {
5+
SetLevelRequestSchema,
6+
type LoggingLevel,
7+
} from '@modelcontextprotocol/sdk/types.js'
48
import { McpAgent } from 'agents/mcp'
59
import {
610
type AuthInfo,
@@ -15,8 +19,12 @@ import { initializeResources } from './resources.ts'
1519
import { initializeTools } from './tools.ts'
1620
import { withCors } from './utils.ts'
1721

18-
export class EpicMeMCP extends McpAgent<Env, {}, { authInfo: AuthInfo }> {
22+
type State = { loggingLevel: LoggingLevel }
23+
type Props = { authInfo: AuthInfo }
24+
25+
export class EpicMeMCP extends McpAgent<Env, State, Props> {
1926
db!: DBClient
27+
initialState: State = { loggingLevel: 'info' }
2028
server = new McpServer(
2129
{
2230
name: 'epicme',
@@ -45,6 +53,15 @@ You can also help users add tags to their entries and get all tags for an entry.
4553
const authInfo = this.props.authInfo
4654
invariant(authInfo, 'Auth info not found')
4755
this.db = getClient(authInfo.token)
56+
57+
this.server.server.setRequestHandler(
58+
SetLevelRequestSchema,
59+
async (request) => {
60+
this.setState({ ...this.state, loggingLevel: request.params.level })
61+
return {}
62+
},
63+
)
64+
4865
await initializeTools(this)
4966
await initializeResources(this)
5067
await initializePrompts(this)

exercises/99.finished/99.solution/src/sampling.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,17 @@ If you have some suggestions, respond with an array of tag objects. Existing tag
8585
.map((id) => allTags.find((t) => t.id === id))
8686
.filter(Boolean)
8787

88-
void agent.server.server.sendLoggingMessage({
89-
level: 'info',
90-
logger: 'tag-generator',
91-
data: {
92-
message: 'Added tags to entry',
93-
addedTags,
94-
entry: updatedEntry,
95-
},
96-
})
88+
if (['debug', 'info'].includes(agent.state.loggingLevel)) {
89+
void agent.server.server.sendLoggingMessage({
90+
level: 'info',
91+
logger: 'tag-generator',
92+
data: {
93+
message: 'Added tags to entry',
94+
addedTags,
95+
entry: updatedEntry,
96+
},
97+
})
98+
}
9799
}
98100

99101
const existingTagSchema = z.object({ id: z.number() })

exercises/99.finished/99.solution/src/tools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export async function initializeTools(agent: EpicMeMCP) {
3434
const user = await agent.requireUser()
3535
return {
3636
structuredContent: { user },
37-
content: [createText(JSON.stringify({ user }, null, 2))],
37+
content: [createText(user)],
3838
}
3939
},
4040
)

0 commit comments

Comments
 (0)