Skip to content

MCP Server 仕様

Model Context Protocol (MCP) に準拠したサーバーインターフェースです。Claude Desktop やその他の MCP クライアントからナレッジベースにアクセスできます。

概要

mermaid
flowchart LR
    subgraph Clients["MCP クライアント"]
        CD["Claude Desktop"]
        CC["Claude Code"]
        Other["その他 MCP クライアント"]
    end

    subgraph Server["MCP Server (stdio)"]
        Tools["ツール定義"]
        Handler["リクエストハンドラー"]
    end

    subgraph Backend["バックエンド"]
        DB["SQLite + FTS5"]
        Claude["Claude API"]
    end

    CD -->|stdio| Server
    CC -->|stdio| Server
    Other -->|stdio| Server
    Handler --> DB
    Handler --> Claude

接続設定

Claude Desktop の設定ファイルに以下を追加:

json
{
  "mcpServers": {
    "x-knowledge": {
      "command": "npx",
      "args": ["tsx", "mcp/server.ts"],
      "cwd": "/path/to/xbookmark-skill"
    }
  }
}

ツール定義

ナレッジベースを検索します。FTS5 によるキーワード検索と、Claude による意味的な再ランキングを組み合わせます。

json
{
  "name": "search",
  "description": "X ブックマークのナレッジベースを検索する",
  "inputSchema": {
    "type": "object",
    "properties": {
      "query": {
        "type": "string",
        "description": "検索クエリ(自然言語またはキーワード)"
      },
      "filters": {
        "type": "object",
        "properties": {
          "category": { "type": "string", "description": "カテゴリスラッグ" },
          "dateFrom": { "type": "string", "description": "開始日 (ISO 8601)" },
          "dateTo": { "type": "string", "description": "終了日 (ISO 8601)" },
          "sentiment": { "type": "string", "enum": ["positive", "neutral", "negative"] },
          "action": { "type": "string", "enum": ["read_later", "try_tool", "reference", "share", "archive"] }
        }
      },
      "limit": {
        "type": "number",
        "description": "最大結果数(デフォルト: 10)"
      }
    },
    "required": ["query"]
  }
}

レスポンス例

json
{
  "results": [
    {
      "tweetId": "1234567890",
      "text": "RAGの実装パターンをまとめた...",
      "author": "@ai_researcher",
      "summary": "RAGアーキテクチャの5つの実装パターン解説",
      "tags": ["rag", "llm", "vector-db"],
      "category": "AI-Tools",
      "relevance": 0.95,
      "url": "https://x.com/ai_researcher/status/1234567890"
    }
  ],
  "totalMatches": 15
}

oss_report

指定されたリポジトリの OSS 検証レポートを取得します。既存レポートがない場合は新規検証を開始できます。

json
{
  "name": "oss_report",
  "description": "GitHub リポジトリの OSS 検証レポートを取得する",
  "inputSchema": {
    "type": "object",
    "properties": {
      "repo_url": {
        "type": "string",
        "description": "GitHub リポジトリURL (例: https://github.com/owner/repo)"
      },
      "verify_if_missing": {
        "type": "boolean",
        "description": "レポートがない場合に新規検証を実行するか(デフォルト: false)"
      }
    },
    "required": ["repo_url"]
  }
}

レスポンス例

json
{
  "repoUrl": "https://github.com/example/tool",
  "repoName": "tool",
  "stars": 1250,
  "license": "MIT",
  "language": "TypeScript",
  "securityScore": 78,
  "securityVerdict": "VERIFY",
  "buildResult": "BUILD_SUCCESS",
  "testResult": "TEST_PASS",
  "usageNotes": "高品質なTypeScriptライブラリ。CI/CDも整備されており、安全に使用可能。",
  "verifiedAt": "2025-01-15T10:00:00Z"
}

recommend

プロジェクトのコンテキストに基づいて、ナレッジベースからツールやリソースを推薦します。

json
{
  "name": "recommend",
  "description": "プロジェクトに適したツール・リソースを推薦する",
  "inputSchema": {
    "type": "object",
    "properties": {
      "project_context": {
        "type": "string",
        "description": "プロジェクトの説明・要件"
      },
      "tech_stack": {
        "type": "array",
        "items": { "type": "string" },
        "description": "使用中の技術スタック"
      },
      "needs": {
        "type": "array",
        "items": { "type": "string" },
        "description": "必要な機能・要件"
      }
    },
    "required": ["project_context"]
  }
}

レスポンス例

json
{
  "recommendations": [
    {
      "type": "tool",
      "name": "LangChain",
      "reason": "RAGパイプラインの構築に最適。複数のブックマークで推奨されている。",
      "source_bookmarks": ["1234567890", "9876543210"],
      "oss_verified": true,
      "security_score": 85
    },
    {
      "type": "article",
      "title": "RAGの実装パターン5選",
      "reason": "プロジェクトの要件に直接関連する実装ガイド",
      "source_bookmark": "1111111111"
    }
  ]
}

ask

ナレッジベースの内容に基づいて自然言語で質問に回答します。

json
{
  "name": "ask",
  "description": "ナレッジベースに基づいて質問に回答する",
  "inputSchema": {
    "type": "object",
    "properties": {
      "question": {
        "type": "string",
        "description": "質問(自然言語)"
      },
      "include_sources": {
        "type": "boolean",
        "description": "回答にソース(元ブックマーク)を含めるか(デフォルト: true)"
      }
    },
    "required": ["question"]
  }
}

レスポンス例

json
{
  "answer": "最近のトレンドとして、RAGとファインチューニングを組み合わせたハイブリッドアプローチが注目されています。特に...",
  "confidence": 0.88,
  "sources": [
    {
      "tweetId": "1234567890",
      "author": "@ai_researcher",
      "text": "RAGとfine-tuningの組み合わせが...",
      "url": "https://x.com/ai_researcher/status/1234567890"
    }
  ]
}

指定期間のトレンドをサマリーします。

json
{
  "name": "trends",
  "description": "指定期間のトレンドサマリーを生成する",
  "inputSchema": {
    "type": "object",
    "properties": {
      "period": {
        "type": "string",
        "enum": ["1d", "1w", "2w", "1m", "3m"],
        "description": "集計期間(デフォルト: 1w)"
      },
      "category": {
        "type": "string",
        "description": "特定カテゴリに限定(オプション)"
      }
    }
  }
}

レスポンス例

json
{
  "period": "1w",
  "dateRange": {
    "from": "2025-01-08",
    "to": "2025-01-15"
  },
  "summary": "今週はAIエージェント関連のブックマークが急増。特にMCPプロトコルとマルチエージェントアーキテクチャへの関心が高い。",
  "topTopics": [
    { "topic": "AIエージェント", "count": 15, "trend": "up" },
    { "topic": "MCP", "count": 8, "trend": "new" },
    { "topic": "RAG", "count": 7, "trend": "stable" }
  ],
  "notableBookmarks": [
    {
      "tweetId": "1234567890",
      "author": "@anthropic",
      "text": "MCP is now...",
      "reason": "最も多くのエンゲージメント"
    }
  ],
  "newTools": [
    { "name": "CrewAI", "mentions": 3 }
  ]
}

エラーハンドリング

MCP プロトコルに従ったエラーレスポンス:

json
{
  "error": {
    "code": -32602,
    "message": "Invalid params: query is required"
  }
}
コード意味
-32600Invalid Request
-32601Method not found
-32602Invalid params
-32603Internal error