Hermes Agent: MCPプロトコル

最終更新:2026-08-31

MCPはAIツール相互接続のUSBインターフェースです。Model Context Protocolにより、Hermes AgentはMCP互換のあらゆるツールサーバーを発見・呼び出しでき、能力の境界を無限に拡張できます。

💡 ヒント: MCP(Model Context Protocol)はAnthropicが提唱したオープンプロトコルで、AIアプリとツールサーバーの標準化された相互接続を定義します。HermesはネイティブでMCPをサポートし、任意のMCPサーバーに接続できます。

📋 前提知識: 第8課 ツールとツールセット、第15課 プラグイン

1. 学ぶ内容

# 内容
MCPプロトコルの概念と原理
HermesのMCP統合
MCPサーバー設定
ツール発見と呼び出し
カスタムMCPサーバー開発

2. ストーリー

(1) 課題:AIツールごとにインターフェースが違う

Bobは5つのAIツールを使っているが、それぞれに独自のAPIフォーマット、認証方式、ツール定義がある。新しいツールを接続するたびに適合レイヤーを再開発しなければならない。

(2) 解決策:MCP統一プロトコル、プラグアンドプレイ

AliceはMCPでHermesに各種ツールサーバーを接続:

BASH
# 1行設定でMCPサーバーに接続
hermes mcp add filesystem --command "npx @anthropic/mcp-filesystem /home/alice"
hermes mcp add github --command "npx @anthropic/mcp-github"

# Hermesが利用可能な全ツールを自動発見
hermes mcp tools
# 15個の新ツールを発見:read_file, write_file, search_files, create_issue...

3. MCPプロトコルの概念

(1) MCPとは?

MCP(Model Context Protocol)はオープンプロトコルで、AIアプリ(クライアント)とツールサーバー間の通信標準を定義します:

100%
graph LR
    A[Hermes Agent<br/>MCP Client] -->|標準プロトコル| B[MCP Server 1<br/>Filesystem]
    A -->|標準プロトコル| C[MCP Server 2<br/>GitHub]
    A -->|標準プロトコル| D[MCP Server 3<br/>Database]
    A -->|標準プロトコル| E[MCP Server N<br/>Custom]

(2) MCPのコア概念

概念 説明 例え
MCP Client リクエストを発行するAIアプリ USBホスト
MCP Server ツールを提供するサーバー USBデバイス
Tool Serverが提供する具体的な操作 デバイス機能
Resource Serverが提供するデータソース デバイスストレージ
Prompt Serverが提供するプロンプトテンプレート デバイスプリセット

(3) MCP vs 従来のAPI

次元 従来のAPI MCP
インターフェースフォーマット それぞれ独自定義 統一標準
ツール発見 手動ドキュメント 自動発見
認証方式 それぞれ独自実装 統一スキーム
接続方式 HTTP/SDK stdio/SSE
エコシステム 孤立 相互接続

4. HermesのMCP統合

(1) MCPの設定

YAML
# ~/.hermes/config.yaml
mcp:
  enabled: true
  
  # MCPサーバーリスト
  servers:
    filesystem:
      command: "npx"
      args: ["@anthropic/mcp-filesystem", "/home/alice/projects"]
      
    github:
      command: "npx"
      args: ["@anthropic/mcp-github"]
      env:
        GITHUB_TOKEN: "${GITHUB_TOKEN}"
        
    database:
      command: "python"
      args: ["-m", "mcp_server_postgres"]
      env:
        DATABASE_URL: "${DATABASE_URL}"
        
    brave-search:
      command: "npx"
      args: ["@anthropic/mcp-brave-search"]
      env:
        BRAVE_API_KEY: "${BRAVE_API_KEY}"

(2) 接続管理

BASH
# MCPサーバーの追加
hermes mcp add filesystem --command "npx @anthropic/mcp-filesystem /home/alice"

# 設定済みサーバー一覧
hermes mcp list

# 接続テスト
hermes mcp test filesystem

# サーバーが提供するツールの確認
hermes mcp tools filesystem

# サーバーの削除
hermes mcp remove filesystem

5. ツール発見と呼び出し

(1) 自動発見

HermesはMCPサーバーに接続後、利用可能な全ツールを自動発見:

BASH
hermes mcp tools

# 出力例:
# ┌─────────────────────┬──────────────┬────────────────────────┐
# │ Tool                │ Server       │ Description            │
# ├─────────────────────┼──────────────┼────────────────────────┤
# │ read_file           │ filesystem   │ Read file contents     │
# │ write_file          │ filesystem   │ Write to file          │
# │ search_files        │ filesystem   │ Search in files        │
# │ create_issue        │ github       │ Create GitHub issue    │
# │ list_prs            │ github       │ List pull requests     │
# │ query               │ database     │ Execute SQL query      │
# │ search              │ brave-search │ Web search             │
# └─────────────────────┴──────────────┴────────────────────────┘

(2) 会話での使用

BASH
me: README.mdの内容を読み込んで
Agent: [MCP: filesystem/read_file]
       # My Project...

