Sponsored by Deepsite.site

MCP Client

Created By
kamusis8 months ago
A lightweight TypeScript client for the Model Context Protocol (MCP) that enables AI language models to access external tools and services.
Content

MCP Client

A TypeScript client for the Model Context Protocol (MCP) that enables communication between language models and external MCP server tools/services.

Overview

This MCP client provides a flexible interface for connecting to various MCP servers, allowing language models like OpenAI's GPT and Anthropic's Claude to access external tools and services through a standardized protocol. The client supports multiple server types and handles cross-platform compatibility.

Features

  • Connect to multiple MCP servers simultaneously
  • Support for both OpenAI and Anthropic language models
  • Cross-platform compatibility (Windows, macOS, Linux)
  • Automatic handling of platform-specific commands
  • Configurable environment variables

Prerequisites

  • Node.js (v16+)
  • npm or yarn
  • TypeScript

Installation

  1. Clone the repository:

    git clone https://github.com/kamusis/mcp-client.git
    cd mcp-client
    
  2. Install dependencies:

    npm install
    
  3. Create a .env file in the project root with your API keys:

    # LLM (OPENAI or ANTHROPIC)
    LLM=OPENAI
    OPENAI_MODEL=gpt-4o
    ANTHROPIC_MODEL=claude-3-5-sonnet-20241022
    
    # LLM API Key
    ANTHROPIC_API_KEY=your_anthropic_api_key
    OPENAI_API_KEY=your_openai_api_key
    
    # MCP Configuration File Path (optional, defaults to ./mcp_config.json)
    # MCP_CONFIG_PATH=./mcp_config.json
    
  4. Configure your MCP servers in mcp_config.json:

    {
      "mcpServers": {
        "sequential-thinking": {
          "command": "npx",
          "args": [
            "-y",
            "@modelcontextprotocol/server-sequential-thinking"
          ]
        },
        "postgres-full-localhost-dev": {
          "command": "node",
          "args": [
            "/path/to/mcp-postgres-full-access-extended/dist/index.js",
            "postgresql://postgres:postgres@127.0.0.1:5432/postgres"
          ],
          "env": {
            "TRANSACTION_TIMEOUT_MS": "60000",
            "MAX_CONCURRENT_TRANSACTIONS": "20",
            "PG_STATEMENT_TIMEOUT_MS": "30000"
          }
        }
      }
    }
    

Building and Running

  1. Build the project:

    npm run build
    
  2. Run the client:

    node build/index.js
    

Configuration

Environment Variables

  • LLM: The language model provider to use (OPENAI or ANTHROPIC)
  • OPENAI_MODEL: The OpenAI model to use (e.g., gpt-4o)
  • ANTHROPIC_MODEL: The Anthropic model to use (e.g., claude-3-5-sonnet-20241022)
  • ANTHROPIC_API_KEY: Your Anthropic API key
  • OPENAI_API_KEY: Your OpenAI API key
  • MCP_CONFIG_PATH: Path to the MCP configuration file (optional, defaults to ./mcp_config.json)

MCP Server Configuration

The mcp_config.json file defines the MCP servers to connect to. Each server entry includes:

  • command: The command to run the server
  • args: Arguments to pass to the command
  • env: Environment variables for the server (optional)

Cross-Platform Compatibility

The client automatically handles platform-specific differences:

  • On Windows, npx commands are adjusted to use npx.cmd
  • Python commands are adjusted based on the platform (python on Windows, python3 on Unix-like systems)
  • Environment variables are properly passed to child processes

License

MIT

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
WindsurfThe new purpose-built IDE to harness magic
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
CursorThe AI Code Editor
Serper MCP ServerA Serper MCP Server
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
ChatWiseThe second fastest AI chatbot™
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
DeepChatYour AI Partner on Desktop
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Tavily Mcp
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
Amap Maps高德地图官方 MCP Server
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
Playwright McpPlaywright MCP server