Skip to content

Commit 31b6a5e

Browse files
committed
improve tools
1 parent f91d08d commit 31b6a5e

File tree

3 files changed

+153
-140
lines changed

3 files changed

+153
-140
lines changed

exercises/99.final/01.solution/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"devDependencies": {
1515
"@epic-web/config": "^1.19.0",
16-
"@modelcontextprotocol/inspector": "^0.10.0",
16+
"@modelcontextprotocol/inspector": "^0.10.2",
1717
"@types/node": "^22.14.1",
1818
"eslint": "^9.24.0",
1919
"prettier": "^3.5.3",

exercises/99.final/01.solution/src/tools.ts

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function initializeTools(server: McpServer, db: DB) {
5757
content: [
5858
{
5959
type: 'text',
60-
text: `Entry "${createdEntry.title}" created successfully with ID ${createdEntry.id}`,
60+
text: `Entry "${createdEntry.title}" created successfully with ID "${createdEntry.id}"`,
6161
},
6262
],
6363
}
@@ -85,7 +85,7 @@ export function initializeTools(server: McpServer, db: DB) {
8585
async ({ id }) => {
8686
try {
8787
const entry = await db.getEntry(id)
88-
invariant(entry, `Entry ${id} not found`)
88+
invariant(entry, `Entry with ID "${id}" not found`)
8989
return {
9090
content: [{ type: 'text', text: JSON.stringify(entry, null, 2) }],
9191
}
@@ -130,25 +130,18 @@ export function initializeTools(server: McpServer, db: DB) {
130130
.nullable()
131131
.optional()
132132
.describe('The title of the entry')
133-
.transform((value) => {
134-
console.log('title', { value })
135-
return value ?? undefined
136-
}),
133+
.transform((value) => value ?? undefined),
137134
content: z
138135
.string()
139136
.nullable()
140137
.optional()
141138
.describe('The content of the entry')
142-
.transform((value) => {
143-
console.log('content', { value })
144-
return value ?? undefined
145-
}),
139+
.transform((value) => value ?? undefined),
146140
},
147141
async ({ id, ...updates }) => {
148-
console.log({ updates })
149142
try {
150143
const existingEntry = await db.getEntry(id)
151-
invariant(existingEntry, `Entry ${id} not found`)
144+
invariant(existingEntry, `Entry with ID "${id}" not found`)
152145
const updatedEntry = await db.updateEntry(id, updates)
153146
return {
154147
content: [
@@ -182,7 +175,7 @@ export function initializeTools(server: McpServer, db: DB) {
182175
async ({ id }) => {
183176
try {
184177
const existingEntry = await db.getEntry(id)
185-
invariant(existingEntry, `Entry ${id} not found`)
178+
invariant(existingEntry, `Entry with ID "${id}" not found`)
186179
await db.deleteEntry(id)
187180
return {
188181
content: [
@@ -219,7 +212,7 @@ export function initializeTools(server: McpServer, db: DB) {
219212
content: [
220213
{
221214
type: 'text',
222-
text: `Tag "${createdTag.name}" created successfully with ID ${createdTag.id}`,
215+
text: `Tag "${createdTag.name}" created successfully with ID "${createdTag.id}"`,
223216
},
224217
],
225218
}
@@ -247,7 +240,7 @@ export function initializeTools(server: McpServer, db: DB) {
247240
async ({ id }) => {
248241
try {
249242
const tag = await db.getTag(id)
250-
invariant(tag, `Tag ${id} not found`)
243+
invariant(tag, `Tag ID "${id}" not found`)
251244
return {
252245
content: [{ type: 'text', text: JSON.stringify(tag, null, 2) }],
253246
}
@@ -296,7 +289,7 @@ export function initializeTools(server: McpServer, db: DB) {
296289
async ({ id, ...updates }) => {
297290
try {
298291
const existingTag = await db.getTag(id)
299-
invariant(existingTag, `Tag ${id} not found`)
292+
invariant(existingTag, `Tag with ID "${id}" not found`)
300293
const updatedTag = await db.updateTag(id, updates)
301294
return {
302295
content: [
@@ -330,7 +323,7 @@ export function initializeTools(server: McpServer, db: DB) {
330323
async ({ id }) => {
331324
try {
332325
const existingTag = await db.getTag(id)
333-
invariant(existingTag, `Tag ${id} not found`)
326+
invariant(existingTag, `Tag ID "${id}" not found`)
334327
await db.deleteTag(id)
335328
return {
336329
content: [
@@ -368,13 +361,13 @@ export function initializeTools(server: McpServer, db: DB) {
368361
const tag = await db.getTag(tagId)
369362
const entry = await db.getEntry(entryId)
370363
invariant(tag, `Tag ${tagId} not found`)
371-
invariant(entry, `Entry ${entryId} not found`)
364+
invariant(entry, `Entry with ID "${entryId}" not found`)
372365
const entryTag = await db.addTagToEntry({ entryId, tagId })
373366
return {
374367
content: [
375368
{
376369
type: 'text',
377-
text: `Tag ${tag.name} (${entryTag.tagId}) added to entry ${entry.title} (${entryTag.entryId}) successfully`,
370+
text: `Tag "${tag.name}" (ID: ${entryTag.tagId}) added to entry "${entry.title}" (ID: ${entryTag.entryId}) successfully`,
378371
},
379372
],
380373
}
@@ -402,7 +395,7 @@ export function initializeTools(server: McpServer, db: DB) {
402395
async ({ entryId }) => {
403396
try {
404397
const entry = await db.getEntry(entryId)
405-
invariant(entry, `Entry ${entryId} not found`)
398+
invariant(entry, `Entry with ID "${entryId}" not found`)
406399
const tags = await db.getEntryTags(entryId)
407400
return {
408401
content: [

0 commit comments

Comments
 (0)