MCPInstall
MCP-quickstart logo

MCP-quickstart

by AgentisLabs AgentisLabs/MCP-quickstart

Model Context Protocol Quickstart - server and client in the same repository.

READMEmain

MCP Client for Claude

This repository contains a TypeScript implementation of a Model Context Protocol (MCP) client that works with Claude AI models. It allows you to connect to any MCP-compatible server and use Claude to interact with the tools provided by that server.

What is MCP?

The Model Context Protocol (MCP) is an open standard that enables AI models to use tools and access external data through a standardized interface. Learn more at modelcontextprotocol.io.

Prerequisites

  • Node.js (v16 or higher)
  • npm or yarn
  • An Anthropic API key for Claude

Installation

  1. Clone this repository:

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

    npm install
    
  3. Create a .env file in the root directory with your Anthropic API key:

    ANTHROPIC_API_KEY=your_api_key_here
    

Building the Client

Build the TypeScript code:

npm run build

This will compile the TypeScript code to JavaScript in the build directory and make the output file executable.

Running the Client

To run the client, you need to provide the path to an MCP server script:

node build/index.js path/to/server/script.js

For Python servers:

node build/index.js path/to/server/script.py

Example with Weather Server

If you have the weather server example in a subdirectory:

# First build the weather server
cd weather
npm run build
cd ..

# Then run the client with the weather server
node build/index.js ./weather/build/index.js

How It Works

  1. The client connects to the specified MCP server using the MCP SDK
  2. It retrieves the list of available tools from the server
  3. When you enter a query, it sends the query to Claude along with the tool definitions
  4. If Claude decides to use a tool, the client:
    • Calls the tool on the MCP server
    • Sends the result back to Claude
    • Returns Claude's final response

Project Structure

  • index.ts: Main client implementation
  • tsconfig.json: TypeScript configuration
  • package.json: Project dependencies and scripts

Available Commands

  • npm run build: Compile TypeScript code and make the output executable

License

MIT License