├── .gitignore
├── README.ja.md
├── README.md
├── assets
├── example-header.svg
├── file-operations-header.svg
├── git-header.svg
├── header.svg
├── nodejs-header.svg
├── python-header.svg
├── release-header-v0.1.0.svg
└── terraform-header.svg
├── docs
└── RELEASE_NOTE_v0.1.0.md
├── example
├── README.md
├── file-operations
│ ├── README.md
│ └── sample.txt
├── git
│ ├── .gitignore
│ └── README.md
├── nodejs
│ ├── README.md
│ ├── app.js
│ └── package.json
├── python
│ ├── README.md
│ └── hello.py
└── terraform
│ ├── README.md
│ └── main.tf
├── package-lock.json
├── package.json
├── src
└── index.ts
└── tsconfig.json
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | build/
3 | *.log
4 | .env*
5 | tasks
6 | tmp/
7 | example/terraform/.terraform
8 | example/terraform/.terraform.lock.hcl
9 | example/terraform/terraform.tfstate
10 | example/terraform/terraform.tfstate.backup
11 |
--------------------------------------------------------------------------------
/README.ja.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # command-executor MCP サーバー
4 |
5 |

6 |
7 |

8 |

9 |
10 |
11 | 事前に承認されたコマンドを安全に実行するためのModel Context Protocolサーバーです。
12 |
13 | ## 🎥 デモ
14 |
15 | https://github.com/user-attachments/assets/ed763a12-b685-4e0b-b9a5-bc948a590f51
16 |
17 | ## ✨ 特徴
18 |
19 | - 事前承認されたコマンドリストによる安全な実行
20 | - 環境変数によるコマンドリストのカスタマイズ機能
21 | - TypeScriptとMCP SDKを使用して構築
22 | - stdioを介した通信による柔軟な統合
23 | - エラーハンドリングとセキュリティ検証
24 | - リアルタイムなコマンド出力ストリーミング
25 |
26 | ## 🚀 インストール
27 |
28 | 依存関係のインストール:
29 | ```bash
30 | npm install
31 | ```
32 |
33 | サーバーのビルド:
34 | ```bash
35 | npm run build
36 | ```
37 |
38 | 開発時の自動リビルド:
39 | ```bash
40 | npm run watch
41 | ```
42 |
43 | ## ⚙️ 設定
44 |
45 | ### 🔒 許可されたコマンド
46 |
47 | デフォルトで以下のコマンドが許可されています:
48 | - git
49 | - ls
50 | - mkdir
51 | - cd
52 | - npm
53 | - npx
54 | - python
55 |
56 | `ALLOWED_COMMANDS`環境変数を設定することで、許可するコマンドをカスタマイズできます:
57 |
58 | ```bash
59 | export ALLOWED_COMMANDS=git,ls,mkdir,python
60 | ```
61 |
62 | ### 🔌 Claude Desktopとの統合
63 |
64 | Claude Desktopで使用するには、以下の場所にサーバー設定を追加してください:
65 |
66 | MacOSの場合:
67 | ```bash
68 | ~/Library/Application Support/Claude/claude_desktop_config.json
69 | ```
70 |
71 | Windowsの場合:
72 | ```
73 | %APPDATA%/Claude/claude_desktop_config.json
74 | ```
75 |
76 | 設定例:
77 | ```json
78 | {
79 | "mcpServers": {
80 | "command-executor": {
81 | "command": "/path/to/command-executor/build/index.js"
82 | }
83 | }
84 | }
85 | ```
86 |
87 | ## 🛡️ セキュリティに関する考慮事項
88 |
89 | command-executorサーバーは以下のセキュリティ対策を実装しています:
90 |
91 | 1. 事前承認コマンドリスト
92 | - 明示的に許可されたコマンドのみ実行可能
93 | - デフォルトリストは制限的でセキュリティ重視
94 | - プレフィックスによるコマンドの検証でインジェクションを防止
95 |
96 | 2. コマンドの検証
97 | - コマンドプレフィックスの検証によりコマンドインジェクションを防止
98 | - セキュリティ向上のためのシェル実行の制限
99 | - 環境変数の適切なサニタイズ
100 |
101 | 3. エラーハンドリング
102 | - 未承認コマンドに対する包括的なエラーハンドリング
103 | - デバッグ用の明確なエラーメッセージ
104 | - コマンド失敗時のサーバー継続動作
105 |
106 | 4. 環境の分離
107 | - 独立した環境でのサーバー実行
108 | - 制御可能な環境変数
109 | - システムアクセスの制限
110 |
111 | ## 💻 開発
112 |
113 | ### 📁 プロジェクト構造
114 |
115 | ```
116 | command-executor/
117 | ├─ src/
118 | │ └─ index.ts # メインサーバーの実装
119 | ├─ build/
120 | │ └─ index.js # コンパイル済みJavaScript
121 | ├─ assets/
122 | │ └─ header.svg # プロジェクトヘッダー画像
123 | └─ package.json # プロジェクト設定
124 | ```
125 |
126 | ### 🐛 デバッグ
127 |
128 | MCPサーバーはstdioを介して通信するため、デバッグが難しい場合があります。[MCP Inspector](https://github.com/modelcontextprotocol/inspector)の使用を推奨します:
129 |
130 | ```bash
131 | npm run inspector
132 | ```
133 |
134 | InspectorはブラウザでデバッグツールにアクセスするためのURLを提供します。
135 |
136 | ## 🛠️ ツールAPI
137 |
138 | サーバーは以下の単一のツールを提供します:
139 |
140 | ### execute_command
141 |
142 | 事前承認されたコマンドを実行します。
143 |
144 | パラメータ:
145 | - `command` (string, 必須):実行するコマンド
146 |
147 | リクエスト例:
148 | ```json
149 | {
150 | "name": "execute_command",
151 | "arguments": {
152 | "command": "git status"
153 | }
154 | }
155 | ```
156 |
157 | レスポンス例:
158 | ```json
159 | {
160 | "content": [
161 | {
162 | "type": "text",
163 | "text": "On branch main\nNothing to commit, working tree clean"
164 | }
165 | ]
166 | }
167 | ```
168 |
169 | エラーレスポンス:
170 | ```json
171 | {
172 | "content": [
173 | {
174 | "type": "text",
175 | "text": "Command execution failed: Command not allowed"
176 | }
177 | ],
178 | "isError": true
179 | }
180 | ```
181 |
182 | ## ❌ エラーハンドリング
183 |
184 | サーバーは様々なシナリオに対して詳細なエラーメッセージを提供します:
185 |
186 | 1. 未承認コマンド
187 | ```json
188 | {
189 | "code": "InvalidParams",
190 | "message": "Command not allowed: [command]. Allowed commands: git, ls, mkdir, cd, npm, npx, python"
191 | }
192 | ```
193 |
194 | 2. 実行失敗
195 | ```json
196 | {
197 | "content": [
198 | {
199 | "type": "text",
200 | "text": "Command execution failed: [error message]"
201 | }
202 | ],
203 | "isError": true
204 | }
205 | ```
206 |
207 | ## 🤝 コントリビューション
208 |
209 | 1. リポジトリをフォーク
210 | 2. 機能ブランチを作成
211 | 3. 変更をコミット
212 | 4. ブランチにプッシュ
213 | 5. プルリクエストを作成
214 |
215 | ## 📄 ライセンス
216 |
217 | このプロジェクトはMITライセンスの下で公開されています - 詳細はLICENSEファイルを参照してください。
218 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # command-executor MCP Server
4 |
5 |

6 |
7 |

8 |

9 |
10 |
11 | A Model Context Protocol server for executing pre-approved commands securely.
12 |
13 | ## 🎥 Demo
14 |
15 | https://github.com/user-attachments/assets/ed763a12-b685-4e0b-b9a5-bc948a590f51
16 |
17 | ## ✨ Features
18 |
19 | - Secure command execution with pre-approved command list
20 | - Configurable allowed commands through environment variables
21 | - Built with TypeScript and MCP SDK
22 | - Communication via stdio for seamless integration
23 | - Error handling and security validations
24 | - Real-time command output streaming
25 |
26 | ## 🚀 Installation
27 |
28 | Install dependencies:
29 | ```bash
30 | npm install
31 | ```
32 |
33 | Build the server:
34 | ```bash
35 | npm run build
36 | ```
37 |
38 | For development with auto-rebuild:
39 | ```bash
40 | npm run watch
41 | ```
42 |
43 | ## ⚙️ Configuration
44 |
45 | ### 🔒 Allowed Commands
46 |
47 | By default, the following commands are allowed:
48 | - git
49 | - ls
50 | - mkdir
51 | - cd
52 | - npm
53 | - npx
54 | - python
55 |
56 | You can customize the allowed commands by setting the `ALLOWED_COMMANDS` environment variable:
57 |
58 | ```bash
59 | export ALLOWED_COMMANDS=git,ls,mkdir,python
60 | ```
61 |
62 | ### 🔌 Claude Desktop Integration
63 |
64 | To use with Claude Desktop, add the server config:
65 |
66 | On MacOS:
67 | ```bash
68 | ~/Library/Application Support/Claude/claude_desktop_config.json
69 | ```
70 |
71 | On Windows:
72 | ```
73 | %APPDATA%/Claude/claude_desktop_config.json
74 | ```
75 |
76 | Configuration example:
77 | ```json
78 | {
79 | "mcpServers": {
80 | "command-executor": {
81 | "command": "/path/to/command-executor/build/index.js"
82 | }
83 | }
84 | }
85 | ```
86 |
87 | ## 🛡️ Security Considerations
88 |
89 | The command-executor server implements several security measures:
90 |
91 | 1. Pre-approved Command List
92 | - Only explicitly allowed commands can be executed
93 | - Default list is restrictive and security-focused
94 | - Commands are validated by prefix to prevent injection
95 |
96 | 2. Command Validation
97 | - Command prefix validation prevents command injection
98 | - No shell execution for improved security
99 | - Environment variables are properly sanitized
100 |
101 | 3. Error Handling
102 | - Comprehensive error handling for unauthorized commands
103 | - Clear error messages for debugging
104 | - Failed commands don't crash the server
105 |
106 | 4. Environment Isolation
107 | - Server runs in its own environment
108 | - Environment variables can be controlled
109 | - Limited system access
110 |
111 | ## 💻 Development
112 |
113 | ### 📁 Project Structure
114 |
115 | ```
116 | command-executor/
117 | ├─ src/
118 | │ └─ index.ts # Main server implementation
119 | ├─ build/
120 | │ └─ index.js # Compiled JavaScript
121 | ├─ assets/
122 | │ └─ header.svg # Project header image
123 | └─ package.json # Project configuration
124 | ```
125 |
126 | ### 🐛 Debugging
127 |
128 | Since MCP servers communicate over stdio, debugging can be challenging. We recommend using the [MCP Inspector](https://github.com/modelcontextprotocol/inspector):
129 |
130 | ```bash
131 | npm run inspector
132 | ```
133 |
134 | The Inspector will provide a URL to access debugging tools in your browser.
135 |
136 | ## 🛠️ Tool API
137 |
138 | The server provides a single tool:
139 |
140 | ### execute_command
141 |
142 | Executes a pre-approved command.
143 |
144 | Parameters:
145 | - `command` (string, required): The command to execute
146 |
147 | Example Request:
148 | ```json
149 | {
150 | "name": "execute_command",
151 | "arguments": {
152 | "command": "git status"
153 | }
154 | }
155 | ```
156 |
157 | Example Response:
158 | ```json
159 | {
160 | "content": [
161 | {
162 | "type": "text",
163 | "text": "On branch main\nNothing to commit, working tree clean"
164 | }
165 | ]
166 | }
167 | ```
168 |
169 | Error Response:
170 | ```json
171 | {
172 | "content": [
173 | {
174 | "type": "text",
175 | "text": "Command execution failed: Command not allowed"
176 | }
177 | ],
178 | "isError": true
179 | }
180 | ```
181 |
182 | ## ❌ Error Handling
183 |
184 | The server provides detailed error messages for various scenarios:
185 |
186 | 1. Unauthorized Commands
187 | ```json
188 | {
189 | "code": "InvalidParams",
190 | "message": "Command not allowed: [command]. Allowed commands: git, ls, mkdir, cd, npm, npx, python"
191 | }
192 | ```
193 |
194 | 2. Execution Failures
195 | ```json
196 | {
197 | "content": [
198 | {
199 | "type": "text",
200 | "text": "Command execution failed: [error message]"
201 | }
202 | ],
203 | "isError": true
204 | }
205 | ```
206 |
207 | ## 🤝 Contributing
208 |
209 | 1. Fork the repository
210 | 2. Create your feature branch
211 | 3. Commit your changes
212 | 4. Push to the branch
213 | 5. Create a new Pull Request
214 |
215 | ## 📄 License
216 |
217 | This project is licensed under the MIT License - see the LICENSE file for details.
218 |
--------------------------------------------------------------------------------
/assets/example-header.svg:
--------------------------------------------------------------------------------
1 |
111 |
--------------------------------------------------------------------------------
/assets/file-operations-header.svg:
--------------------------------------------------------------------------------
1 |
111 |
--------------------------------------------------------------------------------
/assets/git-header.svg:
--------------------------------------------------------------------------------
1 |
111 |
--------------------------------------------------------------------------------
/assets/header.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/assets/nodejs-header.svg:
--------------------------------------------------------------------------------
1 |
111 |
--------------------------------------------------------------------------------
/assets/python-header.svg:
--------------------------------------------------------------------------------
1 |
111 |
--------------------------------------------------------------------------------
/assets/release-header-v0.1.0.svg:
--------------------------------------------------------------------------------
1 |
109 |
--------------------------------------------------------------------------------
/assets/terraform-header.svg:
--------------------------------------------------------------------------------
1 |
111 |
--------------------------------------------------------------------------------
/docs/RELEASE_NOTE_v0.1.0.md:
--------------------------------------------------------------------------------
1 | # 🚀 Command Executor MCP Server:v0.1.0 - 2024-12-22
2 |
3 | 
4 |
5 | ## 主な変更点 / Highlights
6 |
7 | 製品バージョン `0.1.0` では以下の改善が行われました:
8 |
9 | - 🎯 MCPコマンド実行サーバーの初期実装
10 | - 🎨 リリースノート用のヘッダーSVG画像の実装
11 | - 📝 多言語対応(日本語・英語)READMEの追加
12 |
13 | ## ✨ 新機能 / New Features
14 |
15 | ### ⭐️ MCPコマンド実行サーバー
16 | - MCPプロトコルに準拠したコマンド実行サーバーの実装
17 | - 事前に許可されたコマンドのみを安全に実行可能
18 | - 関連Issue: #1
19 |
20 | ### 🎨 リリースノート用ヘッダー画像
21 | - SVGフォーマットによる高品質なヘッダー画像の作成
22 | - バージョン番号を含む動的な画像生成機能
23 | - 関連Issue: #1
24 |
25 | ## 🔧 改善 / Improvements
26 |
27 | - READMEの多言語対応(日本語・英語)
28 | - ドキュメントの可読性向上(絵文字の追加)
29 | - Gitの無視設定の最適化
30 |
31 | ## 📝 その他の変更 / Other Changes
32 |
33 | - プロジェクト構造の整理
34 | - 不要なアセットファイルの整理
35 | - ドキュメントの体裁統一
36 |
37 | ## 📦 アップグレード方法 / How to Upgrade
38 |
39 | ```bash
40 | # パッケージマネージャーを使用している場合
41 | npm install @modelcontextprotocol/command-executor@latest
42 |
43 | # または
44 | yarn add @modelcontextprotocol/command-executor@latest
45 | ```
46 |
47 | ## 🙏 謝辞 / Acknowledgements
48 |
49 | このリリースに貢献してくださった皆様に感謝いたします。
50 |
51 | ---
52 | **Full Changelog**: [Initial...v0.1.0](https://github.com/Sunwood-ai-labs/command-executor-mcp-server/compare/add3524...214f808)
53 |
--------------------------------------------------------------------------------
/example/README.md:
--------------------------------------------------------------------------------
1 |
2 |

3 |
4 |
5 | # コマンド実行サンプル集
6 |
7 | このディレクトリには、様々なコマンドライン操作のサンプルが含まれています。
8 |
9 | ## 📁 ディレクトリ構成
10 |
11 | - [git](./git/): Gitバージョン管理システムの基本的な操作例
12 | - コミット、ブランチ、リモートリポジトリの操作など
13 | - `.gitignore`の設定例
14 |
15 | - [file-operations](./file-operations/): ファイルシステム操作の使用例
16 | - ls, dir, mkdir, cdなどの基本コマンド
17 | - ファイル操作の実践的なサンプル
18 |
19 | - [nodejs](./nodejs/): Node.js関連のコマンド例
20 | - npm, npxの使用方法
21 | - パッケージ管理とスクリプト実行
22 | - シンプルなHTTPサーバーの実装
23 |
24 | - [python](./python/): Python実行環境とパッケージ管理
25 | - スクリプト実行とモジュール管理
26 | - pip、venv環境の使用例
27 | - 基本的な関数実装サンプル
28 |
29 | - [terraform](./terraform/): Terraformインフラストラクチャ管理
30 | - AWSリソースの設定例
31 | - 状態管理とワークスペース操作
32 | - プランとデプロイメントの実行
33 |
34 | ## 🚀 使用方法
35 |
36 | 各ディレクトリには、それぞれの分野に特化したREADMEファイルが含まれています。
37 | これらのREADMEには、一般的なユースケースとコマンドの使用例が記載されています。
38 |
39 | また、実際に試せるサンプルファイルも用意されていますので、手元で動作を確認しながら学習することができます。
40 |
41 | ## 📝 注意事項
42 |
43 | - 各コマンドは、使用している環境(Windows/Unix系)によって異なる場合があります
44 | - 実際の使用時は、プロジェクトやシステムの要件に応じて適切なコマンドを選択してください
45 | - セキュリティに関わるコマンドは、十分な理解と注意を持って実行してください
46 |
--------------------------------------------------------------------------------
/example/file-operations/README.md:
--------------------------------------------------------------------------------
1 |
2 |

3 |
4 |
5 | # ファイル操作サンプル
6 |
7 | このディレクトリには、基本的なファイル操作のサンプルが含まれています。
8 |
9 | ## ディレクトリ操作
10 |
11 | ```bash
12 | # ディレクトリの作成
13 | mkdir new_directory
14 |
15 | # ディレクトリの移動
16 | cd new_directory
17 |
18 | # 現在のディレクトリの内容表示(Windows)
19 | dir
20 |
21 | # 現在のディレクトリの内容表示(Unix系)
22 | ls
23 | ls -la # 詳細表示
24 |
25 | # ディレクトリの削除
26 | rmdir empty_directory # 空のディレクトリの場合
27 | rm -rf directory # ディレクトリとその中身を削除(Unix系)
28 | rd /s /q directory # ディレクトリとその中身を削除(Windows)
29 | ```
30 |
31 | ## ファイル操作
32 |
33 | ```bash
34 | # ファイルの内容表示(Windows)
35 | type filename.txt
36 |
37 | # ファイルの内容表示(Unix系)
38 | cat filename.txt
39 |
40 | # ファイルのコピー
41 | copy source.txt destination.txt # Windows
42 | cp source.txt destination.txt # Unix系
43 |
44 | # ファイルの移動/名前変更
45 | move old.txt new.txt # Windows
46 | mv old.txt new.txt # Unix系
47 |
48 | # ファイルの削除
49 | del filename.txt # Windows
50 | rm filename.txt # Unix系
51 | ```
52 |
53 | ## サンプルファイル
54 |
55 | [sample.txt](./sample.txt)には、基本的なファイル操作を試すためのテキストが含まれています。
56 | このファイルを使って、上記のコマンドを実際に試すことができます。
57 |
--------------------------------------------------------------------------------
/example/file-operations/sample.txt:
--------------------------------------------------------------------------------
1 | これはサンプルテキストファイルです。
2 | このファイルを使って、以下のような操作を試すことができます:
3 |
4 | 1. ファイルの内容表示 (type / cat)
5 | 2. ファイルのコピー (copy / cp)
6 | 3. ファイルの移動 (move / mv)
7 | 4. ファイルの削除 (del / rm)
8 |
9 | また、このファイルを使って、パーミッションの変更やファイル情報の表示なども試すことができます。
10 |
--------------------------------------------------------------------------------
/example/git/.gitignore:
--------------------------------------------------------------------------------
1 | # Node.js
2 | node_modules/
3 | npm-debug.log
4 | yarn-debug.log
5 | yarn-error.log
6 |
7 | # Python
8 | __pycache__/
9 | *.py[cod]
10 | *.so
11 | env/
12 | venv/
13 | .env
14 |
15 | # IDE
16 | .vscode/
17 | .idea/
18 | *.swp
19 | *.swo
20 |
21 | # OS
22 | .DS_Store
23 | Thumbs.db
24 |
--------------------------------------------------------------------------------
/example/git/README.md:
--------------------------------------------------------------------------------
1 |
2 |

3 |
4 |
5 | # Git操作サンプル
6 |
7 | このディレクトリには、Git操作のサンプルスクリプトが含まれています。
8 |
9 | ## 基本的な操作
10 |
11 | ```bash
12 | # リポジトリの初期化
13 | git init
14 |
15 | # ファイルの追加
16 | git add .
17 | git add filename.txt
18 |
19 | # 変更の確認
20 | git status
21 |
22 | # 差分の確認
23 | git diff
24 | ```
25 |
26 | ## コミット操作
27 |
28 | ```bash
29 | # 変更のコミット
30 | git commit -m "コミットメッセージ"
31 |
32 | # 直前のコミットの修正
33 | git commit --amend
34 |
35 | # コミット履歴の確認
36 | git log
37 | git log --oneline
38 | ```
39 |
40 | ## ブランチ操作
41 |
42 | ```bash
43 | # ブランチの作成
44 | git branch feature/new-feature
45 |
46 | # ブランチの切り替え
47 | git checkout feature/new-feature
48 | # または
49 | git switch feature/new-feature
50 |
51 | # ブランチの作成と切り替えを同時に行う
52 | git checkout -b feature/new-feature
53 |
54 | # ブランチ一覧の表示
55 | git branch
56 | git branch -a # リモートブランチも含めて表示
57 | ```
58 |
59 | ## リモートリポジトリ操作
60 |
61 | ```bash
62 | # リモートリポジトリの追加
63 | git remote add origin https://github.com/username/repo.git
64 |
65 | # 変更のプッシュ
66 | git push origin main
67 | git push -u origin main # 上流ブランチの設定を含む
68 |
69 | # リモートの変更の取得
70 | git fetch origin
71 |
72 | # リモートの変更の取得とマージ
73 | git pull origin main
74 | ```
75 |
76 | ## その他の操作
77 |
78 | ```bash
79 | # 変更の退避
80 | git stash
81 | git stash pop
82 |
83 | # タグの作成
84 | git tag v1.0.0
85 |
86 | # 特定のコミットに戻る
87 | git reset --hard commit-hash
88 |
89 | # 変更の取り消し
90 | git checkout -- filename.txt
91 | ```
92 |
93 | ## サンプルファイル
94 |
95 | [.gitignore](./.gitignore)には、一般的なGitの除外設定例が含まれています。
96 | このファイルを参考に、プロジェクトに応じた除外設定を行うことができます。
97 |
--------------------------------------------------------------------------------
/example/nodejs/README.md:
--------------------------------------------------------------------------------
1 |
2 |

3 |
4 |
5 | # Node.js関連サンプル
6 |
7 | このディレクトリには、npm/npxコマンドの使用例が含まれています。
8 |
9 | ## プロジェクト初期化と依存関係管理
10 |
11 | ```bash
12 | # 新規プロジェクトの初期化
13 | npm init -y
14 |
15 | # パッケージのインストール
16 | npm install express # 依存関係として追加
17 | npm install --save-dev jest # 開発依存関係として追加
18 |
19 | # グローバルパッケージのインストール
20 | npm install -g typescript
21 |
22 | # パッケージの更新
23 | npm update
24 |
25 | # パッケージの削除
26 | npm uninstall package-name
27 |
28 | # 依存関係の一覧表示
29 | npm list
30 | ```
31 |
32 | ## スクリプトの実行
33 |
34 | ```bash
35 | # package.jsonのscriptsセクションに定義されたコマンドの実行
36 | npm run test
37 | npm run build
38 | npm run start
39 |
40 | # 開発サーバーの起動(一般的な例)
41 | npm run dev
42 | ```
43 |
44 | ## npxの使用例
45 |
46 | ```bash
47 | # Create React Appを使用して新しいReactプロジェクトを作成
48 | npx create-react-app my-app
49 |
50 | # TypeScriptプロジェクトの初期化
51 | npx tsc --init
52 |
53 | # パッケージを一時的に実行
54 | npx cowsay "Hello!"
55 | ```
56 |
57 | ## パッケージ管理のベストプラクティス
58 |
59 | ```bash
60 | # package-lock.jsonを使用した一貫したインストール
61 | npm ci
62 |
63 | # 脆弱性のチェック
64 | npm audit
65 |
66 | # 脆弱性の修正
67 | npm audit fix
68 | ```
69 |
70 | ## サンプルファイル
71 |
72 | - [package.json](./package.json): プロジェクト設定ファイル
73 | - [app.js](./app.js): シンプルなHTTPサーバーと非同期処理の例
74 |
--------------------------------------------------------------------------------
/example/nodejs/app.js:
--------------------------------------------------------------------------------
1 | // シンプルなHTTPサーバーの例
2 | const http = require('http');
3 |
4 | const PORT = 3000;
5 |
6 | // サーバーの作成
7 | const server = http.createServer((req, res) => {
8 | // レスポンスヘッダーの設定
9 | res.writeHead(200, {'Content-Type': 'text/plain'});
10 |
11 | // 現在時刻を含むメッセージを送信
12 | const message = `Hello Node.js! Current time: ${new Date().toLocaleString()}`;
13 | res.end(message);
14 | });
15 |
16 | // サーバーの起動
17 | server.listen(PORT, () => {
18 | console.log(`サーバーが起動しました: http://localhost:${PORT}`);
19 | });
20 |
21 | // 基本的な非同期処理の例
22 | setTimeout(() => {
23 | console.log('3秒経過しました');
24 | }, 3000);
25 |
26 | // 配列操作の例
27 | const numbers = [1, 2, 3, 4, 5];
28 | const doubled = numbers.map(num => num * 2);
29 | console.log('倍にした数:', doubled);
30 |
--------------------------------------------------------------------------------
/example/nodejs/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "nodejs-example",
3 | "version": "1.0.0",
4 | "description": "Node.js実行サンプル",
5 | "main": "app.js",
6 | "scripts": {
7 | "start": "node app.js",
8 | "test": "echo \"Error: no test specified\" && exit 1"
9 | },
10 | "keywords": [],
11 | "author": "",
12 | "license": "ISC"
13 | }
14 |
--------------------------------------------------------------------------------
/example/python/README.md:
--------------------------------------------------------------------------------
1 |
2 |

3 |
4 |
5 | # Python実行サンプル
6 |
7 | このディレクトリには、Pythonの実行に関するサンプルが含まれています。
8 |
9 | ## 基本的な実行コマンド
10 |
11 | ```bash
12 | # Pythonスクリプトの実行
13 | python script.py
14 | python3 script.py # Python3を明示的に指定
15 |
16 | # モジュールとして実行
17 | python -m module_name
18 |
19 | # 対話型シェル
20 | python
21 | python3
22 | ```
23 |
24 | ## パッケージ管理(pip)
25 |
26 | ```bash
27 | # パッケージのインストール
28 | pip install package_name
29 | pip3 install package_name
30 |
31 | # 特定のバージョンをインストール
32 | pip install package_name==1.0.0
33 |
34 | # requirements.txtからインストール
35 | pip install -r requirements.txt
36 |
37 | # パッケージの一覧表示
38 | pip list
39 |
40 | # パッケージ情報の表示
41 | pip show package_name
42 |
43 | # パッケージのアップグレード
44 | pip install --upgrade package_name
45 |
46 | # パッケージのアンインストール
47 | pip uninstall package_name
48 | ```
49 |
50 | ## 仮想環境の管理
51 |
52 | ```bash
53 | # venv環境の作成
54 | python -m venv myenv
55 |
56 | # 仮想環境の有効化
57 | # Windows
58 | myenv\Scripts\activate
59 | # Unix系
60 | source myenv/bin/activate
61 |
62 | # 仮想環境の無効化
63 | deactivate
64 | ```
65 |
66 | ## その他の有用なコマンド
67 |
68 | ```bash
69 | # Pythonのバージョン確認
70 | python --version
71 | python3 --version
72 |
73 | # コードの構文チェック
74 | python -m py_compile script.py
75 |
76 | # 単体テストの実行
77 | python -m unittest test_script.py
78 |
79 | # コードフォーマット
80 | python -m black script.py
81 |
82 | # 型チェック(mypy使用時)
83 | python -m mypy script.py
84 | ```
85 |
86 | ## サンプルスクリプト
87 |
88 | [hello.py](./hello.py)には、基本的な関数定義と実行例が含まれています。
89 |
--------------------------------------------------------------------------------
/example/python/hello.py:
--------------------------------------------------------------------------------
1 | def greet(name="World"):
2 | """シンプルな挨拶を返す関数"""
3 | return f"Hello, {name}!"
4 |
5 | def calculate_sum(numbers):
6 | """数値のリストの合計を計算する関数"""
7 | return sum(numbers)
8 |
9 | if __name__ == "__main__":
10 | # 基本的な挨拶
11 | print(greet())
12 | print(greet("Python"))
13 |
14 | # リストの合計計算
15 | numbers = [1, 2, 3, 4, 5]
16 | total = calculate_sum(numbers)
17 | print(f"合計: {total}")
18 |
--------------------------------------------------------------------------------
/example/terraform/README.md:
--------------------------------------------------------------------------------
1 |
2 |

3 |
4 |
5 | # Terraform実行サンプル
6 |
7 | このディレクトリには、Terraformの基本的なコマンドの使用例が含まれています。
8 |
9 | ## 初期化と設定
10 |
11 | ```bash
12 | # プロジェクトの初期化
13 | terraform init
14 |
15 | # プロバイダーのアップグレード
16 | terraform init -upgrade
17 |
18 | # 作業ディレクトリの初期化(バックエンド設定含む)
19 | terraform init -backend-config="backend.hcl"
20 | ```
21 |
22 | ## 計画と適用
23 |
24 | ```bash
25 | # 実行計画の表示
26 | terraform plan
27 |
28 | # 特定の変数を指定して実行計画を表示
29 | terraform plan -var="instance_count=2"
30 |
31 | # 変数ファイルを使用
32 | terraform plan -var-file="prod.tfvars"
33 |
34 | # インフラストラクチャの作成/更新
35 | terraform apply
36 |
37 | # 自動承認でのインフラストラクチャ作成/更新
38 | terraform apply -auto-approve
39 | ```
40 |
41 | ## 状態管理
42 |
43 | ```bash
44 | # 現在の状態を表示
45 | terraform show
46 |
47 | # 状態ファイルの一覧表示
48 | terraform state list
49 |
50 | # 特定のリソースの状態を表示
51 | terraform state show aws_instance.example
52 |
53 | # リソースの状態を削除
54 | terraform state rm aws_instance.example
55 |
56 | # 状態のインポート
57 | terraform import aws_instance.example i-1234567890abcdef0
58 | ```
59 |
60 | ## 破棄と削除
61 |
62 | ```bash
63 | # リソースの削除計画を表示
64 | terraform plan -destroy
65 |
66 | # リソースの削除
67 | terraform destroy
68 |
69 | # 自動承認での削除
70 | terraform destroy -auto-approve
71 | ```
72 |
73 | ## ワークスペース管理
74 |
75 | ```bash
76 | # ワークスペース一覧の表示
77 | terraform workspace list
78 |
79 | # 新しいワークスペースの作成
80 | terraform workspace new dev
81 |
82 | # ワークスペースの切り替え
83 | terraform workspace select prod
84 |
85 | # 現在のワークスペースを表示
86 | terraform workspace show
87 | ```
88 |
89 | ## フォーマットとバリデーション
90 |
91 | ```bash
92 | # コードのフォーマット
93 | terraform fmt
94 |
95 | # 設定の検証
96 | terraform validate
97 | ```
98 |
99 | ## その他の有用なコマンド
100 |
101 | ```bash
102 | # プロバイダーとモジュールのアップグレード
103 | terraform get -update
104 |
105 | # 出力値の表示
106 | terraform output
107 |
108 | # 特定の出力値の表示
109 | terraform output instance_ip
110 |
111 | # バージョン情報の表示
112 | terraform version
113 | ```
114 |
115 | ## サンプルファイル
116 |
117 | [main.tf](./main.tf)には、基本的なAWSリソース(VPC、サブネット、EC2インスタンス)の設定例が含まれています。
118 |
--------------------------------------------------------------------------------
/example/terraform/main.tf:
--------------------------------------------------------------------------------
1 | # AWSプロバイダーの設定
2 | provider "aws" {
3 | region = "ap-northeast-1" # 東京リージョン
4 | }
5 |
6 | # 変数の定義
7 | variable "instance_type" {
8 | description = "EC2インスタンスタイプ"
9 | type = string
10 | default = "t2.micro"
11 | }
12 |
13 | # VPCの作成
14 | resource "aws_vpc" "main" {
15 | cidr_block = "10.0.0.0/16"
16 | enable_dns_hostnames = true
17 | enable_dns_support = true
18 |
19 | tags = {
20 | Name = "example-vpc"
21 | }
22 | }
23 |
24 | # パブリックサブネットの作成
25 | resource "aws_subnet" "public" {
26 | vpc_id = aws_vpc.main.id
27 | cidr_block = "10.0.1.0/24"
28 | availability_zone = "ap-northeast-1a"
29 |
30 | tags = {
31 | Name = "example-public-subnet"
32 | }
33 | }
34 |
35 | # EC2インスタンスの作成
36 | resource "aws_instance" "example" {
37 | ami = "ami-0d979355d03fa2522" # Amazon Linux 2 AMI
38 | instance_type = var.instance_type
39 | subnet_id = aws_subnet.public.id
40 |
41 | tags = {
42 | Name = "example-instance"
43 | }
44 | }
45 |
46 | # 出力の定義
47 | output "instance_id" {
48 | description = "作成されたEC2インスタンスのID"
49 | value = aws_instance.example.id
50 | }
51 |
52 | output "public_ip" {
53 | description = "EC2インスタンスのパブリックIP"
54 | value = aws_instance.example.public_ip
55 | }
56 |
--------------------------------------------------------------------------------
/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "command-executor",
3 | "version": "0.1.0",
4 | "lockfileVersion": 3,
5 | "requires": true,
6 | "packages": {
7 | "": {
8 | "name": "command-executor",
9 | "version": "0.1.0",
10 | "dependencies": {
11 | "@modelcontextprotocol/sdk": "0.6.0"
12 | },
13 | "bin": {
14 | "command-executor": "build/index.js"
15 | },
16 | "devDependencies": {
17 | "@types/node": "^20.11.24",
18 | "typescript": "^5.3.3"
19 | }
20 | },
21 | "node_modules/@modelcontextprotocol/sdk": {
22 | "version": "0.6.0",
23 | "resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-0.6.0.tgz",
24 | "integrity": "sha512-9rsDudGhDtMbvxohPoMMyAUOmEzQsOK+XFchh6gZGqo8sx9sBuZQs+CUttXqa8RZXKDaJRCN2tUtgGof7jRkkw==",
25 | "license": "MIT",
26 | "dependencies": {
27 | "content-type": "^1.0.5",
28 | "raw-body": "^3.0.0",
29 | "zod": "^3.23.8"
30 | }
31 | },
32 | "node_modules/@types/node": {
33 | "version": "20.17.10",
34 | "resolved": "https://registry.npmjs.org/@types/node/-/node-20.17.10.tgz",
35 | "integrity": "sha512-/jrvh5h6NXhEauFFexRin69nA0uHJ5gwk4iDivp/DeoEua3uwCUto6PC86IpRITBOs4+6i2I56K5x5b6WYGXHA==",
36 | "dev": true,
37 | "license": "MIT",
38 | "dependencies": {
39 | "undici-types": "~6.19.2"
40 | }
41 | },
42 | "node_modules/bytes": {
43 | "version": "3.1.2",
44 | "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz",
45 | "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==",
46 | "license": "MIT",
47 | "engines": {
48 | "node": ">= 0.8"
49 | }
50 | },
51 | "node_modules/content-type": {
52 | "version": "1.0.5",
53 | "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz",
54 | "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==",
55 | "license": "MIT",
56 | "engines": {
57 | "node": ">= 0.6"
58 | }
59 | },
60 | "node_modules/depd": {
61 | "version": "2.0.0",
62 | "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz",
63 | "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==",
64 | "license": "MIT",
65 | "engines": {
66 | "node": ">= 0.8"
67 | }
68 | },
69 | "node_modules/http-errors": {
70 | "version": "2.0.0",
71 | "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz",
72 | "integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==",
73 | "license": "MIT",
74 | "dependencies": {
75 | "depd": "2.0.0",
76 | "inherits": "2.0.4",
77 | "setprototypeof": "1.2.0",
78 | "statuses": "2.0.1",
79 | "toidentifier": "1.0.1"
80 | },
81 | "engines": {
82 | "node": ">= 0.8"
83 | }
84 | },
85 | "node_modules/iconv-lite": {
86 | "version": "0.6.3",
87 | "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz",
88 | "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==",
89 | "license": "MIT",
90 | "dependencies": {
91 | "safer-buffer": ">= 2.1.2 < 3.0.0"
92 | },
93 | "engines": {
94 | "node": ">=0.10.0"
95 | }
96 | },
97 | "node_modules/inherits": {
98 | "version": "2.0.4",
99 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
100 | "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
101 | "license": "ISC"
102 | },
103 | "node_modules/raw-body": {
104 | "version": "3.0.0",
105 | "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-3.0.0.tgz",
106 | "integrity": "sha512-RmkhL8CAyCRPXCE28MMH0z2PNWQBNk2Q09ZdxM9IOOXwxwZbN+qbWaatPkdkWIKL2ZVDImrN/pK5HTRz2PcS4g==",
107 | "license": "MIT",
108 | "dependencies": {
109 | "bytes": "3.1.2",
110 | "http-errors": "2.0.0",
111 | "iconv-lite": "0.6.3",
112 | "unpipe": "1.0.0"
113 | },
114 | "engines": {
115 | "node": ">= 0.8"
116 | }
117 | },
118 | "node_modules/safer-buffer": {
119 | "version": "2.1.2",
120 | "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
121 | "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
122 | "license": "MIT"
123 | },
124 | "node_modules/setprototypeof": {
125 | "version": "1.2.0",
126 | "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
127 | "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==",
128 | "license": "ISC"
129 | },
130 | "node_modules/statuses": {
131 | "version": "2.0.1",
132 | "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz",
133 | "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==",
134 | "license": "MIT",
135 | "engines": {
136 | "node": ">= 0.8"
137 | }
138 | },
139 | "node_modules/toidentifier": {
140 | "version": "1.0.1",
141 | "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz",
142 | "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==",
143 | "license": "MIT",
144 | "engines": {
145 | "node": ">=0.6"
146 | }
147 | },
148 | "node_modules/typescript": {
149 | "version": "5.7.2",
150 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.2.tgz",
151 | "integrity": "sha512-i5t66RHxDvVN40HfDd1PsEThGNnlMCMT3jMUuoh9/0TaqWevNontacunWyN02LA9/fIbEWlcHZcgTKb9QoaLfg==",
152 | "dev": true,
153 | "license": "Apache-2.0",
154 | "bin": {
155 | "tsc": "bin/tsc",
156 | "tsserver": "bin/tsserver"
157 | },
158 | "engines": {
159 | "node": ">=14.17"
160 | }
161 | },
162 | "node_modules/undici-types": {
163 | "version": "6.19.8",
164 | "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz",
165 | "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==",
166 | "dev": true,
167 | "license": "MIT"
168 | },
169 | "node_modules/unpipe": {
170 | "version": "1.0.0",
171 | "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
172 | "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==",
173 | "license": "MIT",
174 | "engines": {
175 | "node": ">= 0.8"
176 | }
177 | },
178 | "node_modules/zod": {
179 | "version": "3.24.1",
180 | "resolved": "https://registry.npmjs.org/zod/-/zod-3.24.1.tgz",
181 | "integrity": "sha512-muH7gBL9sI1nciMZV67X5fTKKBLtwpZ5VBp1vsOQzj1MhrBZ4wlVCm3gedKZWLp0Oyel8sIGfeiz54Su+OVT+A==",
182 | "license": "MIT",
183 | "funding": {
184 | "url": "https://github.com/sponsors/colinhacks"
185 | }
186 | }
187 | }
188 | }
189 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "command-executor",
3 | "version": "0.1.0",
4 | "description": "A Model Context Protocol server for executing pre-approved commands",
5 | "private": true,
6 | "type": "module",
7 | "bin": {
8 | "command-executor": "./build/index.js"
9 | },
10 | "files": [
11 | "build"
12 | ],
13 | "scripts": {
14 | "build": "tsc && node -e \"require('fs').chmodSync('build/index.js', '755')\"",
15 | "prepare": "npm run build",
16 | "watch": "tsc --watch",
17 | "inspector": "npx @modelcontextprotocol/inspector build/index.js"
18 | },
19 | "dependencies": {
20 | "@modelcontextprotocol/sdk": "0.6.0"
21 | },
22 | "devDependencies": {
23 | "@types/node": "^20.11.24",
24 | "typescript": "^5.3.3"
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/index.ts:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | import { Server } from '@modelcontextprotocol/sdk/server/index.js';
3 | import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4 | import {
5 | CallToolRequestSchema,
6 | ErrorCode,
7 | ListToolsRequestSchema,
8 | McpError,
9 | } from '@modelcontextprotocol/sdk/types.js';
10 | import { exec } from 'child_process';
11 | import { promisify } from 'util';
12 |
13 | const execAsync = promisify(exec);
14 |
15 | // 許可されたコマンドのプレフィックスリスト(環境変数から取得、デフォルト値を設定)
16 | const DEFAULT_ALLOWED_COMMANDS = [
17 | 'git',
18 | 'ls',
19 | 'mkdir',
20 | 'cd',
21 | 'npm',
22 | 'npx',
23 | 'python'
24 | ];
25 |
26 | const getAllowedCommands = (): string[] => {
27 | const envCommands = process.env.ALLOWED_COMMANDS;
28 | if (!envCommands) {
29 | return DEFAULT_ALLOWED_COMMANDS;
30 | }
31 | return envCommands.split(',').map(cmd => cmd.trim());
32 | };
33 |
34 | class CommandExecutorServer {
35 | private server: Server;
36 | private allowedCommands: string[];
37 |
38 | constructor() {
39 | this.allowedCommands = getAllowedCommands();
40 |
41 | this.server = new Server(
42 | {
43 | name: 'command-executor',
44 | version: '0.1.0',
45 | },
46 | {
47 | capabilities: {
48 | tools: {},
49 | },
50 | }
51 | );
52 |
53 | this.setupToolHandlers();
54 |
55 | // エラーハンドリング
56 | this.server.onerror = (error) => console.error('[MCP Error]', error);
57 | process.on('SIGINT', async () => {
58 | await this.server.close();
59 | process.exit(0);
60 | });
61 | }
62 |
63 | private isCommandAllowed(command: string): boolean {
64 | // コマンドの最初の部分(スペース区切りの最初の単語)を取得
65 | const commandPrefix = command.split(' ')[0];
66 | return this.allowedCommands.some(allowed => commandPrefix === allowed);
67 | }
68 |
69 | private setupToolHandlers() {
70 | this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
71 | tools: [
72 | {
73 | name: 'execute_command',
74 | description: '事前に許可されたコマンドを実行します',
75 | inputSchema: {
76 | type: 'object',
77 | properties: {
78 | command: {
79 | type: 'string',
80 | description: '実行するコマンド',
81 | },
82 | },
83 | required: ['command'],
84 | },
85 | },
86 | ],
87 | }));
88 |
89 | this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
90 | if (request.params.name !== 'execute_command') {
91 | throw new McpError(
92 | ErrorCode.MethodNotFound,
93 | `Unknown tool: ${request.params.name}`
94 | );
95 | }
96 |
97 | const { command } = request.params.arguments as { command: string };
98 |
99 | // コマンドが許可されているか確認
100 | if (!this.isCommandAllowed(command)) {
101 | throw new McpError(
102 | ErrorCode.InvalidParams,
103 | `Command not allowed: ${command}. Allowed commands: ${this.allowedCommands.join(', ')}`
104 | );
105 | }
106 |
107 | try {
108 | const { stdout, stderr } = await execAsync(command);
109 | return {
110 | content: [
111 | {
112 | type: 'text',
113 | text: stdout || stderr,
114 | },
115 | ],
116 | };
117 | } catch (error: any) {
118 | return {
119 | content: [
120 | {
121 | type: 'text',
122 | text: `Command execution failed: ${error.message}`,
123 | },
124 | ],
125 | isError: true,
126 | };
127 | }
128 | });
129 | }
130 |
131 | async run() {
132 | const transport = new StdioServerTransport();
133 | await this.server.connect(transport);
134 | console.error('Command Executor MCP server running on stdio');
135 | console.error('Allowed commands:', this.allowedCommands.join(', '));
136 | }
137 | }
138 |
139 | const server = new CommandExecutorServer();
140 | server.run().catch(console.error);
141 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "ES2022",
4 | "module": "Node16",
5 | "moduleResolution": "Node16",
6 | "outDir": "./build",
7 | "rootDir": "./src",
8 | "strict": true,
9 | "esModuleInterop": true,
10 | "skipLibCheck": true,
11 | "forceConsistentCasingInFileNames": true
12 | },
13 | "include": ["src/**/*"],
14 | "exclude": ["node_modules"]
15 | }
16 |
--------------------------------------------------------------------------------