Token导航 LogoToken导航TokenDH.com
Easy MCP Use logo
AI代理未说明官方级别未说明来源级核验

Easy MCP Use

MCP Server

Easy-MCP-Use is the open source TypeScript library to connect any LLM to any MCP server and build custom agents that have tool access, without using closed source or application clients.

工具数

0

提示词数

0

GitHub Stars

13

资源数

0
开源TypeScriptAI代理模型集成

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

dforel

提供方

dforel

最后核验

2026/5/18 02:52

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

详细介绍

英语|简体中文

Unified MCP Client Library for TypeScript

](https://www.npmjs.com/package/easy-mcp-use) ](https://www.npmjs.com/package/easy-mcp-use) ](https://www.npmjs.com/package/easy-mcp-use) ![TypeScript Support](https://www.npmjs.com/package/easy-mcp-use) ![Documentation](https://easy-mcp-use.52kx.net)

![License](https://github.com/dforel/easy-mcp-use/blob/main/LICENSE) ![Code Style: Prettier](https://prettier.io) ](https://github.com/dforel/easy-mcp-use/stargazers) ![Twitter Follow](https://x.com/dforel99)

🌐 Easy MCP Use是一个用于连接的开源TypeScript库 任何LLM到任何MCP服务器 并构建具有工具访问权限的自定义代理,而无需使用闭源或应用程序客户端。

💡 让开发人员轻松地将任何LLM连接到具有完整TypeScript支持的web浏览、文件操作等工具。

特性

✨ 主要特点

特性描述
🔄 易用性只需6行TypeScript代码即可创建第一个支持MCP的代理
🤖 LLM灵活性适用于任何支持LangChain并支持工具调用的LLM(OpenAI、Anthropic、Groq、LLama等)
🌐 HTTP支持直接连接到在特定HTTP端口上运行的MCP服务器
⚙️ 动态服务器选择TODO代理可以从可用池中为给定任务动态选择最合适的MCP服务器
🧩 多服务器支持TODO在单个代理中同时使用多个MCP服务器
🛡️ 工具限制TODO限制文件系统或网络访问等潜在危险的工具
📝 类型安全TODO完全支持TypeScript,所有API和配置都有类型定义

快速启动

使用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提供程序

通过LangChain,各种LLM提供商可以轻松使用mcp。您需要为您选择的LLM安装相应的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=
重要:只有具有工具调用功能的模型才能轻松使用mcp。确保您选择的模型支持函数调用或工具使用。

启动您的代理:


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服务器示例

有一个示例项目: 简单的mcp使用示例 (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这使得需要来自不同服务器的工具的复杂工作流程成为可能,例如与文件操作或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 配置有多个服务器。

默认情况下,代理将可以从所有配置的服务器访问工具。如果需要为特定任务定位特定服务器,可以指定 serverName 当呼叫 agent.run() 方法。

// 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
);

特定代理的详细描述

如果您只想查看代理的调试信息,而不启用完整的调试日志记录,则可以设置 verbose 创建MCPAgent时的参数:

// Create agent with increased verbosity
const agent = new MCPAgent({
    llm,
    client,
    verbose: true  // Only shows debug messages from the agent
});

当您只需要查看代理的步骤和决策过程,而不需要查看其他组件的所有低级调试信息时,这很有用。

路线图

[x] Multiple Servers at once

[x] Test remote connectors (http, ws)

[ ] ...

贡献

我们热爱贡献!对于bug或功能请求,请随时打开问题。

需求

  • 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使用

我希望你喜欢

许可证

麻省理工学院

目录标签

目录标签

开源TypeScriptAI代理模型集成developer-toolsLLM集成本地部署工具调用多服务器支持

接入字段

传输方式(transport,传输协议)

未说明

鉴权方式(authType,认证方式)

none

工具数量(toolCount,工具数)

0

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

未说明none部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

仍需确认:installCommand

来源信息

继续浏览同类 MCP