金曜日, 6月 27, 2025
金曜日, 6月 27, 2025
- Advertisment -
ホームニューステックニュースAnthropicのDesktop Extensions (DXT)完全ガイド: ローカルAIアプリケーションの新時代

AnthropicのDesktop Extensions (DXT)完全ガイド: ローカルAIアプリケーションの新時代



2025年6月27日、AnthropicがClaude Desktop用の「Desktop Extensions (DXT)」を発表しました。これは、ローカルMCPサーバーを単一の .dxt ファイルにパッケージ化し、ワンクリックでインストールできるようにする画期的な仕組みです。

本記事では、DXTの技術的詳細から実装方法、そして日本企業での活用方法まで、開発者向けに徹底解説します。

📋 目次

  1. DXTとは何か
  2. 従来のMCPサーバー導入の課題
  3. DXTのアーキテクチャ
  4. クイックスタート
  5. 実装例:社内ツールのDXT化
  6. セキュリティと企業向け機能
  7. 公式サンプルの衝撃
  8. 今後の展望

Desktop Extensions (DXT) は、Model Context Protocol (MCP) サーバーとその依存関係を単一のパッケージにまとめる新しい配布フォーマットです。Chrome拡張機能のように、ユーザーはダブルクリックするだけでClaude Desktopに機能を追加できます。

主な特徴

  • 🎯 ワンクリックインストール: 技術的知識不要
  • 📦 自己完結型パッケージ: 全依存関係を内包
  • 🔐 セキュア: APIキーはOSキーチェーンで管理
  • 🔄 自動アップデート: 最新版を自動で取得
  • 🌍 オープン仕様: 他のAIアプリでも利用可能


これまでMCPサーバーをClaude Desktopで使うには、以下のような手順が必要でした:


brew install node  


git clone https://github.com/example/mcp-server


npm install


vi ~/Library/Application\ Support/Claude/claude_desktop_config.json
{
  "mcpServers": {
    "example-server": {
      "command": "node",
      "args": ["/absolute/path/to/server/index.js"],
      "env": {
        "API_KEY": "your-api-key-here"
      }
    }
  }
}

この方法には多くの問題がありました:

  • ❌ パスの設定ミスで動作しない
  • ❌ 依存関係の競合
  • ❌ アップデート時の再設定
  • ❌ チーム内での環境差異
  • ❌ セキュリティリスク(平文でのAPIキー保存)


DXTは、これらの問題を根本的に解決する設計になっています。

パッケージ構造

.dxt ファイルは実質的にZIPアーカイブで、以下の構造を持ちます:

example.dxt/
├── manifest.json       # 拡張機能のメタデータ
├── server/            # MCPサーバーのコード
│   ├── index.js
│   └── package.json
├── node_modules/      # 依存関係(バンドル済み)
└── resources/         # その他のリソース

manifest.json の構造

{
  "dxt_version": "0.0.1",
  "name": "社内DB検索ツール",
  "description": "自然言語で社内データベースを検索",
  "author": "Your Name",
  "version": "1.0.0",
  "license": "MIT",
  "permissions": ["read_clipboard", "network"],
  "server": {
    "type": "node",
    "entry_point": "server/index.js",
    "install_command": "npm install"
  },
  "user_config": {
    "database_url": {
      "type": "string",
      "description": "データベースのURL",
      "default": "localhost:5432"
    },
    "api_key": {
      "type": "string",
      "description": "APIキー",
      "sensitive": true
    }
  }
}

ランタイムの仕組み

Claude DesktopにはNode.jsランタイムが内蔵されており、DXT内のMCPサーバーを直接実行できます。これにより:

  • ユーザーはNode.jsをインストール不要
  • バージョンの不整合が発生しない
  • サンドボックス環境で安全に実行

1. CLIツールのインストール

npm install -g @anthropic-ai/dxt

2. 新規プロジェクトの作成

対話形式で基本情報を入力:

? Extension name: 社内ツール連携
? Description: 社内の各種ツールとClaudeを連携
? Author: Taro Yamada
? License: MIT

3. MCPサーバーの実装

server/index.js:

import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import {
  ListToolsRequestSchema,
  CallToolRequestSchema,
} from '@modelcontextprotocol/sdk/types.js';

const server = new Server({
  name: '社内ツール連携',
  version: '1.0.0'
}, {
  capabilities: {
    tools: {}
  }
});


