Skip to content

Commit 4438d62

Browse files
Merge pull request modelcontextprotocol#15 from modelcontextprotocol/justin/fixes
Tweaks to "Get started" and "Your first server"
2 parents 9a6d592 + 9a2bdab commit 4438d62

File tree

6 files changed

+249
-215
lines changed

6 files changed

+249
-215
lines changed

docs/concepts/transport.mdx renamed to docs/concepts/transports.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
2-
title: "Transport"
2+
title: "Transports"
33
description: "Learn about MCP's communication mechanisms"
44
---
55

6-
Transport in the Model Context Protocol (MCP) provides the foundation for communication between clients and servers. It handles the underlying mechanics of how messages are sent and received.
6+
Transports in the Model Context Protocol (MCP) provide the foundation for communication between clients and servers. A transport handles the underlying mechanics of how messages are sent and received.
77

8-
## How transport works
8+
## How transports work
99

10-
MCP transport is built on a simple message-passing architecture where both clients and servers can send messages to each other. The transport layer is responsible for:
10+
An MCP transport is built on a simple message-passing architecture where both clients and servers can send messages to each other. The transport layer is responsible for:
1111

1212
- Establishing connections
1313
- Sending messages
@@ -275,4 +275,4 @@ Choose the appropriate transport based on your needs:
275275
- Only server-to-client streaming is needed
276276
- WebSocket support is limited
277277
- Working with restricted networks
278-
- Implementing simple updates
278+
- Implementing simple updates

docs/first-server/python.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ Let's build your first MCP server in Python! We'll create a weather server that
1111

1212
## Prerequisites
1313

14+
<Info>
15+
The following steps are for macOS. Guides for other platforms are coming soon.
16+
</Info>
17+
1418
<Steps>
1519
<Step title="Install Python">
1620
You'll need Python 3.10 or higher:
@@ -20,7 +24,9 @@ Let's build your first MCP server in Python! We'll create a weather server that
2024
```
2125
</Step>
2226

23-
<Step title="Install uv (https://docs.astral.sh/uv/) via homebrew">
27+
<Step title="Install uv via homebrew">
28+
See https://docs.astral.sh/uv/ for more information.
29+
2430
```bash
2531
brew install uv
2632
uv --version # Should be 0.4.18 or higher

docs/first-server/typescript.mdx

Lines changed: 64 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -22,35 +22,17 @@ This guide uses the OpenWeatherMap API. You'll need a free API key from [OpenWea
2222
</Step>
2323

2424
<Step title="Create a new project">
25+
You can use our [create-typescript-server](https://github.com/modelcontextprotocol/create-typescript-server) tool to bootstrap a new project:
26+
2527
```bash
26-
mkdir weather-server
28+
npx @modelcontextprotocol/create-server weather-server
2729
cd weather-server
28-
npm init -y
2930
```
3031
</Step>
3132

3233
<Step title="Install dependencies">
3334
```bash
34-
npm install @modelcontextprotocol/sdk axios dotenv typescript @types/node
35-
npm install --save-dev ts-node
36-
```
37-
</Step>
38-
39-
<Step title="Configure TypeScript">
40-
Create `tsconfig.json`:
41-
```json
42-
{
43-
"compilerOptions": {
44-
"target": "ES2020",
45-
"module": "ES2020",
46-
"moduleResolution": "node",
47-
"esModuleInterop": true,
48-
"outDir": "./dist",
49-
"rootDir": "./src",
50-
"strict": true
51-
},
52-
"include": ["src/**/*"]
53-
}
35+
npm install --save axios dotenv
5436
```
5537
</Step>
5638

@@ -65,16 +47,8 @@ This guide uses the OpenWeatherMap API. You'll need a free API key from [OpenWea
6547
## Create your server
6648

6749
<Steps>
68-
<Step title="Create project structure">
69-
```bash
70-
mkdir src
71-
touch src/index.ts
72-
touch src/types.ts
73-
```
74-
</Step>
75-
7650
<Step title="Define types">
77-
In `src/types.ts`:
51+
Create a file `src/types.ts`, and add the following:
7852

7953
```typescript
8054
export interface OpenWeatherResponse {
@@ -111,7 +85,7 @@ This guide uses the OpenWeatherMap API. You'll need a free API key from [OpenWea
11185
}
11286

11387
// Type guard for forecast arguments
114-
export function isValidForecastArgs(args: unknown): args is GetForecastArgs {
88+
export function isValidForecastArgs(args: any): args is GetForecastArgs {
11589
return (
11690
typeof args === "object" &&
11791
args !== null &&
@@ -124,9 +98,10 @@ This guide uses the OpenWeatherMap API. You'll need a free API key from [OpenWea
12498
</Step>
12599

126100
<Step title="Add the base code">
127-
In `src/index.ts`:
101+
Replace `src/index.ts` with the following:
128102

129103
```typescript
104+
#!/usr/bin/env node
130105
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
131106
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
132107
import {
@@ -142,7 +117,6 @@ This guide uses the OpenWeatherMap API. You'll need a free API key from [OpenWea
142117
import {
143118
WeatherData,
144119
ForecastDay,
145-
GetForecastArgs,
146120
OpenWeatherResponse,
147121
isValidForecastArgs
148122
} from "./types.js";
@@ -171,6 +145,11 @@ This guide uses the OpenWeatherMap API. You'll need a free API key from [OpenWea
171145
this.server = new Server({
172146
name: "example-weather-server",
173147
version: "0.1.0"
148+
}, {
149+
capabilities: {
150+
resources: {},
151+
tools: {}
152+
}
174153
});
175154

176155
// Configure axios with defaults
@@ -223,7 +202,7 @@ This guide uses the OpenWeatherMap API. You'll need a free API key from [OpenWea
223202
</Step>
224203

225204
<Step title="Add resource handlers">
226-
Add this to the `setupHandlers` method:
205+
Add this to the `setupResourceHandlers` method:
227206

228207
```typescript
229208
private setupResourceHandlers(): void {
@@ -289,7 +268,7 @@ This guide uses the OpenWeatherMap API. You'll need a free API key from [OpenWea
289268
</Step>
290269

291270
<Step title="Add tool handlers">
292-
Add these handlers to the `setupHandlers` method:
271+
Add these handlers to the `setupToolHandlers` method:
293272

294273
```typescript
295274
private setupToolHandlers(): void {
@@ -359,13 +338,21 @@ This guide uses the OpenWeatherMap API. You'll need a free API key from [OpenWea
359338
});
360339
}
361340

