MCP Tools Usage From LangChain / Example in TypeScript

by hideya

MCP Client 12 stars
  • agent-framework

MCP Tools Usage From LangChain ReAct Agent / Example in TypeScript

About

What is MCP Tools Usage From LangChain / Example in TypeScript?

This is a command-line Model Context Protocol (MCP) client built with TypeScript that demonstrates how to use MCP server tools via LangChain’s ReAct Agent. It runs on Node.js 16+ and is intended for developers integrating MCP with LangChain.

How to use MCP Tools Usage From LangChain / Example in TypeScript?

Clone the repository, install dependencies with npm install, copy .env.template to .env and add your Anthropic (or OpenAI) API key, then run npm start. Optionally install uv to support Python-based MCP servers.

Key features of MCP Tools Usage From LangChain / Example in TypeScript

- Demonstrates MCP tool usage with LangChain ReAct Agent
- Parallel initialization of multiple MCP servers
- Converts MCP tools to LangChain‑compatible StructuredTool[]
- Uses Anthropic Claude 3.5 Sonnet by default
- Includes commented‑out support for OpenAI GPT‑4o
- Provides sample OAuth authentication for SSE connections

Use cases of MCP Tools Usage From LangChain / Example in TypeScript

- Learn how to integrate MCP servers into LangChain‑based agents
- Prototype and test combinations of MCP tools in a TypeScript environment
- Explore OAuth authentication for MCP servers over SSE
- Serve as a foundation for building production MCP clients using LangChain

FAQ from MCP Tools Usage From LangChain / Example in TypeScript

What LLMs does it support?

It uses Anthropic’s claude-3-5-sonnet-latest by default. Code for OpenAI’s gpt-4o is included but commented out.

How do I add my own MCP servers?

You modify the server configuration in the source code; the convertMcpToLangchainTools utility handles parallel initialization and tool conversion.

Does it support Python‑based MCP servers?

Yes, if you have uv (or uvx) installed, you can run Python‑based MCP servers alongside Node‑based ones.

What license is it under?

This project is released under the MIT License.

Do I need a paid API key to run it?

Yes, you need an API key from either Anthropic or OpenAI. Usage of those APIs may incur costs depending on your plan.

Details

Author
hideya
GitHub stars
12
Category
agent-framework
Repository
hideya/langchain-mcp-tools-ts-usage

MCP Tools Usage From LangChain / Example in TypeScript License: MIT

This simple Model Context Protocol (MCP)
client demonstrates the use of MCP server tools by LangChain ReAct Agent.

It leverages a utility function convertMcpToLangchainTools() from
@h1deya/langchain-mcp-tools.
This function handles parallel initialization of specified multiple MCP servers
and converts their available tools into an array of LangChain-compatible tools
([StructuredTool[]](https://api.js.langchain.com/classes/_langchain_core.tools.StructuredTool.html)).

Anthropic's claude-3-5-sonnet-latest is used as the LLM.
For convenience, code for OpenAI's gpt-4o is also included and commented out.

A bit more realistic (conversational) MCP Client is available
here

A python equivalent of this app is available
here

Prerequisites

- Node.js 16+
- npm 7+ (npx) to run Node.js-based MCP servers
- [optional] uv (uvx)
installed to run Python-based MCP servers
- API key from Anthropic
(or OpenAI)

Usage

1. Install dependencies:

    npm install
    

2. Setup API key:

    cp .env.template .env

- Update .env as needed.
- .gitignore is configured to ignore .env
to prevent accidental commits of the credentials.

3. Run the app:

    npm start

Sample Code for SSE Authentiocation

A simple example of showing how to implement an OAuth client provider and
use it with the langchain-mcp-tools library can be found
in src/sse-auth-test-client.ts.

For testing purposes, a sample MCP server with OAuth authentication support
that works with the above client is provided
in src/sse-auth-test-server.ts.

You can run the server with npm run sse-auth-test-server
and the client with npm run sse-auth-test-client.