MCP TypeScript スターター
これは、TypeScriptを使用してモデルコンテキストプロトコル(MCP)サーバーを作成するためのスターターテンプレートです。サンプルツールの実装を含む基本的なセットアップが提供されており、独自のMCPサーバーの構築を始めるのに役立ちます。
特徴
- TypeScriptの設定
- 基本的なMCPサーバーのセットアップ
- サンプルツールの実装
- 型安全な開発環境
はじめる
独自の MCP サーバーを作成するには、次の手順に従います。
# Create a new directory for your project
mkdir <project_name>
cd <project_name>
# Initialize a new npm project
npm init -y
# Install dependencies
npm install @modelcontextprotocol/sdk zod
npm install -D @types/node typescript
# Create source directory and main file
mkdir src
touch src/index.ts
プロジェクト構造
.
├── src/
│ └── index.ts # Main server implementation
├── package.json # Project dependencies and scripts
└── tsconfig.json # TypeScript configuration
発達
src/index.ts
にツールを実装する- プロジェクトをビルドします。
新しいツールの追加
新しいツールを追加するには、 server.tool()
メソッドを使用します。例:
server.tool(
"tool-name",
"tool-description",
{
// Define your tool's parameters using Zod schema
param: z.string().describe("parameter description")
},
async ({ param }) => {
// Implement your tool logic here
return {
content: [
{
type: "text",
text: `Tool executed with parameter: ${param}`,
},
],
};
},
);
ライセンス
ISC