Skip to main content

Installing mcp-use

Prerequisites:
  • Install Node.js (version 18 or higher)
  • npm, pnpm, or yarn package manager

Option 1: Create an MCP Server (for Building Servers)

The fastest way to scaffold a new MCP server project is to use create-mcp-use-app:
npx create-mcp-use-app my-mcp-server
cd my-mcp-server
npm run dev
This command will:
  • Create a new directory with your project name
  • Initialize a TypeScript project with mcp-use configured
  • Set up a basic MCP server template with example tools
  • Install all dependencies automatically
Check out UI Widgets with support to MCP-UI and OpenAI Apps SDK for ChatGPT.

Option 2: Install as a Library (for MCP Agents)

Install mcp_use using your preferred package manager:
npm install mcp-use
Then install your preferred LangChain provider:
npm install @langchain/openai dotenv

Setting Up Your First Project

1

Create your MCP server or install the library

Use create-mcp-use-app for MCP servers or npm install for agents (see above).
2

Configure your LLM provider

Choose and install your preferred LangChain provider.
3

Set up environment variables

Create a .env file for your API keys:
.env
OPENAI_API_KEY=your_openai_key_here
ANTHROPIC_API_KEY=your_anthropic_key_here
GROQ_API_KEY=your_groq_key_here
GOOGLE_API_KEY=your_google_key_here
4

Verify installation

Test your installation with a simple script:
import { MCPAgent, MCPClient } from 'mcp-use'
console.log('mcp-use installed successfully!')

Development Installation

If you want to contribute or use the latest features, install from source:
git clone https://github.com/mcp-use/mcp-use.git
cd mcp-use/libraries/typescript
pnpm install
pnpm run build

Installing MCP Servers

mcp-use connects to MCP servers that provide the actual tools.
Check out the Awesome MCP Servers repository for a comprehensive list of available servers.

Environment Setup

Environment Variables

Create a .env file in your project root:
.env
# LLM Provider Keys
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
GROQ_API_KEY=gsk_...
GOOGLE_API_KEY=AI...

# Optional: Logging level
LOG_LEVEL=INFO

# Optional: MCP server paths
MCP_SERVER_PATH=/path/to/mcp/servers
Load environment variables in your scripts:
import { config } from 'dotenv'

config()

// Your API keys are now available as environment variables
const openaiKey = process.env.OPENAI_API_KEY

Verification

Verify your installation works correctly:
import { config } from 'dotenv'
import { ChatOpenAI } from '@langchain/openai'
import { MCPAgent, MCPClient } from 'mcp-use'

async function verifyInstallation() {
    config()

    // Simple configuration for testing
    const configuration = {
        mcpServers: {
            test: {
                command: 'echo',
                args: ['Hello from MCP!']
            }
        }
    }

    try {
        const client = new MCPClient(configuration)
        console.log('✅ MCPClient created successfully')

        const llm = new ChatOpenAI({ model: 'gpt-3.5-turbo' })
        console.log('✅ LLM initialized successfully')

        const agent = new MCPAgent({ llm, client })
        console.log('✅ MCPAgent created successfully')

        console.log('\n🎉 Installation verified! You\'re ready to use mcp_use.')

        // Clean up
        await client.closeAllSessions()

    } catch (error) {
        console.error('❌ Verification failed:', error)
        console.error('Please check your installation and API keys.')
    }
}

verifyInstallation().catch(console.error)

Next Steps

Troubleshooting

Make sure mcp_use is installed and accessible:
npm list mcp-use
Verify your .env file is in the correct location and your API keys are valid:
cat .env  # Check file contents
Ensure your MCP servers are properly installed and accessible:
which npx  # For Node.js-based servers
Tool Calling Required: Only models with tool calling capabilities can be used with mcp_use. Make sure your chosen model supports function calling or tool use.