server.setRequestHandler(ListToolsRequestSchema, async () => ({
  tools: [
    {
      name: 'search_database',
      description: 'データベースを検索します',
      inputSchema: {
        type: 'object',
        properties: {
          query: {
            type: 'string',
            description: '検索クエリ'
          },
          limit: {
            type: 'number',
            description: '結果の最大件数',
            default: 10
          }
        },
        required: ['query']
      }
    },
    {
      name: 'create_task',
      description: 'タスク管理システムに新規タスクを作成',
      inputSchema: {
        type: 'object',
        properties: {
          title: { type: 'string' },
          description: { type: 'string' },
          assignee: { type: 'string' }
        },
        required: ['title']
      }
    }
  ]
}));


server.setRequestHandler(CallToolRequestSchema, async (request) => {
  const { name, arguments: args } = request.params;

  switch (name) {
    case 'search_database':
      
      const results = await searchDatabase(args.query, args.limit);
      return {
        content: [{
          type: 'text',
          text: JSON.stringify(results, null, 2)
        }]
      };

    case 'create_task':
      
      const task = await createTask(args);
      return {
        content: [{
          type: 'text',
          text: `タスクを作成しました: ${task.id}`
        }]
      };

    default:
      throw new Error(`Unknown tool: ${name}`);
  }
});


const transport = new StdioServerTransport();
await server.connect(transport);

4. パッケージング

5. インストール

  1. Claude Desktopを開く
  2. 設定 → Extensions
  3. “Install Extension” をクリック
  4. .dxt ファイルを選択
  5. 必要に応じて設定を入力(APIキーなど)

PostgreSQLクライアント

社内データベースと連携するMCPサーバーの例:

import { Client } from 'pg';

async function searchDatabase(query, limit = 10) {
  const client = new Client({
    connectionString: process.env.DATABASE_URL
  });
  
  await client.connect();
  
  try {
    const result = await client.query(`
      SELECT * FROM products 
      WHERE name ILIKE $1 
      LIMIT $2
    `, [`%${query}%`, limit]);
    
    return result.rows;
  } finally {
    await client.end();
  }
}

ファイルシステム連携

ローカルファイルを操作するMCPサーバー:

import fs from 'fs/promises';
import path from 'path';

server.setRequestHandler(CallToolRequestSchema, async (request) => {
  if (request.params.name === 'list_files') {
    const dir = request.params.arguments.directory;
    const files = await fs.readdir(dir);
    
    const fileInfo = await Promise.all(
      files.map(async (file) => {
        const stat = await fs.stat(path.join(dir, file));
        return {
          name: file,
          type: stat.isDirectory() ? 'directory' : 'file',
          size: stat.size,
          modified: stat.mtime
        };
      })
    );
    
    return {
      content: [{
        type: 'text',
        text: JSON.stringify(fileInfo, null, 2)
      }]
    };
  }
});

DXTは日本企業が重視するセキュリティ要件を満たす設計になっています。

セキュアな認証情報管理

{
  "user_config": {
    "api_key": {
      "type": "string",
      "description": "API認証キー",
      "sensitive": true  
    }
  }
}

sensitive: true を指定すると:

  • 値はOSのセキュアストレージに保存
  • プロセス起動時に環境変数として注入
  • 設定ファイルには保存されない

企業向け管理機能

Windows グループポリシー


Publishers>
  Publisher>CN=YourCompany,O=YourCompany,C=JPPublisher>
Publishers>

macOS MDM設定

key>com.anthropic.claude.desktopkey>
dict>
  key>AllowedExtensionskey>
  array>
    string>com.yourcompany.internal-toolsstring>
  array>
  key>BlockedExtensionskey>
  array>
    string>com.untrusted.*string>
  array>
dict>

プライベートリポジトリ

社内専用の拡張機能ストアを構築:

{
  "extensionDirectories": [
    "https://extensions.yourcompany.com/",
    "https://claude.anthropic.com/extensions/"
  ]
}

Anthropicが公開したサンプルは、DXTの可能性を如実に示しています。

Apple Notes連携


const script = `
  tell application "Notes"
    make new note at folder "Notes" with properties {
      name: "${title}",
      body: "${content}"
    }
  end tell
`;

await exec(`osascript -e '${script}'`);

これにより実現できること:

  • 「今日の議事録をNotesに保存」
  • 「先週のメモを全て要約」
  • 「特定のフォルダのノートを検索」

Chrome完全制御

PlaywrightやSeleniumを超えた、OSレベルでの制御:

