-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlesson.json
More file actions
658 lines (658 loc) · 17 KB
/
Copy pathlesson.json
File metadata and controls
658 lines (658 loc) · 17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
{
"id": "typescript-mcp-lesson",
"name": "Building an MCP Server with TypeScript",
"description": "Learn how to create the same MCP server using TypeScript and Anthropic's official SDK",
"actions": [
{
"name": "author-speak-before",
"value": "In the previous lesson, we built our first MCP server using FastMCP in Python and successfully tested it with mcp-cli."
},
{
"name": "author-speak-before",
"value": "Now let's create the exact same functionality using TypeScript and Anthropic's official MCP SDK. First, we'll organize our project by moving the Python file into its own folder."
},
{
"name": "author-speak-before",
"value": "We can close this python file for now."
},
{
"name": "mouse-move-editor-tab-close",
"value": "hello_mcp.py"
},
{
"name": "mouse-left-click",
"value": "1"
},
{
"name": "terminal-open",
"value": "1"
},
{
"name": "author-speak-before",
"value": "We'll make the folder with mkdir in the terminal."
},
{
"name": "terminal-type",
"value": "mkdir python"
},
{
"name": "terminal-enter",
"value": "1"
},
{
"name": "author-speak-before",
"value": "And move it into that folder."
},
{
"name": "terminal-type",
"value": "mv hello_mcp.py python/hello_mcp.py"
},
{
"name": "terminal-enter",
"value": "1"
},
{
"name": "author-speak-before",
"value": "Now let's create a typescript folder to keep our TypeScript implementation organized."
},
{
"name": "terminal-type",
"value": "mkdir typescript"
},
{
"name": "terminal-enter",
"value": "1"
},
{
"name": "terminal-type",
"value": "cd typescript"
},
{
"name": "terminal-enter",
"value": "1"
},
{
"name": "author-speak-before",
"value": "Perfect! Now let's set up our TypeScript project. We'll start by initializing a new Node.js project."
},
{
"name": "terminal-type",
"value": "npm init -y"
},
{
"name": "terminal-enter",
"value": "1"
},
{
"name": "file-explorer-create-file",
"value": "~/typescript/package.json"
},
{
"name": "file-explorer-set-file-contents",
"value": "~/typescript/package.json_____{\n \"name\": \"hello-mcp-typescript\",\n \"version\": \"1.0.0\",\n \"type\": \"module\",\n \"main\": \"build/index.js\",\n \"bin\": {\n \"hello-mcp-ts\": \"./build/index.js\"\n },\n \"scripts\": {\n \"build\": \"tsc\",\n \"start\": \"node build/index.js\"\n },\n \"dependencies\": {\n \"@modelcontextprotocol/sdk\": \"^1.13.1\",\n \"zod\": \"^3.22.4\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^22.10.5\",\n \"typescript\": \"^5.7.2\"\n }\n}"
},
{
"name": "terminal-set-output",
"value": "Wrote to package.json"
},
{
"name": "author-speak-before",
"value": "Now we'll install the Anthropic MCP SDK and TypeScript dependencies."
},
{
"name": "terminal-type",
"value": "npm install @modelcontextprotocol/sdk zod"
},
{
"name": "terminal-enter",
"value": "1"
},
{
"name": "terminal-set-output",
"value": "added 15 packages, and audited 16 packages in 2s"
},
{
"name": "terminal-type",
"value": "npm install -D typescript @types/node"
},
{
"name": "terminal-enter",
"value": "1"
},
{
"name": "terminal-set-output",
"value": "added 3 packages, and audited 19 packages in 1s"
},
{
"name": "author-speak-before",
"value": "Let's create our TypeScript configuration file."
},
{
"name": "mouse-move-file-explorer-folder",
"value": "typescript"
},
{
"name": "mouse-right-click",
"value": "1"
},
{
"name": "mouse-move-file-explorer-folder-context-menu-new-file",
"value": "1"
},
{
"name": "mouse-left-click",
"value": "1"
},
{
"name": "file-explorer-type-new-file-input",
"value": "tsconfig.json"
},
{
"name": "file-explorer-enter-new-file-input",
"value": "1"
},
{
"name": "editor-type",
"value": "{\n \"compilerOptions\": {\n \"target\": \"ES2022\",\n \"module\": \"Node16\",\n \"moduleResolution\": \"Node16\",\n \"outDir\": \"./build\",\n \"rootDir\": \"./src\",\n \"strict\": true,\n \"esModuleInterop\": true,\n \"skipLibCheck\": true,\n \"forceConsistentCasingInFileNames\": true\n },\n \"include\": [\"src /**/*\"],\n \"exclude\": [\"node_modules\"]\n}"
},
{
"name": "editor-save",
"value": "1"
},
{
"name": "author-speak-before",
"value": "Now let's create a source directory and our main TypeScript file."
},
{
"name": "mouse-move-file-explorer-folder",
"value": "typescript"
},
{
"name": "mouse-right-click",
"value": "1"
},
{
"name": "mouse-move-file-explorer-folder-context-menu-new-folder",
"value": "1"
},
{
"name": "mouse-left-click",
"value": "1"
},
{
"name": "file-explorer-type-new-folder-input",
"value": "src"
},
{
"name": "file-explorer-enter-new-folder-input",
"value": "1"
},
{
"name": "mouse-move-file-explorer-folder",
"value": "typescript/src"
},
{
"name": "mouse-right-click",
"value": "1"
},
{
"name": "mouse-move-file-explorer-folder-context-menu-new-file",
"value": "1"
},
{
"name": "mouse-left-click",
"value": "1"
},
{
"name": "file-explorer-type-new-file-input",
"value": "index.ts"
},
{
"name": "file-explorer-enter-new-file-input",
"value": "1"
},
{
"name": "author-speak-before",
"value": "Perfect! Now let's write our TypeScript MCP server. We'll start by importing the necessary modules from Anthropic's SDK."
},
{
"name": "editor-type",
"value": "import { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";"
},
{
"name": "editor-enter",
"value": "1"
},
{
"name": "editor-type",
"value": "import { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";"
},
{
"name": "editor-enter",
"value": "1"
},
{
"name": "editor-type",
"value": "import { z } from \"zod\";"
},
{
"name": "editor-enter",
"value": "2"
},
{
"name": "author-speak-before",
"value": "Next, we'll create our MCP server instance with the same 'hello' namespace we used in Python."
},
{
"name": "editor-type",
"value": "// 1. Create an MCP server with the same namespace"
},
{
"name": "editor-enter",
"value": "1"
},
{
"name": "editor-type",
"value": "const server = new McpServer({"
},
{
"name": "editor-enter",
"value": "1"
},
{
"name": "editor-type",
"value": " name: \"hello\","
},
{
"name": "editor-enter",
"value": "1"
},
{
"name": "editor-type",
"value": " version: \"1.0.0\""
},
{
"name": "editor-enter",
"value": "1"
},
{
"name": "editor-type",
"value": "});"
},
{
"name": "editor-enter",
"value": "2"
},
{
"name": "author-speak-before",
"value": "Now we'll register our greet tool using the same logic as our Python version. The TypeScript SDK uses registerTool method with Zod schema validation."
},
{
"name": "editor-type",
"value": "// 2. Register the same greet tool"
},
{
"name": "editor-enter",
"value": "1"
},
{
"name": "editor-type",
"value": "server.registerTool("
},
{
"name": "editor-enter",
"value": "1"
},
{
"name": "editor-type",
"value": " \"greet\","
},
{
"name": "editor-enter",
"value": "1"
},
{
"name": "editor-type",
"value": " {"
},
{
"name": "editor-enter",
"value": "1"
},
{
"name": "editor-type",
"value": " title: \"Greeting Tool\","
},
{
"name": "editor-enter",
"value": "1"
},
{
"name": "editor-type",
"value": " description: \"Return a friendly greeting\","
},
{
"name": "editor-enter",
"value": "1"
},
{
"name": "editor-type",
"value": " inputSchema: {"
},
{
"name": "editor-enter",
"value": "1"
},
{
"name": "editor-type",
"value": " name: z.string().describe(\"Name to greet\")"
},
{
"name": "editor-enter",
"value": "1"
},
{
"name": "editor-type",
"value": " }"
},
{
"name": "editor-enter",
"value": "1"
},
{
"name": "editor-type",
"value": " },"
},
{
"name": "editor-enter",
"value": "1"
},
{
"name": "editor-type",
"value": " async ({ name }) => ({"
},
{
"name": "editor-enter",
"value": "1"
},
{
"name": "editor-type",
"value": " content: [{"
},
{
"name": "editor-enter",
"value": "1"
},
{
"name": "editor-type",
"value": " type: \"text\","
},
{
"name": "editor-enter",
"value": "1"
},
{
"name": "editor-type",
"value": " text: `Hello, ${name}! 👋`"
},
{
"name": "editor-enter",
"value": "1"
},
{
"name": "editor-type",
"value": " }]"
},
{
"name": "editor-enter",
"value": "1"
},
{
"name": "editor-type",
"value": " })"
},
{
"name": "editor-enter",
"value": "1"
},
{
"name": "editor-type",
"value": ");"
},
{
"name": "editor-enter",
"value": "2"
},
{
"name": "author-speak-before",
"value": "Finally, let's add the startup code that connects our server to the stdio transport, just like our Python version."
},
{
"name": "editor-type",
"value": "// 3. Start the server with stdio transport"
},
{
"name": "editor-enter",
"value": "1"
},
{
"name": "editor-type",
"value": "async function main() {"
},
{
"name": "editor-enter",
"value": "1"
},
{
"name": "editor-type",
"value": " const transport = new StdioServerTransport();"
},
{
"name": "editor-enter",
"value": "1"
},
{
"name": "editor-type",
"value": " await server.connect(transport);"
},
{
"name": "editor-enter",
"value": "1"
},
{
"name": "editor-type",
"value": "}"
},
{
"name": "editor-enter",
"value": "2"
},
{
"name": "editor-type",
"value": "main().catch(console.error);"
},
{
"name": "author-speak-before",
"value": "Excellent! Our TypeScript MCP server is complete. Let's save the file and then update our package.json to include build scripts."
},
{
"name": "editor-save",
"value": "1"
},
{
"name": "mouse-move-file-explorer",
"value": "1"
},
{
"name": "mouse-left-click",
"value": "1"
},
{
"name": "author-speak-before",
"value": "Now let's build our TypeScript project."
},
{
"name": "terminal-type",
"value": "npm run build"
},
{
"name": "terminal-enter",
"value": "1"
},
{
"name": "terminal-set-output",
"value": "TypeScript compilation completed successfully"
},
{
"name": "author-speak-before",
"value": "Perfect! Now let's test our TypeScript MCP server the same way we tested the Python version."
},
{
"name": "terminal-type",
"value": "nohup npm start &"
},
{
"name": "terminal-enter",
"value": "1"
},
{
"name": "terminal-set-output",
"value": "🚀 MCP server \"hello\" listening on STDIN/STDOUT"
},
{
"name": "terminal-enter",
"value": "1"
},
{
"name": "author-speak-before",
"value": "Excellent! Our TypeScript server is now running. Let's test it with the exact same mcp-cli command we used before."
},
{
"name": "terminal-open",
"value": "1"
},
{
"name": "terminal-type",
"value": "echo '{ \"tool\": \"hello\", \"action\": \"greet\", \"params\": { \"name\": \"world\" } }' | npx mcp-cli call -"
},
{
"name": "terminal-enter",
"value": "1"
},
{
"name": "terminal-set-output",
"value": "{ \"status\": \"ok\", \"result\": \"Hello, world! 👋\" }"
},
{
"name": "terminal-enter",
"value": "1"
},
{
"name": "author-speak-before",
"value": "Perfect! We've successfully recreated the exact same MCP server functionality using TypeScript and Anthropic's official SDK."
},
{
"name": "author-speak-before",
"value": "Let's compare what we just built. Both servers expose the same 'hello' namespace with a 'greet' action that returns identical responses. The key differences are in the implementation approach."
},
{
"name": "author-speak-before",
"value": "The Python version used FastMCP with decorators - a more pythonic approach where @mcp.tool automatically converts functions into tools."
},
{
"name": "author-speak-before",
"value": "The TypeScript version uses Anthropic's official SDK with explicit registration and Zod schema validation, giving you more control over input validation and response formatting."
},
{
"name": "author-speak-before",
"value": "Both approaches achieve the same goal: creating MCP servers that any compatible client can connect to. Whether you choose Python or TypeScript depends on your team's preferences and existing tech stack."
},
{
"name": "author-speak-before",
"value": "In our next lesson, we'll explore more advanced MCP capabilities like resources and prompts, and see how to add multiple tools to create more sophisticated AI integrations!"
}
],
"initialSnapshot": {
"isUnsavedChangesDialogOpen": false,
"unsavedFileName": "",
"fileExplorerSnapshot": {
"fileStructure": {
"hello_mcp.py": {
"type": "file",
"content": "from fastmcp import FastMCP\n\n# 1. Instantiate a server and give our tool a namespace\nmcp = FastMCP(\"hello\")\n\n# 2. Expose a single action\n@mcp.tool\ndef greet(name: str) -> str:\n \"\"\"Return a friendly greeting.\"\"\"\n return f\"Hello,{name}! 👋\"\n\n# 3. Run with the built-in stdio transport (works with any client)\nif __name__ == \"__main__\":\n mcp.run()",
"language": "py",
"caretPosition": {
"row": 0,
"col": 0
}
}
},
"isFileExplorerContextMenuOpen": false,
"isFileContextMenuOpen": false,
"isFolderContextMenuOpen": false,
"isNewFileInputVisible": false,
"isNewFolderInputVisible": false,
"newFileInputValue": "",
"newFolderInputValue": "",
"isRenameFileInputVisible": false,
"isRenameFolderInputVisible": false,
"originalFileBeingRenamed": "",
"originalFolderBeingRenamed": "",
"renameFileInputValue": "",
"renameFolderInputValue": "",
"newFileParentPath": "",
"newFolderParentPath": ""
},
"editorSnapshot": {
"editors": [
{
"isActive": true,
"filename": "hello_mcp.py",
"content": "from fastmcp import FastMCP\n\n# 1. Instantiate a server and give our tool a namespace\nmcp = FastMCP(\"hello\")\n\n# 2. Expose a single action\n@mcp.tool\ndef greet(name: str) -> str:\n \"\"\"Return a friendly greeting.\"\"\"\n return f\"Hello,{name}! 👋\"\n\n# 3. Run with the built-in stdio transport (works with any client)\nif __name__ == \"__main__\":\n mcp.run()",
"caretPosition": {
"row": 14,
"col": 14
},
"highlightCoordinates": null,
"isSaved": true
}
],
"isEditorContextMenuOpen": false
},
"terminalSnapshot": {
"terminals": [
{
"content": ""
}
]
},
"mouseSnapshot": {
"location": "editor",
"currentHoveredFileName": "",
"currentHoveredFolderName": "",
"currentHoveredEditorTabFileName": "",
"x": 0,
"y": 0,
"timestamp": 0,
"type": "move",
"button": 0,
"buttonStates": {
"left": false,
"right": false,
"middle": false
},
"scrollPosition": {
"x": 0,
"y": 0
},
"scrollDelta": 0
},
"authorSnapshot": {
"authors": [
{
"currentSpeechCaption": "In the next lesson, we'll see how to create the same server but using TypeScript with Anthropic's TypeScript SDK. See you there!"
}
]
}
}
}