关于 Unified MCP Client Library for TypeScript
Easy-MCP-Use 是面向开发者的开源 TypeScript 库,可将支持工具调用的 LangChain LLM 接入一个或多个 MCP 服务,用于构建可调用工具的 Agent。
主要功能
- 01连接支持工具调用的 LLM 与 MCP 服务
- 02配置多个 MCP 服务
- 03为 Agent 任务选择服务
- 04通过 HTTP 连接服务
- 05提供 TypeScript 库与 API
适用场景
- 01构建使用网页浏览工具的 Agent
- 02组合浏览与文件服务的工具
- 03将任务路由到指定 MCP 服务
MCP 相关
该库提供 MCP 客户端,用于配置和连接 MCP 服务,包括多个服务和 HTTP 连接。Agent 可使用这些服务提供的工具。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
English|简体中文
适用于 TypeScript 的统一 MCP 客户端库
🌐 Easy-MCP-Use 是一个开源 TypeScript 库,可连接任意大模型与任意 MCP 服务,并构建能够使用工具的自定义 Agent,无需使用闭源客户端或应用客户端。
💡 让开发者能够轻松连接任意大模型与网页浏览、文件操作等工具,并提供完整的 TypeScript 支持。
功能
✨ 主要功能
| 功能 | 描述 |
|---|---|
| 🔄 易于使用 | 只需 6 行 TypeScript 代码,即可创建第一个支持 MCP 的 Agent |
| 🤖 大模型灵活性 | 可与任何受 LangChain 支持且支持工具调用的大模型配合使用(OpenAI、Anthropic、Groq、LLama 等) |
| 🌐 HTTP 支持 | 直接连接到运行在指定 HTTP 端口上的 MCP 服务 |
| ⚙️ 动态服务选择 | TODO Agent 可从可用服务池中动态选择最适合特定任务的 MCP 服务 |
| 🧩 多服务支持 | TODO 在单个 Agent 中同时使用多个 MCP 服务 |
| 🛡️ 工具限制 | TODO 限制文件系统或网络访问等可能有危险的工具 |
| 📝 类型安全 | TODO 为所有 API 和配置提供完整的 TypeScript 类型定义 |
快速开始
使用 npm:
npm install easy-mcp-use
或从源码安装:
git clone https://github.com/dforel/easy-mcp-use.git
cd easy-mcp-use
npm install
npm run build
安装 LangChain 提供方
easy-mcp-use 通过 LangChain 支持多种大模型提供方。你需要为所选的大模型安装相应的 LangChain 提供方包。例如:
# For OpenAI
npm install @langchain/openai
# For Anthropic
npm install @langchain/anthropic
# For other providers, check the [LangChain chat models documentation](https://js.langchain.com/docs/integrations/chat/)
并将要使用的提供方 API 密钥添加到 .env 文件中。
OPENAI_API_KEY=
ANTHROPIC_API_KEY=
重要提示:easy-mcp-use 只能使用支持工具调用的模型。请确保所选模型支持函数调用或工具使用。
启动 Agent:
import { MCPClient } from 'easy-mcp-use';
import { MCPAgent, MCPAgentOptions } from 'easy-mcp-use';
import { ChatOpenAI } from '@langchain/openai';
import dotenv from 'dotenv';
dotenv.config();
const openAIApiKey = process.env.openRouteApiKey;
if (!openAIApiKey) {
throw new Error("openAIApiKey environment variable is not set");
}
console.log(`openAIApiKey: ${openAIApiKey}`);
async function main() {
let config = {"mcpServers": {"http": {"url": "http://localhost:3001/sse"}}}
// 从配置文件创建客户端
const client = MCPClient.fromConfig( config );
try {
const chat = new ChatOpenAI(
{
modelName: 'google/gemini-2.0-flash-exp:free',
streaming: true,
openAIApiKey: openAIApiKey,
configuration: {
baseURL: 'https://openrouter.ai/api/v1',
}
}
);
let options = {
client: client,
// verbose: true,
maxSteps: 30,
llm: chat,
}
let agent = new MCPAgent(options)
let result = agent.run(
`
100 rmb can exchange how much doller?
`
);
console.log( JSON.stringify(result) );
} finally {
// console.info('finally');
}
}
main().catch(console.error);
你也可以像这样从配置文件中添加服务配置:
const client = MCPClient.fromConfigFile(
path.join(__dirname, 'browser_mcp.json')
);
配置文件示例(browser_mcp.json):
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["@playwright/mcp@latest"],
"env": {
"DISPLAY": ":1"
}
}
}
}
有关其他设置、模型等信息,请查阅文档。
使用场景示例
HTTP 服务示例
这里有一个示例项目: easy-mcp-use-example (https://github.com/dforel/easy-mcp-use-examples)
使用 Playwright 浏览网页
import { MCPClient } from '../src/client';
import path from 'path';
import { MCPAgent, MCPAgentOptions } from '../src/agents/mcpagent';
// import { ChatOpenAI } from 'langchain/core/language_models/chat_openai';
// import { OpenAI } from "@langchain/llms/openai";
import { ChatOpenAI } from '@langchain/openai';
import { logger } from '../src/logging';
import dotenv from 'dotenv';
dotenv.config();
const openAIApiKey = process.env.openAIApiKey;
if (!openAIApiKey) {
throw new Error("openAIApiKey environment variable is not set");
}
logger.info(`openAIApiKey: ${openAIApiKey}`);
async function main() {
// 从配置文件创建客户端
const client = await MCPClient.fromConfigFile(
path.resolve(__dirname, './browser_mcp.json')
);
try {
const chat = new ChatOpenAI(
{
modelName: 'google/gemini-2.0-flash-exp:free',
// modelName: 'google/gemini-2.5-pro-exp-03-25:free',
streaming: true,
openAIApiKey: openAIApiKey,
configuration: {
baseURL: 'https://openrouter.ai/api/v1',
}
}
);
let options: MCPAgentOptions = {
client: client,
verbose: true,
maxSteps: 30,
llm: chat,
}
let agent = new MCPAgent(options)
let result = agent.run(
`
open bing.com
click input
input easy-mcp-use
click search
`
);
console.log( JSON.stringify(result) );
} finally {
console.info('finally');
}
}
main().catch(console.error);
此示例演示如何连接到运行在指定 HTTP 端口上的 MCP 服务。运行此示例前,请确保已启动 MCP 服务。
多服务支持
MCP-Use-TS 支持使用 MCPClient 配置并同时连接多个 MCP 服务。这使得需要使用不同服务工具的复杂工作流成为可能,例如将网页浏览与文件操作或 3D 建模相结合。
配置
你可以在配置文件中配置多个服务:
{
"mcpServers": {
"airbnb": {
"command": "npx",
"args": ["-y", "@openbnb/mcp-server-airbnb", "--ignore-robots-txt"]
},
"playwright": {
"command": "npx",
"args": ["@playwright/mcp@latest"],
"env": {
"DISPLAY": ":1"
}
}
}
}
用法
MCPClient 类提供了用于管理与多个服务的连接的方法。创建 MCPAgent 时,可以提供一个配置了多个服务的 MCPClient。
默认情况下,Agent 可以使用所有已配置服务中的工具。如果需要针对特定任务指定某个服务,可以在调用 agent.run() 方法时指定 serverName。
// Example: Manually selecting a server for a specific task
const airbnbResult = await agent.run(
'Search for Airbnb listings in Barcelona',
{ serverName: 'airbnb' } // Explicitly use the airbnb server
);
const googleResult = await agent.run(
'Find restaurants near the first result using Google Search',
{ serverName: 'playwright' } // Explicitly use the playwright server
);
Agent 专属详细程度
如果只想查看 Agent 的调试信息,而不启用完整的调试日志,可以在创建 MCPAgent 时设置 verbose 参数:
// Create agent with increased verbosity
const agent = new MCPAgent({
llm,
client,
verbose: true // Only shows debug messages from the agent
});
如果你只需要查看 Agent 的步骤和决策过程,而不需要其他组件提供的所有底层调试信息,这会很有用。
路线图
- [x] 同时使用多个服务
- [x] 测试远程连接器(http、ws)
- [ ] ...
贡献
我们欢迎贡献!欢迎提交问题报告或功能请求。
要求
- Node.js 18+
- TypeScript 5.0+
- MCP 实现(如 Playwright MCP)
- LangChain 和适用的模型库(OpenAI、Anthropic 等)
引用
如果你在研究或项目中使用 MCP-Use-TS,请引用:
@software{easy-mcp-use,
author = {dforel},
title = {Easy-MCP-Use: MCP Library for TypeScript},
year = {2025},
publisher = {GitHub},
url = {https://github.com/dforel/easy-mcp-use}
}
其他
此项目是 mcp-use 的一个分支。
希望你喜欢它。
许可证
MIT
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。