Skip to content

Commit 9b4329c

Browse files
committed
improve instructions
1 parent 78aae12 commit 9b4329c

File tree

4 files changed

+57
-2
lines changed

4 files changed

+57
-2
lines changed

exercises/01.ping/01.problem.connect/README.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ comments.
1818

1919
Right now if you try to run the server, you'll get an error. Let's fix that!
2020

21+
- 📜 [MCP TypeScript SDK Docs](https://github.com/modelcontextprotocol/typescript-sdk)
2122
- 📜 [MCP Spec: Ping](https://modelcontextprotocol.io/specification/2025-03-26/basic/utilities/ping)

exercises/01.ping/01.problem.connect/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// 🐨 create a new McpServer
66
// - it should have a name of 'EpicMe' and a version of '1.0.0'
77
// - it should have instructions for the LLM to know what this server can be used to do (we'll start out by saying it can solve math problems)
8+
// 📜 If you're unsure how to do this, check out the MCP TypeScript SDK Docs:
9+
// https://github.com/modelcontextprotocol/typescript-sdk
810

911
async function main() {
1012
// 🐨 create a new StdioServerTransport

exercises/01.ping/01.solution.connect/README.mdx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,55 @@
22

33
👨‍💼 Great job! Now we know we've got an MCP server up and running. From here we
44
can start adding a bunch of different tools, resources, and more to it.
5+
6+
<details>
7+
<summary>🦉 What the StdioServerTransport does</summary>
8+
9+
The `StdioServerTransport` is a simple transport that allows you to connect to
10+
your MCP server using the command line. It's a good way to get started and
11+
understand how MCP servers work.
12+
13+
The MCP Client takes the `command` and `args` you configure and spawns a child
14+
process:
15+
16+
```ts
17+
import { spawn } from 'child_process'
18+
19+
// these come from our config in the MCP Inspector:
20+
const command = 'npm'
21+
const args = [
22+
'--silent',
23+
'--prefix',
24+
'/Users/kody/code/mcp-fundamentals',
25+
'run',
26+
'dev:mcp',
27+
]
28+
29+
// Then the MCP client spawns a child process:
30+
const child = spawn(command, args)
31+
```
32+
33+
Then it listens for messages from the child process and sends them to the MCP
34+
server:
35+
36+
```ts
37+
child.stdout.on('data', (data) => {
38+
console.log(data)
39+
})
40+
```
41+
42+
This is why we use `console.error` in our server, so that the MCP Client can
43+
print it to the console without interfering with the server's output.
44+
45+
It also listens for messages from the MCP server and sends them to the child
46+
process:
47+
48+
```ts
49+
child.stdin.write(JSON.stringify({ jsonrpc: '2.0', method: 'ping' }))
50+
```
51+
52+
Other transport mechanisms exist as well, and while the code for them is
53+
different the underlying concept is the same. Just a server and client
54+
communicating with each other.
55+
56+
</details>

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)