From 1e5dc3398e5ed914846ce2d9227a6de7a12f16ea Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Thu, 21 Nov 2024 13:22:16 +0000 Subject: [PATCH] Use `@modelcontextprotocol/create-server` --- docs/first-server/typescript.mdx | 54 +++++--------------------------- 1 file changed, 8 insertions(+), 46 deletions(-) diff --git a/docs/first-server/typescript.mdx b/docs/first-server/typescript.mdx index 0047394..d46c882 100644 --- a/docs/first-server/typescript.mdx +++ b/docs/first-server/typescript.mdx @@ -22,35 +22,17 @@ This guide uses the OpenWeatherMap API. You'll need a free API key from [OpenWea + You can use our [create-typescript-server](https://github.com/modelcontextprotocol/create-typescript-server) tool to bootstrap a new project: + ```bash - mkdir weather-server + npx @modelcontextprotocol/create-server weather-server cd weather-server - npm init -y ``` ```bash - npm install @modelcontextprotocol/sdk axios dotenv typescript @types/node - npm install --save-dev ts-node - ``` - - - - Create `tsconfig.json`: - ```json - { - "compilerOptions": { - "target": "ES2020", - "module": "ES2020", - "moduleResolution": "node", - "esModuleInterop": true, - "outDir": "./dist", - "rootDir": "./src", - "strict": true - }, - "include": ["src/**/*"] - } + npm install --save axios dotenv ``` @@ -65,16 +47,8 @@ This guide uses the OpenWeatherMap API. You'll need a free API key from [OpenWea ## Create your server - - ```bash - mkdir src - touch src/index.ts - touch src/types.ts - ``` - - - In `src/types.ts`: + Create a file `types.ts`, and add the following: ```typescript export interface OpenWeatherResponse { @@ -124,7 +98,7 @@ This guide uses the OpenWeatherMap API. You'll need a free API key from [OpenWea - In `src/index.ts`: + Replace `index.ts` with the following: ```typescript import { Server } from "@modelcontextprotocol/sdk/server/index.js"; @@ -376,21 +350,9 @@ This guide uses the OpenWeatherMap API. You'll need a free API key from [OpenWea - Add these scripts to `package.json`: - ```json - { - "scripts": { - "build": "tsc", - "start": "node dist/index.js", - "dev": "ts-node src/index.ts" - } - } - ``` - - Then run: ```bash npm run build - npm install -g . + npm link ``` @@ -628,4 +590,4 @@ npx tsc --noEmit 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. - \ No newline at end of file +