๐Ÿš€ Easily Connect LLMs and MCP Servers with mcp-use (TypeScript)

Integrating Large Language Models (LLMs) with external services and tools efficiently is a common challenge developers face. Enter mcp-use, an open-source TypeScript library designed to simplify this integration, allowing you to quickly and safely co…


This content originally appeared on DEV Community and was authored by Zane

Image description

Integrating Large Language Models (LLMs) with external services and tools efficiently is a common challenge developers face. Enter mcp-use, an open-source TypeScript library designed to simplify this integration, allowing you to quickly and safely connect any LangChain.js-compatible LLM with MCP servers, building powerful, flexible AI agents.

๐ŸŒŸ Why Choose mcp-use?

mcp-use provides a unified and simple interface to help you rapidly develop intelligent agents capable of calling various tools, freeing you from complex integration tasks and enabling you to focus on your core logic.

โœจ Key Features:

  • ๐Ÿšฆ Extreme Simplicity: Create functional intelligent agents in just a few lines of code.
  • ๐Ÿ”ง LLM Flexibility: Compatible with any LangChain.js-supported LLM that supports tool calls.
  • ๐ŸŒ HTTP/SSE Support: Easily connect to MCP servers.
  • ๐Ÿ”„ Dynamic Server Selection: Agents dynamically choose the most suitable server in real-time.
  • ๐Ÿงฉ Multi-Server Support: Effortlessly use multiple MCP servers simultaneously.
  • ๐Ÿ”’ Fine-Grained Tool Permissions: Restrict sensitive or potentially dangerous tool calls.
  • ๐Ÿ› ๏ธ Fully Customizable: Create custom agents based on LangChain.js or implement new adapters.

โšก Quick Start

๐Ÿ“ฆ Install Dependencies

npm install mcp-use langchain @langchain/openai dotenv

Create a .env file:

OPENAI_API_KEY=your_api_key

๐Ÿ› ๏ธ Example Code

import { ChatOpenAI } from '@langchain/openai';
import { MCPAgent, MCPClient } from 'mcp-use';
import 'dotenv/config';

async function main() {
  const config = {
    mcpServers: {
      playwright: { command: 'npx', args: ['@playwright/mcp@latest'] }
    }
  };

  const client = MCPClient.fromDict(config);
  const llm = new ChatOpenAI({ modelName: 'gpt-4o' });

  const agent = new MCPAgent({ llm, client, maxSteps: 20 });
  const result = await agent.run('Find the best restaurant in Tokyo using Google Search');

  console.log('๐Ÿ” Result:', result);
}

main().catch(console.error);

๐Ÿ—‚๏ธ Using Configuration Files

Manage MCP server configurations in a JSON file:

{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": ["@playwright/mcp@latest"]
    }
  }
}

Load the configuration file:

import { MCPClient } from 'mcp-use';
const client = MCPClient.fromConfigFile('./mcp-config.json');

๐ŸŒ Advanced Multi-Server Usage

const config = {
  mcpServers: {
    airbnb: { command: 'npx', args: ['@openbnb/mcp-server-airbnb'] },
    playwright: { command: 'npx', args: ['@playwright/mcp@latest'] }
  }
};

const client = MCPClient.fromDict(config);
const agent = new MCPAgent({ llm, client, useServerManager: true });
await agent.run('Search Airbnb in Barcelona, then Google restaurants nearby');

๐Ÿ” Fine-Grained Permission Control

const agent = new MCPAgent({
  llm,
  client,
  disallowedTools: ['file_system', 'network']
});

๐Ÿ“– Contribute

mcp-use is fully open-source, and contributions via issues or pull requests are welcome!

If you find mcp-use helpful, consider giving the project a GitHub star. Your support motivates continuous improvement!


This content originally appeared on DEV Community and was authored by Zane


Print Share Comment Cite Upload Translate Updates
APA

Zane | Sciencx (2025-04-20T13:07:05+00:00) ๐Ÿš€ Easily Connect LLMs and MCP Servers with mcp-use (TypeScript). Retrieved from https://www.scien.cx/2025/04/20/%f0%9f%9a%80-easily-connect-llms-and-mcp-servers-with-mcp-use-typescript/

MLA
" » ๐Ÿš€ Easily Connect LLMs and MCP Servers with mcp-use (TypeScript)." Zane | Sciencx - Sunday April 20, 2025, https://www.scien.cx/2025/04/20/%f0%9f%9a%80-easily-connect-llms-and-mcp-servers-with-mcp-use-typescript/
HARVARD
Zane | Sciencx Sunday April 20, 2025 » ๐Ÿš€ Easily Connect LLMs and MCP Servers with mcp-use (TypeScript)., viewed ,<https://www.scien.cx/2025/04/20/%f0%9f%9a%80-easily-connect-llms-and-mcp-servers-with-mcp-use-typescript/>
VANCOUVER
Zane | Sciencx - » ๐Ÿš€ Easily Connect LLMs and MCP Servers with mcp-use (TypeScript). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/04/20/%f0%9f%9a%80-easily-connect-llms-and-mcp-servers-with-mcp-use-typescript/
CHICAGO
" » ๐Ÿš€ Easily Connect LLMs and MCP Servers with mcp-use (TypeScript)." Zane | Sciencx - Accessed . https://www.scien.cx/2025/04/20/%f0%9f%9a%80-easily-connect-llms-and-mcp-servers-with-mcp-use-typescript/
IEEE
" » ๐Ÿš€ Easily Connect LLMs and MCP Servers with mcp-use (TypeScript)." Zane | Sciencx [Online]. Available: https://www.scien.cx/2025/04/20/%f0%9f%9a%80-easily-connect-llms-and-mcp-servers-with-mcp-use-typescript/. [Accessed: ]
rf:citation
» ๐Ÿš€ Easily Connect LLMs and MCP Servers with mcp-use (TypeScript) | Zane | Sciencx | https://www.scien.cx/2025/04/20/%f0%9f%9a%80-easily-connect-llms-and-mcp-servers-with-mcp-use-typescript/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.