Claude Code MCP: How to Add MCP Servers (Complete Guide)
Table of Contents
Introduction
This tutorial provides a comprehensive guide on how to enhance your Claude Code agents by adding Model Context Protocol (MCP) servers. By integrating servers like Context7 for documentation and Bright Data for web scraping, you can significantly improve the functionality of your AI agents. This guide will walk you through setting up both remote and STDIO servers, configuring environment variables, and installing necessary components on Windows without WSL.
Step 1: Understanding MCP Server Types
Before diving into the setup, it's essential to know the types of MCP servers:
- Remote MCP Servers: These servers are accessed over the internet and can provide dynamic data and documentation.
- Local (STDIO) Servers: These are hosted on your local machine and are suitable for development and testing.
Step 2: Adding a Remote MCP Server (Context7)
To integrate a remote MCP server like Context7, follow these steps:
-
Gather Required Information:
- Ensure you have the API endpoint and any required authentication keys from Context7.
-
Use MCP Add Command:
- The command structure to add a remote MCP server is as follows:
MCP add --name <server_name> --type remote --url <server_url> --api-key <your_api_key>
- Replace
<server_name>
,<server_url>
, and<your_api_key>
with your specific details.
- The command structure to add a remote MCP server is as follows:
-
Execute the Command:
- Run the command in your terminal to add the remote server.
Step 3: Adding STDIO Servers
To set up a local STDIO server, follow these steps:
-
Start the STDIO Server:
- Use the command:
MCP start --type stdio
- Use the command:
-
Verify the Server is Running:
- Check your terminal output for confirmation that the server has started successfully.
Step 4: Configuring Environment Variables and API Keys
Proper configuration of environment variables is crucial for your servers to function correctly.
-
Set Environment Variables:
- Depending on your operating system, add the necessary environment variables:
- For Windows:
- Open the Start Menu.
- Search for "Environment Variables".
- Click on "Environment Variables" under System Properties.
- Add a new variable for your API key (e.g.,
MCP_API_KEY=<your_api_key>
).
- For Windows:
- Depending on your operating system, add the necessary environment variables:
-
Test Environment Variables:
- In your terminal, run:
echo $MCP_API_KEY # On Unix/Linux/Mac echo %MCP_API_KEY% # On Windows
- Ensure the output matches your API key.
- In your terminal, run:
Step 5: Windows Setup Without WSL
If you’re using Windows and prefer not to use Windows Subsystem for Linux (WSL), follow these steps:
-
Download Required Tools:
- Download and install any necessary tools like Node.js or Python, depending on your project requirements.
-
Install MCP Dependencies:
- Use your terminal or command prompt to install any dependencies required for your MCP server setup.
-
Verify Installation:
- Check that all components are correctly installed by running:
MCP --version
- Check that all components are correctly installed by running:
Step 6: Advanced Setup with Bright Data MCP Server
To add advanced functionality with Bright Data, do the following:
-
Obtain API Details:
- Sign up for Bright Data and gather your account details and API keys.
-
Add Bright Data MCP Server:
- Use the similar command structure as shown in Step 2, adjusting for Bright Data:
MCP add --name BrightData --type remote --url <bright_data_url> --api-key <your_bright_data_api_key>
- Use the similar command structure as shown in Step 2, adjusting for Bright Data:
-
Test the Integration:
- Ensure your Bright Data server is correctly integrated by making sample requests to verify connectivity.
Step 7: Live Demo Testing
Finally, test both your MCP servers to ensure they are working correctly with your Claude Code agents.
-
Run Sample Queries:
- Use your agents to query both the Context7 and Bright Data servers and observe the responses.
-
Troubleshoot Issues:
- If any errors occur, check your API keys, server URLs, and ensure your environment variables are set correctly.
Conclusion
By following this guide, you have successfully integrated MCP servers into your Claude Code agents. You can now leverage real-time data and documentation, enhancing the capabilities of your AI applications. As a next step, consider exploring additional MCP servers or integrating further APIs to expand your project's functionality.