Storacha MCP ストレージサーバー
Storacha ストレージ用のモデル コンテキスト プロトコル (MCP) サーバー実装。これにより、AI アプリケーションは標準化されたインターフェースを介して分散ストレージと対話できるようになります。
特徴
- ファイル操作
- Storachaの分散型ストレージネットワークにファイルをアップロードする
- Storacha の HTTP ゲートウェイ経由でファイルを取得する
- アイデンティティ管理
- StorachaエージェントのDIDキーを取得する
- デュアルトランスポートモード
- リアルタイム通信のためのサーバー送信イベント(SSE)を備えたHTTP
- ローカル統合のためのstdioトランスポート
- 標準化されたインターフェース
- ツールの検出と呼び出しのためのMCP準拠API
- JSON-RPC メッセージ処理
- 安全
- 無記名トークン
- CORS設定
- 入力検証
- 安全なエラー処理
米国の事例
- ドキュメントの保存と分析: Blob ドキュメントを安全にアップロードおよび取得します。
- 長期構造化データ ストレージ: 長期性とアクセス性を考慮して最適化された構造化データ ストレージを維持します。
- エージェントとシステム間のデータ共有: **CID (コンテンツ識別子)**を使用して、複数のエージェントとさまざまなシステム間でデータを簡単に共有し、分散型で検証可能かつ効率的なデータ交換を可能にします。
- アプリケーション統合: モデル コンテキスト プロトコルを介して、Storacha ストレージ取得をアプリケーションにシームレスに統合します。
- AI モデル開発: Storacha に保存されている外部データセットへの信頼性の高いアクセスを提供することで、AI モデルをサポートします。
- LLM 統合: Storacha ストレージに直接接続してシームレスなデータ アクセスを実現し、大規模言語モデル (LLM) を強化します。
- Web アプリケーションのバックアップ: 災害復旧のために Web アプリケーションのバックアップ コピーを確実に保存します。
- 機械学習データセット: 機械学習ワークフローで使用される大規模なデータセットを効率的に管理およびアクセスします。
インストール
- リポジトリをクローンする
git clone https://github.com/storacha/mcp-storage-server.git
cd mcp-storage-server
- 依存関係をインストールする
.env
ファイルを作成する- 次の環境変数を使用してサーバーを設定します
# MCP Server Configuration
MCP_SERVER_PORT=3001 # Optional: The port the server will listen on (default: 3001)
MCP_SERVER_HOST=0.0.0.0 # Optional: The host address to bind to (default: 0.0.0.0)
MCP_CONNECTION_TIMEOUT=30000 # Optional: The connection timeout in milliseconds (default: 30000)
MCP_TRANSPORT_MODE=stdio # Optional: The transport mode to use (stdio or sse) (default: stdio)
# Security
SHARED_ACCESS_TOKEN= # Optional: Set this to require authentication for uploads
# Storage Client Configuration
PRIVATE_KEY= # Required: The Storacha Agent private key that is authorized to upload files
DELEGATION= # Optional: The base64 encoded delegation that authorizes the Agent owner of the private key to upload files. If not set, MUST be provided for each upload request.
GATEWAY_URL=https://storacha.link # Optional: Custom gateway URL for file retrieval (default: https://storacha.link)
# File Limits
MAX_FILE_SIZE=104857600 # Optional: Maximum file size in bytes (default: 100MB)
サーバーの起動
オプション 1 - Stdio サーバーを実行する (ローカル サーバー通信に推奨)
オプション 2 - SSE サーバーを実行する (リモート サーバー通信に推奨)
MCP クライアント統合 (stdio モード)
MCPサーバーに接続する
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
// Create the transport for communication
const transport = new StdioClientTransport({
command: 'node',
args: ['dist/index.js'],
env: {
...loadEnvVars(),
MCP_TRANSPORT_MODE: 'stdio',
},
});
// Instantiate the MCP client
client = new Client(
{
name: 'test-client',
version: '1.0.0',
},
{
capabilities: {
tools: {},
},
}
);
// Connect to the server
await client.connect(transport);
リストツール
const response = await client.listTools();
console.log(response.tools.map(tool => tool.name));
// output: ['identity', 'retrieve', 'upload']
エージェントのDIDキーを取得する
// Get the agent's DID key
const response = await client.callTool({
name: 'identity',
arguments: {}, // Send an empty object
});
console.log('Agent DID:', JSON.parse(response.content[0].text));
// output: {"id":"did:key:z6MkjiNpY1QhuULQUkF5thrDbVz2fZwg49zYMg4a7zY1KDr9"}
ファイルをアップロードする
// Upload a file to the storage space defined in the delegation set in the MCP Server
const fileBuffer = new Uint8Array([1, 2, 3]);
const base64File = Buffer.from(fileBuffer).toString('base64');
const result = await client.invoke('upload', {
file: base64File,
name: 'example.txt',
type: 'text/plain',
});
// output: {"root":"bafk...123","rootURL":"https://storacha.link/ipfs/bafk...123","files":[{"name":"test.txt","type":"text/plain","url":"https://storacha.link/ipfs/bafk...123/test.txt"}]}
カスタム委任を使用してファイルをアップロードする
// Upload a file to the storage space defined in the delegation set in the upload request
const result = await client.invoke('upload', {
file: base64File,
name: 'example.txt',
type: 'text/plain',
delegation: base64Delegation,
});
CLI を使用して委任を作成する方法については、ステップバイステップ ガイドをお読みください。
MCP Inspectorによるテスト
MCP Inspectorは、MCPサーバーのテストとデバッグのためのビジュアルインターフェースを提供します。Storacha MCPサーバーをテストするには、以下の手順に従ってください。
- MCPインスペクターを起動する
- Storacha MCPサーバーを起動する
- サーバーに接続する
- ブラウザを開き、 http://localhost:5173/#toolsでインスペクタ UI にアクセスします。
- サーバーのURLを入力します(例:
http://localhost:3001
) - インスペクターは利用可能なツールを自動的に検出します
- アップロードと取得ツールをインターフェースから直接テストできます
デバッグのヒント
- サーバーログで接続の問題を確認してください
- 環境変数が正しく設定されていることを確認する
- Inspector の互換性のために、サーバーが SSE または Stdio モードで実行されていることを確認します。
発達
プロジェクト構造
/
├── src/
│ ├── core/
│ │ ├── server/
│ │ │ ├── index.ts # Main server entry point
│ │ │ ├── config.ts # Server configuration
│ │ │ ├── types.ts # TypeScript type definitions
│ │ │ ├── tools/ # MCP tools implementation
│ │ │ │ ├── index.ts # Tool registration
│ │ │ │ ├── upload.ts # Upload tool
│ │ │ │ ├── retrieve.ts # Retrieve tool
│ │ │ │ └── identity.ts # Identity tool
│ │ │ └── transports/ # Transport implementations
│ │ │ ├── sse.ts # SSE transport
│ │ │ └── stdio.ts # Stdio transport
│ │ └── storage/ # Storage client implementation
│ │ ├── client.ts # Storage client
│ │ ├── config.ts # Storage configuration
│ │ ├── types.ts # Storage types
│ │ └── utils.ts # Storage utilities
├── test/
│ ├── core/
│ │ ├── server/
│ │ │ ├── config.test.ts # Configuration tests
│ │ │ ├── index.test.ts # Server tests
│ │ │ ├── tools/ # Tool tests
│ │ │ └── transports/ # Transport tests
│ │ └── storage/ # Storage tests
│ ├── integration/ # Integration tests
│ └── setup.ts # Test setup
├── .env.example # Example environment variables
├── .eslintrc.json # ESLint configuration
├── .prettierrc # Prettier configuration
├── .husky/ # Git hooks
│ └── pre-commit # Pre-commit hook
├── package.json # Project dependencies and scripts
├── tsconfig.json # TypeScript configuration
└── README.md # Project documentation
建物
# Install dependencies
pnpm install
# Build the project
pnpm build
# Run tests
pnpm test
貢献
- リポジトリをフォークする
- 機能ブランチを作成します(
git checkout -b feature/amazing-feature
) - 変更をコミットします (
git commit -m 'Add some amazing feature'
) - ブランチにプッシュする (
git push origin feature/amazing-feature
) - プルリクエストを開く
ライセンス
MIT または Apache 2 ライセンス
サポート
サポートについては、 Storacha サポートにアクセスするか、このリポジトリで問題を開いてください。