Skip to content

Commit d85e851

Browse files
Merge pull request modelcontextprotocol#1950 from narengogi/fix/remove-deprecated-tool-initialization-code-in-typescript
Replace deprecated server.tool() initialization snippet in getting started with server.registerTool() for TS sdk
2 parents 575485d + 87ecde6 commit d85e851

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

docs/docs/develop/build-server.mdx

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -587,11 +587,17 @@ The tool execution handler is responsible for actually executing the logic of ea
587587

588588
```typescript
589589
// Register weather tools
590-
server.tool(
590+
591+
server.registerTool(
591592
"get_alerts",
592-
"Get weather alerts for a state",
593593
{
594-
state: z.string().length(2).describe("Two-letter state code (e.g. CA, NY)"),
594+
description: "Get weather alerts for a state",
595+
inputSchema: {
596+
state: z
597+
.string()
598+
.length(2)
599+
.describe("Two-letter state code (e.g. CA, NY)"),
600+
},
595601
},
596602
async ({ state }) => {
597603
const stateCode = state.toUpperCase();
@@ -635,16 +641,22 @@ server.tool(
635641
},
636642
);
637643

638-
server.tool(
644+
server.registerTool(
639645
"get_forecast",
640-
"Get weather forecast for a location",
641646
{
642-
latitude: z.number().min(-90).max(90).describe("Latitude of the location"),
643-
longitude: z
644-
.number()
645-
.min(-180)
646-
.max(180)
647-
.describe("Longitude of the location"),
647+
description: "Get weather forecast for a location",
648+
inputSchema: {
649+
latitude: z
650+
.number()
651+
.min(-90)
652+
.max(90)
653+
.describe("Latitude of the location"),
654+
longitude: z
655+
.number()
656+
.min(-180)
657+
.max(180)
658+
.describe("Longitude of the location"),
659+
},
648660
},
649661
async ({ latitude, longitude }) => {
650662
// Get grid point data

0 commit comments

Comments
 (0)