362-
return { toolResult: forecasts };
341+
return {
342+
content: {
343+
mimeType: "application/json",
344+
text: JSON.stringify(forecasts, null, 2)
345+
}
346+
};
363347
} catch (error) {
364348
if (axios.isAxiosError(error)) {
365-
throw new McpError(
366-
ErrorCode.InternalError,
367-
`Weather API error: ${error.response?.data.message ?? error.message}`
368-
);
349+
return {
350+
content: {
351+
mimeType: "text/plain",
352+
text: `Weather API error: ${error.response?.data.message ?? error.message}`
353+
},
354+
isError: true,
355+
}
369356
}
370357
throw error;
371358
}
@@ -376,21 +363,9 @@ This guide uses the OpenWeatherMap API. You'll need a free API key from [OpenWea
376363
</Step>
377364

378365
<Step title="Build and test">
379-
Add these scripts to `package.json`:
380-
```json
381-
{
382-
"scripts": {
383-
"build": "tsc",
384-
"start": "node dist/index.js",
385-
"dev": "ts-node src/index.ts"
386-
}
387-
}
388-
```
389-
390-
Then run:
391366
```bash
392367
npm run build
393-
npm install -g .
368+
npm link
394369
```
395370
</Step>
396371
</Steps>
@@ -399,7 +374,7 @@ This guide uses the OpenWeatherMap API. You'll need a free API key from [OpenWea
399374

400375
<Steps>
401376
<Step title="Update Claude config">
402-
Add to `claude_desktop_config.json`:
377+
If you didn't already connect to Claude Desktop during project setup, add to `claude_desktop_config.json`:
403378

