EM

edanyal/mcp-client

Developer tools

このページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。 原文を見る

30 stars 3 forks 品質 54 トレンド 11

Typescript mcp クライアントライブラリ.

概要

LLMエージェントのモデルコンテキストプロトコル(MCP)クライアントのTypeScript実装。 - MCP 仕様のフル実装 - stdio と HTTP+SSE の両方の転送のサポート - 組み込みの MCP サーバー プロセス管理 - Claude のネイティブ ツール呼び出しとの統合 - Type-safe API - イベントベースのアーキテクチャ - Promise ベースの async/await API - すべての MCP 操作のサポート: - リソース - ツール - Prompts - Sampling MCP Client を使用する最も一般的な方法は、npx を使用して標準の MCP サーバーです。 設定ファイル(mcp-config)を作成します.

概要(AI 翻訳)

LLMエージェントのモデルコンテキストプロトコル(MCP)クライアントのTypeScript実装。

インストール

##特徴

  • MCP 仕様の完全な実装
  • stdioとHTTP+SSEの両方の輸送をサポート
  • MCPサーバープロセス管理内蔵
  • Claudeのネイティブツールコールとの統合
  • タイプ安全API
  • イベントベースのアーキテクチャ
  • Promise ベースの async/await API
  • すべてのMCP操作のサポート:
  • リソース
  • ツール
  • プロンプト
  • サンプリング

使用法

MCP サーバーでの使用

MCP Client を使用する最も一般的な方法は、npx を使用して標準の MCP サーバーです。 設定ファイル(mcp-config.json)を作成します。

次に、MCPConnectionManager を使用して、サーバーに接続します。

##Claudeとの統合

クライアントは、Claudeのネイティブツールコールでシームレスに動作するように設計されています。

低レベルの使用法

より多くの制御が必要な場合は、クライアントを直接使用できます。

利用可能な MCP サーバー

npx で利用可能な一般的な MPC サーバー:

  • [@modelcontextprotocol/server-memory - ナレッジグラフ操作
  • [@modelcontextprotocol/server-filesystem - ファイルシステム操作
  • [@modelcontextprotocol/server-brave-search - Web検索機能

このページは AI により自動翻訳されています。技術的な詳細は原文をご確認ください。

README

以下は原文 README の抜粋です。原文を見る。

MCP Client

A TypeScript implementation of a Model Context Protocol (MCP) client for LLM agents.

Installation

npm install mcp-client

Features

  • Full implementation of the MCP specification
  • Support for both stdio and HTTP+SSE transports
  • Built-in MCP server process management
  • Integration with Claude’s native tool calling
  • Type-safe API
  • Event-based architecture
  • Promise-based async/await API
  • Support for all MCP operations:
    • Resources
    • Tools
    • Prompts
    • Sampling

Usage

Using with MCP Servers

The most common way to use MCP Client is with standard MCP servers via npx. Create a configuration file (mcp-config.json):

{
  "mcpServers": {
    "memory": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-memory"
      ]
    },
    "filesystem": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-filesystem",
        "/path/to/allowed/directory"
      ]
    },
    "brave-search": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-brave-search"
      ],
      "env": {
        "BRAVE_API_KEY": "your-api-key"
      }
    }
  }
}

Then use the MCPConnectionManager to connect to your servers:

import { MCPConnectionManager } from 'mcp-client';

const manager = new MCPConnectionManager();
await manager.initialize('./mcp-config.json');

// Get clients for specific servers
const memoryClient = manager.getClient('memory');
const fsClient = manager.getClient('filesystem');

// Use tools from the servers
const memoryTools = await memoryClient?.listTools();
const fsTools = await fsClient?.listTools();

// Clean up when done
await manager.cleanup();

Integration with Claude

The client is designed to work seamlessly with Claude’s native tool calling:

import { Anthropic } from '@anthropic-ai/sdk';
import { MCPConnectionManager } from 'mcp-client';

// Initialize Claude and MCP
const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
const manager = new MCPConnectionManager();
await manager.initialize('./mcp-config.json');

// Get a client
const memoryClient = manager.getClient('memory');
const tools = await memoryClient?.listTools();

// Use with Claude
const response = await anthropic.messages.create({
  model: 'claude-3-sonnet-20240229',
  max_tokens: 1024,
  messages: [{ role: 'user', content: 'your prompt' }],
  tools: tools?.map(tool => ({
    name: tool.name,
    description: tool.description || '',
    parameters: tool.inputSchema
  }))
});

// Handle tool calls
if (!response.content[0].text && response.content[0].type === 'tool_call') {
  const toolCall = response.content[0].tool_calls[0];
  const result = await memoryClient?.callTool(
    toolCall.name,
    toolCall.parameters
  );
  // Send result back to Claude...
}

Low-level Usage

If you need more control, you can use the client directly:

GitHub で README 全文を見る

インストール

npx -y @modelcontextprotocol/server-memory
MCP 初心者?mcpskill.org のガイドから始めましょう →

設定

{ "mcpServers": { "memory": { "command": "npx", "args": [ "-y", "@modelcontextprotocol/server-memory" ] }, "filesystem": { "command": "npx", "args": [ "-y", "@modelcontextprotocol/server-filesystem", "/path/to/allowed/directory" ] }, "brave-search": { "command": "npx", "args": [ "-y", "@modelcontextprotocol/server-brave-search" ], "env": { "BRAVE_API_KEY": "your-api-key" } } } }