Cline公式の.clinerulesを用いてMCPプラグインを作成する
Cline公式DocsにMCPサーバーをClineによって作成する方法が書かれているのでその通りにやってみる。
肝は公式の提供するこの.clinerulesだ。.clinerulesのお手本としても参考になる。
code:txt
# MCP Plugin Development Protocol
⚠️ CRITICAL: DO NOT USE attempt_completion BEFORE TESTING ⚠️
## Step 1: Planning (PLAN MODE)
- What problem does this tool solve?
- What API/service will it use?
- What are the authentication requirements?
□ Standard API key
□ OAuth (requires separate setup script)
□ Other credentials
## Step 2: Implementation (ACT MODE)
1. Bootstrap
- For web services, JavaScript integration, or Node.js environments:
`bash
npx @modelcontextprotocol/create-server my-server
cd my-server
npm install
`
- For data science, ML workflows, or Python environments:
`bash
pip install mcp
# Or with uv (recommended)
`
2. Core Implementation
- Use MCP SDK
- Implement comprehensive logging
- TypeScript (for web/JS projects):
`typescript
console.error('Setup Initializing server...'); console.error('API Request to endpoint:', endpoint); console.error('Error Failed with:', error); `
- Python (for data science/ML projects):
`python
import logging
logging.error('Setup Initializing server...') logging.error(f'API Request to endpoint: {endpoint}') logging.error(f'Error Failed with: {str(error)}') `
- Add type definitions
- Handle errors with context
- Implement rate limiting if needed
3. Configuration
- Get credentials from user if needed
- Add to MCP settings:
- For TypeScript projects:
`json
{
"mcpServers": {
"my-server": {
"command": "node",
"env": {
"API_KEY": "key"
},
"disabled": false,
"autoApprove": []
}
}
}
`
- For Python projects:
`bash
# Directly with command line
mcp install server.py -v API_KEY=key
# Or in settings.json
{
"mcpServers": {
"my-server": {
"command": "python",
"env": {
"API_KEY": "key"
},
"disabled": false,
"autoApprove": []
}
}
}
`
## Step 3: Testing (BLOCKER ⛔️)
<thinking>
BEFORE using attempt_completion, I MUST verify:
□ Have I tested EVERY tool?
□ Have I confirmed success from the user for each test?
□ Have I documented the test results?
If ANY answer is "no", I MUST NOT use attempt_completion.
</thinking>
1. Test Each Tool (REQUIRED)
□ Test each tool with valid inputs
□ Verify output format is correct
⚠️ DO NOT PROCEED UNTIL ALL TOOLS TESTED
## Step 4: Completion
❗ STOP AND VERIFY:
□ Every tool has been tested with valid inputs
□ Output format is correct for each tool
Only after ALL tools have been tested can attempt_completion be used.
## Key Requirements
- ✓ Must use MCP SDK
- ✓ Must have comprehensive logging
- ✓ Must test each tool individually
- ✓ Must handle errors gracefully
- ⛔️ NEVER skip testing before completion
まずはこの.clinerulesを作業ディレクトリ作成する。
そして何を作りたいか?目的は何か?といったことをプロンプトとして2,3行で書くだけ。今回はscrapboxの公開ページの内容を取得してくれるMCPサーバーを作ってもらう。
code:txt
私はScrapboxの任意のページのURLを指定すると、そのページの内容を取得するMCPプラグインを作りたいです。
Scraxpboxのページのリンクは下記のような形式です。
あとはplan実行->act実行と進めば作成完了となる。
planモードで計画してくれた仕様はこんな感じ。DESIGN.mdみたいなファイルにまとめておいてもらってる。
code:md
# Scrapbox MCP プラグイン
## 概要
このMCPプラグインは、Scrapboxの任意のページのURLを指定すると、そのページの内容を取得する機能を提供します。Model Context Protocol (MCP)を使用して、AIアシスタントがScrapboxのコンテンツを直接参照できるようにします。
## 機能
- Scrapbox URLからページコンテンツを取得
- ページのタイトル、本文、リンク等の情報を構造化されたデータとして提供
- エラーハンドリングとログ記録
## 使用するAPI
- Scrapbox公開API
- エンドポイント: https://scrapbox.io/api/pages/{projectName}/{pageTitle}
- 認証: 公開ページの場合は不要
## 技術スタック
- TypeScript/Node.js
- MCP SDK
- axios (HTTPリクエスト用)
## 実装計画
### ツール
1. get_page_content: Scrapboxページの内容を取得するツール
- 入力: Scrapbox URL
- 出力: ページの内容(タイトル、本文、リンク等)
### 実装ステップ
1. プロジェクトのブートストラップ
2. Scrapbox APIとの通信機能の実装
- URLからプロジェクト名とページ名を抽出する関数
- APIリクエストを行う関数
3. MCPツールの実装
4. エラーハンドリングとログ記録の追加
5. 設定ファイルの作成
### エラーハンドリング
- 無効なURL形式
- 存在しないページ
- APIレスポンスエラー
- ネットワークエラー
## 使用方法
### インストール
`bash
# MCPプラグインのインストール
npm install
npm run build
`
### 設定
MCP設定ファイルに以下を追加:
`json
{
"mcpServers": {
"scrapbox": {
"command": "node",
"disabled": false,
"autoApprove": []
}
}
}
`
### 使用例
`
ユーザー: Scrapboxの「コルブの経験学習モデル」ページの内容を教えて
コルブの経験学習モデルについての情報:
...
`
## テスト計画
1. 有効なScrapbox URLでのテスト
2. 無効なURLでのテスト
3. 存在しないページでのテスト
4. 大きなページでのテスト(パフォーマンス)
## ライセンス
MIT
ちなみにClaude.appへのMCP設定もしてくれるのだけど、MCP設定ファイルのjsonに"command": "node",という感じでnodeを指定するとコマンドが見つからなくてspawn node ENOENTみたいなエラーが出るのでnodeの絶対パスとして/Users/hoge/.shims/nodeとかとにかくnodeの絶対パスを指定しておくとエラーが消えるはず。