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
-
Clone this repository:
git clone https://github.com/yourusername/mcp-client-typescript.git cd mcp-client-typescript -
Install dependencies:
npm install -
Create a
.envfile 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
- The client connects to the specified MCP server using the MCP SDK
- It retrieves the list of available tools from the server
- When you enter a query, it sends the query to Claude along with the tool definitions
- 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 implementationtsconfig.json: TypeScript configurationpackage.json: Project dependencies and scripts
Available Commands
npm run build: Compile TypeScript code and make the output executable
