umaidashi
MCP Serverumaidashipublic

mcp client ts

使用 Model Context Protocol (MCP) 的 TypeScript 应用程序,集成 Anthropic API 实现对话型 AI 助手。

Repository Info

0
Stars
0
Forks
0
Watchers
0
Issues
JavaScript
Language
-
License

About This Server

使用 Model Context Protocol (MCP) 的 TypeScript 应用程序,集成 Anthropic API 实现对话型 AI 助手。

Model Context Protocol (MCP) - This server can be integrated with AI applications to provide additional context and capabilities, enabling enhanced AI interactions and functionality.

Documentation

mcp-client-ts

Model Context Protocol (MCP)を使用したTypeScriptクライアントアプリケーションです。Anthropic APIと連携して、対話型のAIアシスタントを実装しています。

機能

  • Anthropic APIとの連携
  • Model Context Protocol (MCP)サーバーとの通信
  • 対話型のチャットインターフェース
  • ツールの動的な呼び出しと実行

必要条件

  • Bun v1.1.21以上
  • Anthropic APIキー(環境変数として設定)

インストール

bun install

使用方法

  1. 環境変数の設定:
export ANTHROPIC_API_KEY=your_api_key_here
  1. サーバースクリプトを指定して実行:
bun run index.ts <path_to_server_script>

プロジェクト構造

  • index.ts: メインのクライアントアプリケーション
  • MCPClientクラス: クライアントの主要な機能を実装
    • サーバー接続管理
    • クエリ処理
    • チャットループ
    • リソース管理

主要な関数とメソッド

メイン関数

  • main(): プログラムのエントリーポイント
    • コマンドライン引数の処理
    • MCPClientの初期化と実行
    • 終了時のクリーンアップ処理

MCPClientクラスのメソッド

  • constructor(): クラスの初期化

    • Anthropic APIクライアントの設定
    • MCPクライアントの初期化
  • connectToServer(serverScriptPath: string): サーバー接続処理

    • 指定されたサーバースクリプトの実行
    • 利用可能なツールの取得と保存
    • 接続状態の管理

NOTE

このMCPサーバーなに使えるかの部分が、各Client(Cursor, VSCode, Claude Desktop)で違う 今回は cli の引数で受け取っているが、 config ファイルにしてしまうこともできる

  • processQuery(query: string): クエリ処理
    • ユーザー入力の処理
    • Anthropic APIとの通信
    • ツールの呼び出しと結果の処理
    • 応答の生成

NOTE

ユーザーからの入力値を受け取る WebServerであれば、HTTPリクエストのボディから取得する

  • chatLoop(): 対話型インターフェース
    • ユーザー入力の待ち受け
    • クエリの処理と応答の表示
    • 終了条件の管理

NOTE

チャットが生きている限り、続くもの Webサーバーでリロードしてもチャットを活かすには、DBに保存しておくなど工夫が必要(ChatIDなどをキーに取り出す)

  • cleanup(): リソース解放
    • クライアント接続の終了
    • リソースの解放

NOTE

チャットが終了したら、リソースを解放する

開発情報

このプロジェクトはbun initを使用して作成されました。Bunは高速なオールインワンJavaScriptランタイムです。

Quick Start

1

Clone the repository

git clone https://github.com/umaidashi/mcp-client-ts
2

Install dependencies

cd mcp-client-ts
npm install
3

Follow the documentation

Check the repository's README.md file for specific installation and usage instructions.

Repository Details

Ownerumaidashi
Repomcp-client-ts
LanguageJavaScript
License-
Last fetched8/10/2025

Recommended MCP Servers

💬

Discord MCP

Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.

integrationsdiscordchat
🔗

Knit MCP

Connect AI agents to 200+ SaaS applications and automate workflows.

integrationsautomationsaas
🕷️

Apify MCP Server

Deploy and interact with Apify actors for web scraping and data extraction.

apifycrawlerdata
🌐

BrowserStack MCP

BrowserStack MCP Server for automated testing across multiple browsers.

testingqabrowsers

Zapier MCP

A Zapier server that provides automation capabilities for various apps.

zapierautomation