404379
```json
405380
{
@@ -504,14 +479,35 @@ This guide uses the OpenWeatherMap API. You'll need a free API key from [OpenWea
504479
title="Error Handling"
505480
icon="shield"
506481
>
482+
When a tool encounters an error, return the error message with `isError: true`, so the model can self-correct:
483+
484+
```typescript
485+
try {
486+
const response = await axiosInstance.get(...);
487+
} catch (error) {
488+
if (axios.isAxiosError(error)) {
489+
return {
490+
content: {
491+
mimeType: "text/plain",
492+
text: `Weather API error: ${error.response?.data.message ?? error.message}`
493+
},
494+
isError: true,
495+
}
496+
}
497+
throw error;
498+
}
499+
```
500+
501+
For other handlers, throw an error, so the application can notify the user:
502+
507503
```typescript
508504
try {
509505
const response = await this.axiosInstance.get(...);
510506
} catch (error) {
511507
if (axios.isAxiosError(error)) {
512508
throw new McpError(
513509
ErrorCode.InternalError,
514-
`API error: ${error.response?.data.message}`
510+
`Weather API error: ${error.response?.data.message}`
515511
);
516512
}
517513
throw error;
@@ -520,11 +516,11 @@ This guide uses the OpenWeatherMap API. You'll need a free API key from [OpenWea
520516
</Card>
521517

522518
<Card
523-
title="Type Guards"
519+
title="Type Validation"
524520
icon="check"
525521
>
526522
```typescript
527-
function isValidForecastArgs(args: unknown): args is GetForecastArgs {
523+
function isValidForecastArgs(args: any): args is GetForecastArgs {
528524
return (
529525
typeof args === "object" &&
530526
args !== null &&
@@ -533,71 +529,36 @@ This guide uses the OpenWeatherMap API. You'll need a free API key from [OpenWea
533529
);
534530
}
535531
```
536-
</Card>
537-
538-
<Card
539-
title="Environment Variables"
540-
icon="gear"
541-
>
542-
```typescript
543-
if (!process.env.OPENWEATHER_API_KEY) {
544-
throw new Error("OPENWEATHER_API_KEY is required");
545-
}
546-
```
547-
</Card>
548532

549-
<Card
550-
title="Constants"
551-
icon="box"
552-
>
553-
```typescript
554-
const API_CONFIG = {
555-
BASE_URL: '...',
556-
ENDPOINTS: {
557-
CURRENT: 'weather',
558-
FORECAST: 'forecast'
559-
}
560-
} as const;
561-
```
533+
<Tip>You can also use libraries like [Zod](https://zod.dev/) to perform this validation automatically.</Tip>
562534
</Card>
563535
</CardGroup>
564536

565537
## Available transports
566538

567-
While this guide uses stdio transport, MCP supports multiple transport options:
568-
569-
### WebSocket
570-
```typescript
571-
import { WebSocketServerTransport } from "@modelcontextprotocol/sdk/server/websocket.js";
572-
const transport = new WebSocketServerTransport();
573-
```
574-
575-
### SSE (Server-Sent Events)
576-
```typescript
577-
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
578-
const transport = new SSEServerTransport("/events", response);
579-
```
539+
While this guide uses stdio to run the MCP server as a local process, MCP supports other [transports](/docs/concepts/transports) as well.
580540

581541
## Troubleshooting
582542

543+
<Info>
544+
The following troubleshooting tips are for macOS. Guides for other platforms are coming soon.
545+
</Info>
546+
583547
### Build errors
584548
```bash
585549
# Check TypeScript version
586550
npx tsc --version
587551

588552
# Clean and rebuild
589-
rm -rf dist/
553+
rm -rf build/
590554
npm run build
591555
```
592556

593557
### Runtime errors
594-
Look for detailed error messages in the Claude app logs:
558+
Look for detailed error messages in the Claude Desktop logs:
595559
```bash
596-
# Launch Claude with logging
597-
open /Applications/Claude.app --stdout ~/Claude.log --stderr ~/Claude.log
598-
599560
# Monitor logs
600-
tail -f ~/Claude.log
561+
tail -n 20 -f ~/Library/Application\ Support/Claude/mcp*.log
601562
```
602563

603564
### Type errors
@@ -628,4 +589,4 @@ npx tsc --noEmit
628589

629590
<Note>
630591
Need help? Ask Claude! Since it has access to the MCP SDK documentation, it can help you debug issues and suggest improvements to your server.
631-
</Note>
592+
</Note>

introduction.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Choose the path that best fits your needs:
2626
</Card>
2727
<Card
2828
title="Build your first server (TypeScript)"
29-
icon="code"
29+
icon="square-js"
3030
href="/docs/first-server/typescript"
3131
>
3232
Create a simple MCP server in TypeScript to understand the basics
@@ -94,14 +94,14 @@ Dive deeper into MCP's core concepts and capabilities:
9494
Let your servers request completions from LLMs
9595
</Card>
9696
<Card
97-
title="Transport"
97+
title="Transports"
9898
icon="network-wired"
99-
href="/docs/concepts/transport"
99+
href="/docs/concepts/transports"
100100
>
101-
Learn about MCP's communication mechanisms
101+
Learn about MCP's communication mechanism
102102
</Card>
103103
</CardGroup>
104104

105105
## Contributing
106106

107-
Want to contribute? Check out our [GitHub repository](https://github.com/modelcontextprotocol) or join our growing community of developers building with MCP.
107+
Want to contribute? Check out [@modelcontextprotocol](https://github.com/modelcontextprotocol) on GitHub to join our growing community of developers building with MCP.

0 commit comments

Comments
 (0)