Claude CodeのSlash commandsはMCPで配信しよう!

Claude CodeのSlash commandsはMCPで配信しよう!

MCPのPromptsは使えない子ではありません!!!!
2025.08.11

はじめに

小ネタです。Claude CodeのSlash commandsはMCPのPromptsで配信できます。今回はローカルMCPで試しますが、リモートMCPにすればローカル側で更新不要なのでエンドユーザーの更新負荷がなくなります。

配信しているMCPのtoolと組み合わせて使って欲しいプロンプトがある場合などとても相性が良いと思います。

やってみる

今回はConventional Commitタイプを引数で受け取り、対応した絵文字をつけてメッセージを生成するMCPプロンプトサーバー(例: /commit feat → feat: ✨ 新機能)を作ります。Conventional Commitタイプは生成AIだと難しいケースがあるので、人間が指定し、コミットメッセージはAIが作った方が上手いので人間とAIのそれぞれ得意なところを組み合わせたスラッシュコマンドです。

実装は以下の通りです。

https://github.com/shuntaka9576/slash-command-mcp-example/blob/5181ed5fffcc95be831d14320cc08917fe736d2a/src/index.ts#L1-L72

https://github.com/shuntaka9576/slash-command-mcp-example/blob/5181ed5fffcc95be831d14320cc08917fe736d2a/src/prompts/commit.ts#L1-L72

prompts/list を stdin から流してリストが返却されることを確認します。

$  echo '{"jsonrpc":"2.0","id":1,"method":"prompts/list","params":{}}' | node --experimental-strip-types src/index.ts
MCP server started
{"result":{"prompts":[{"name":"commit","description":"Conventional Commitタイプからコミットメッセージを生成","arguments":[{"name":"type","description":"Conventional Commitタイプ (feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert)","required":true},{"name":"description","description":"コミットの詳細説明","required":false}]}]},"jsonrpc":"2.0","id":1}

Claude Code側の設定を行います。MCPサーバー名(jsonのmcpServers配下のkey)がClaude CodeのSlash Command名のprefixになります。

{
   "mcpServers": {
      "slash-command-mcp-example": {
         "args": [
            "--experimental-strip-types",
            "/Users/shuntaka/repos/github.com/shuntaka9576/slash-command-mcp-example/src/index.ts"
         ],
         "command": "node"
      }
   }
}

/slash-command-mcp-example:commit (MCP) が確認できます。

CleanShot 2025-08-11 at 05.14.46@2x

/(MCPサーバー名):(プロンプト名) の形式になっています。

(MCPサーバー名)はMCP設定のKeyから

{
   "mcpServers": {
+      "slash-command-mcp-example": {
         "args": [
            "--experimental-strip-types",
            "/Users/shuntaka/repos/github.com/shuntaka9576/slash-command-mcp-example/src/index.ts"
         ],
         "command": "node"
      }
   }
}

(プロンプト名)prompts/list のnameから取得しています。

https://github.com/shuntaka9576/slash-command-mcp-example/blob/5181ed5fffcc95be831d14320cc08917fe736d2a/src/index.ts#L24-L42

使ってみます。

CleanShot 2025-08-11 at 05.25.37@2x

Conventional commitのprefixから、コミットメッセージを生成して絵文字付きでコミットされていますね!

さいごに

こういう取り組みをしているので、マイMCPを育てる機運になりました。

この記事をシェアする

facebookのロゴhatenaのロゴtwitterのロゴ

© Classmethod, Inc. All rights reserved.