const script = `
  tell application "Google Chrome"
    set tabList to {}
    repeat with w in windows
      repeat with t in tabs of w
        set end of tabList to {
          title: title of t,
          url: URL of t,
          active: active tab index of w is index of t
        }
      end repeat
    end repeat
    return tabList
  end tell
`;

const tabs = await exec(`osascript -e '${script}'`);

可能になること:

  • 全タブの情報を横断的に収集
  • 特定条件でタブを自動整理
  • ブックマークや履歴との連携
  • メモリ使用量に基づく最適化

iMessage連携

  tell application "Messages"
    set messageList to {}
    repeat with s in services
      repeat with c in chats of s
        repeat with m in messages of c
          set end of messageList to {
            sender: sender of m,
            content: text of m,
            date: date of m
          }
        end repeat
      end repeat
    end repeat
    return messageList
  end tell

エコシステムの拡大

DXT仕様は完全にオープンソースであり、他のAIアプリケーションでも採用可能です。これは以下を意味します:

  1. 標準化: MCPサーバーの配布フォーマットとしてのデファクトスタンダード
  2. 相互運用性: 一度作成したDXTは複数のAIアプリで利用可能
  3. マーケットプレイス: 将来的にはDXT専用のストアが登場する可能性

開発のベストプラクティス

1. エラーハンドリング

server.setRequestHandler(CallToolRequestSchema, async (request) => {
  try {
    
  } catch (error) {
    console.error(`Error in ${request.params.name}:`, error);
    return {
      content: [{
        type: 'text',
        text: `エラーが発生しました: ${error.message}`
      }],
      isError: true
    };
  }
});

2. ログ出力

import winston from 'winston';

const logger = winston.createLogger({
  level: process.env.LOG_LEVEL || 'info',
  format: winston.format.json(),
  transports: [
    new winston.transports.File({ 
      filename: path.join(process.env.LOG_DIR, 'mcp-server.log') 
    })
  ]
});

3. 設定の検証

function validateConfig() {
  const required = ['DATABASE_URL', 'API_KEY'];
  const missing = required.filter(key => !process.env[key]);
  
  if (missing.length > 0) {
    throw new Error(`Missing required config: ${missing.join(', ')}`);
  }
}

実装のヒント

パフォーマンス最適化


const pool = new Pool({
  connectionString: process.env.DATABASE_URL,
  max: 20,
  idleTimeoutMillis: 30000,
  connectionTimeoutMillis: 2000,
});


const cache = new Map();
const CACHE_TTL = 60 * 1000; 

async function searchWithCache(query) {
  const cacheKey = `search:${query}`;
  const cached = cache.get(cacheKey);
  
  if (cached && cached.expires > Date.now()) {
    return cached.data;
  }
  
  const result = await searchDatabase(query);
  cache.set(cacheKey, {
    data: result,
    expires: Date.now() + CACHE_TTL
  });
  
  return result;
}

非同期処理の最適化


async function processBatch(items, batchSize = 10) {
  const results = [];
  
  for (let i = 0; i  items.length; i += batchSize) {
    const batch = items.slice(i, i + batchSize);
    const batchResults = await Promise.all(
      batch.map(item => processItem(item))
    );
    results.push(...batchResults);
  }
  
  return results;
}

Desktop Extensions (DXT) は、AIアプリケーションのローカル統合における新しいパラダイムを提示しています。

主なメリット

  1. 開発者にとって: 簡単なパッケージング、配布、アップデート
  2. ユーザーにとって: ワンクリックインストール、技術知識不要
  3. 企業にとって: セキュアな管理、統制された展開

今すぐ始めるべき理由

  • 🚀 先行者利益を得られる
  • 🔧 社内ツールの価値を最大化
  • 🌍 オープンエコシステムへの貢献
  • 💡 新しいビジネスチャンスの創出

📣 経営層を説得する武器を用意しました

「DXTすごい!でも上が理解してくれない…」

そんなあなたへ。経営者向け記事を書きました:

👉 「先月の売上データまだ?」が死語になる日

説得ポイント:

  • 45分→3秒の衝撃
  • ROI 300%の実例
  • エンジニア用語ゼロ

この記事を上司に送ってください。
技術だけでは何も変わりません。決裁を動かしましょう。

月曜日の会議で、変化を起こすのは、あなたです。

リソース

DXTは、まさにAI時代の「App Store」となる可能性を秘めています。
この機会を逃さず、ローカルAIアプリケーションの新時代を共に創造していきましょう。



Source link

Views: 0

RELATED ARTICLES

返事を書く

あなたのコメントを入力してください。
ここにあなたの名前を入力してください

- Advertisment -