me: GitHubにIssueを作成して
Agent: [MCP: github/create_issue]
       タイトル?→ "Bug: Login fails on mobile"
       ✅ Issue #42を作成しました

me: 最新のAIニュースを検索して
Agent: [MCP: brave-search/search]
       5件の結果を発見...

(3) ツールルーティング

複数のMCPサーバーが類似ツールを提供する場合、Hermesは自動的にルーティング:

YAML
mcp:
  routing:
    # MCPツールを優先使用
    prefer_mcp: true
    
    # 同名ツールの優先度
    priority:
      filesystem.read_file: 100     # MCP版を優先
      fs_read: 50                   # 組み込み版は次点
      
    # 競合解決
    conflict_resolution: "priority"  # priority / server_order / ask_user

6. カスタムMCPサーバー開発

(1) Python MCPサーバー

PYTHON
# mcp_server_custom.py
from mcp.server import Server, Tool

server = Server("custom-tools")

@server.tool("get_weather")
async def get_weather(city: str) -> dict:
    """Get current weather for a city"""
    # カスタムロジック
    import httpx
    response = httpx.get(f"https://api.weather.com/{city}")
    return response.json()

@server.tool("send_notification")
async def send_notification(message: str, channel: str = "default") -> dict:
    """Send a notification to a channel"""
    # カスタム通知ロジック
    return {"status": "sent", "channel": channel}

if __name__ == "__main__":
    server.run()

(2) TypeScript MCPサーバー

TYPESCRIPT
// mcp-server-custom.ts
import { Server, Tool } from "@anthropic/mcp";

const server = new Server("custom-tools");

server.tool("query_database", {
  description: "Query the database",
  parameters: {
    sql: { type: "string", required: true },
    limit: { type: "number", default: 100 }
  },
  async execute({ sql, limit }) {
    // カスタムデータベースクエリ
    const results = await db.query(sql, { limit });
    return { rows: results };
  }
});

server.run();

(3) カスタムサーバーの登録

BASH
# カスタムMCPサーバーの登録
hermes mcp add custom-tools \
  --command "python mcp_server_custom.py" \
  --working-dir /path/to/server

# またはconfig.yamlに設定
YAML
mcp:
  servers:
    custom-tools:
      command: "python"
      args: ["mcp_server_custom.py"]
      working_dir: "/path/to/server"
      env:
        API_KEY: "${CUSTOM_API_KEY}"

7. MCPエコシステム

(1) 公式MCPサーバー

サーバー 機能 インストール
filesystem ファイルシステム操作 npx @anthropic/mcp-filesystem
github GitHub操作 npx @anthropic/mcp-github
gitlab GitLab操作 npx @anthropic/mcp-gitlab
postgres PostgreSQLクエリ npx @anthropic/mcp-postgres
sqlite SQLite操作 npx @anthropic/mcp-sqlite
brave-search Web検索 npx @anthropic/mcp-brave-search
google-drive Google Drive npx @anthropic/mcp-google-drive
slack Slack操作 npx @anthropic/mcp-slack

(2) コミュニティMCPサーバー

コミュニティが100以上のMCPサーバーを保守しており、以下をカバー:


❓ よくある質問

Q MCPとプラグインの違いは?
A プラグインはHermes専用拡張で深く統合。MCPはオープンプロトコルで、どんなAIアプリでも使える。MCPはより汎用的、プラグインはより深い統合。
Q MCPサーバーはパフォーマンスに影響しますか?
A MCPサーバーは独立プロセスで、アイドル時はゼロ消費。呼び出し時はstdio/SSEで通信し、レイテンシは通常50ms未満。
Q 同時にいくつのMCPサーバーに接続できますか?
A ハードリミットなし。実際5-10サーバーの同時使用で全く問題なし。各サーバーは独立プロセス。
Q MCP通信は安全ですか?
A stdioモードでは通信は完全ローカル。SSEモードはTLSをサポート。認証は環境変数で渡され、プロトコルに露出しません。
Q MCP接続問題のデバッグ方法は?
A hermes mcp test <server>で接続テスト、--debugで通信詳細を確認。
Q MCPはストリーミングレスポンスに対応していますか?
A はい。SSEモードでストリーミング返信をサポートし、長時間実行ツールに適しています。

📖 まとめ


📝 練習問題

  1. 基本(⭐): MCPサーバー(例:filesystem)を1つ設定し、ツール発見と呼び出しを確認してください。
  2. 中級(⭐⭐): 3つのMCPサーバーを同時に設定し、会話で異なるサーバーのツールを使用してください。
  3. 上級(⭐⭐⭐): カスタムMCPサーバーを開発し、よく使うAPIをラップし、Hermesに登録して完全なワークフローを確認してください。
Web-Tutorial.com

Web-Tutorial 技術チーム

複数の開発者によって共同維持されているプログラミングチュートリアルプラットフォーム。各チュートリアルは専門分野の開発者が執筆・レビューしています。正確で信頼性の高いコンテンツを目指しています — 問題を見つけた場合はお知らせください。

100%