Skip to content

Commit 5662b4b

Browse files
committed
add title to mcp server and improve instructions
1 parent d4a0ccc commit 5662b4b

File tree

27 files changed

+72
-32
lines changed

27 files changed

+72
-32
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
// import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
44

55
// 🐨 create a new McpServer
6-
// - it should have a name of 'EpicMe' and a version of '1.0.0'
6+
// - it should have a name of 'epicme', title 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+
// 💰 NOTE: the `instructions` should appear as a property of an object in the second argument of the McpServer constructor
89
// 📜 If you're unsure how to do this, check out the MCP TypeScript SDK Docs:
910
// https://github.com/modelcontextprotocol/typescript-sdk
1011

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
33

44
const server = new McpServer(
55
{
6-
name: 'EpicMe',
6+
name: 'epicme',
7+
title: 'EpicMe',
78
version: '1.0.0',
89
},
910
{

exercises/02.tools/01.problem.simple/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
33

44
const server = new McpServer(
55
{
6-
name: 'EpicMe',
6+
name: 'epicme',
7+
title: 'EpicMe',
78
version: '1.0.0',
89
},
910
{

exercises/02.tools/01.solution.simple/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
33

44
const server = new McpServer(
55
{
6-
name: 'EpicMe',
6+
name: 'epicme',
7+
title: 'EpicMe',
78
version: '1.0.0',
89
},
910
{

exercises/02.tools/02.problem.args/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
33

44
const server = new McpServer(
55
{
6-
name: 'EpicMe',
6+
name: 'epicme',
7+
title: 'EpicMe',
78
version: '1.0.0',
89
},
910
{

exercises/02.tools/02.solution.args/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { z } from 'zod'
44

55
const server = new McpServer(
66
{
7-
name: 'EpicMe',
7+
name: 'epicme',
8+
title: 'EpicMe',
89
version: '1.0.0',
910
},
1011
{

exercises/02.tools/03.problem.errors/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { z } from 'zod'
44

55
const server = new McpServer(
66
{
7-
name: 'EpicMe',
7+
name: 'epicme',
8+
title: 'EpicMe',
89
version: '1.0.0',
910
},
1011
{

exercises/02.tools/03.solution.errors/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { z } from 'zod'
55

66
const server = new McpServer(
77
{
8-
name: 'EpicMe',
8+
name: 'epicme',
9+
title: 'EpicMe',
910
version: '1.0.0',
1011
},
1112
{

exercises/02.tools/README.mdx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,21 @@ sequenceDiagram
7777

7878
## Example: Defining a Simple Tool
7979

80-
```ts
80+
```ts lines=7
8181
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
8282

8383
const server = new McpServer(
8484
{ name: 'hello-world-server', version: '1.0.0' },
85-
{ capabilities: { tools: {} }, instructions: 'A simple hello world server.' },
85+
{
86+
capabilities: {
87+
// add the tools object to explicitly declare that this server supports tools
88+
tools: {},
89+
},
90+
instructions: 'A simple hello world server.',
91+
},
8692
)
8793

94+
// register a tool with the server
8895
server.registerTool(
8996
// llm-facing name
9097
'hello',
@@ -93,10 +100,15 @@ server.registerTool(
93100
title: 'Hello',
94101
// llm-facing description (clients could also display this to the user)
95102
description: 'Say hello',
103+
// add a schema to validate the input
104+
inputSchema: {
105+
// the input description is llm-facing, (the user may see it as well)
106+
name: z.string().describe('The name to say hello to'),
107+
},
96108
},
97-
async () => {
109+
async ({ name }) => {
98110
return {
99-
content: [{ type: 'text', text: 'Hello, world!' }],
111+
content: [{ type: 'text', text: `Hello, ${name}!` }],
100112
}
101113
},
102114
)
@@ -111,7 +123,9 @@ Example client request:
111123
"method": "tools/call",
112124
"params": {
113125
"name": "hello",
114-
"arguments": {}
126+
"arguments": {
127+
"name": "Kody"
128+
}
115129
}
116130
}
117131
```
@@ -126,7 +140,7 @@ Example server response:
126140
"content": [
127141
{
128142
"type": "text",
129-
"text": "Hello, world!"
143+
"text": "Hello, Kody!"
130144
}
131145
],
132146
"isError": false

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ export class EpicMeMCP {
99
db: DB
1010
server = new McpServer(
1111
{
12-
name: 'EpicMe',
12+
name: 'epicme',
13+
title: 'EpicMe',
1314
version: '1.0.0',
1415
},
1516
{

0 commit comments

Comments
 (0)