AI Workflows

How to Add MCP Servers to Claude Code

Learn how to configure and use Model Context Protocol (MCP) servers within Claude Code for enhanced AI tool integration.

4 min read

Learn how to configure and integrate MCP (Model Context Protocol) servers like Context 7, DBHub, and GitHub into Claude Code. MCP servers allow the AI to interact with external tools and data sources and enhance its functionality for tasks like querying databases, accessing documentation, or managing repositories.

Prerequisites for Adding MCP Servers

Before you start integrating MCP servers into Claude Code, ensure you have the following:

prerequisites

  • Claude Code Installed: Confirm you have Claude Code set up on your machine.
  • MCP Knowledge: Familiarize yourself with concepts like MCP transports and scopes (local, project, user).
  • Access to MCP Server Docs/APIs: Have server-specific details, such as API keys or endpoints, available.

Adding Context 7 MCP Server

To integrate Context 7, follow these steps to enable AI-assisted access to up-to-date documentation:

steps

  1. Run the Cloud MCP add Command:

    bash
    cloud mcp add --server https://api.context7.com --scope project

    This adds the Context 7 MCP with project-level scope.

  2. Retrieve an API Key:

    • Log into the Context 7 website.
    • Generate an API key intended for "Cloud Code" and copy it.
  3. Update Configuration:

    • Open the .mcp.json file in your project directory.
    • Add the API key under the apiKey property for the Context 7 server.
  4. Enable MCP Discovery:

    • Run Claude Code in your terminal, e.g.,:
      bash
      cloud
    • Approve the addition of MCP configs when prompted.
  5. Test Context 7 Queries:

    • Ask Claude Code for documentation, e.g., "How to install Tailwind CSS in a Next.js project."

Configuring DBHub MCP Server

Integrate DBHub to connect Claude Code with a local or remote database.

steps

  1. Run the Local MCP Add Command:

    bash
    cloud mcp add --server stdio --name DBHub --scope project
  2. Modify MCP Configuration:

    • Open the .mcp.json file and edit the DBHub section:
      json
      {
        "type": "database",
        "transport": "stdio",
        "config": {
          "dsn": "mysql://root@localhost:3306/mydatabase"
        }
      }
    • Replace dsn with your database connection string.
  3. Start Claude Code:

    bash
    cloud
  4. Test Database Queries:

    • Ask Claude Code questions like "List all tables in my database" or "Which product has the highest sales?"

Integrating GitHub MCP Server

Set up GitHub MCP to provide repository management capabilities for Claude Code.

steps

  1. Run the Cloud MCP add Command:

    bash
    cloud mcp add --server https://github.com/mcp --scope project
  2. Generate a Personal Access Token (PAT):

    • Go to GitHub settings > Developer Settings > Personal Access Tokens.
    • Create a fine-grained PAT with the necessary permissions (e.g., "repo", "admin:repo_hook").
  3. Update MCP Configuration:

    • Open the .mcp.json file.
    • Add the following:
      json
      {
        "type": "github",
        "config": {
          "accessToken": "your_personal_access_token"
        }
      }
  4. Verify and Test:

    • Start Claude Code: cloud.
    • Run commands like /mcp fork-repo [repository-url] to test the integration.

Common Mistakes to Avoid

Here are some pitfalls to watch out for during MCP integration:

Verifying MCP Configuration

Once the setup is complete, use these steps to confirm MCP servers are active and functioning:

steps

  1. List Active MCP Servers:

    bash
    cloud mcp list

    Confirm all added servers are displayed.

  2. Test Server Functionality:

    • Query your Context 7 server for documentation, DBHub for database manipulation, or GitHub for repository actions.
  3. Troubleshoot Issues:

    • Review the .mcp.json file for accuracy.
    • Rerun the applicable cloud mcp add command if issues persist.

Summary of MCP Integration Process

FAQ

How do I change the scope of an existing MCP server?

To change the scope, delete the current configuration using cloud mcp remove [server-name], then re-add the server with the desired scope using the --scope option.

Can I use multiple MCP servers simultaneously in Claude Code?

Yes, you can connect to multiple MCP servers simultaneously. Ensure their configurations are accurate and avoid overlapping functions or naming conflicts.

How can I secure my API keys when using MCP servers?

You can store sensitive information like API keys in environment variables instead of directly in the configuration file. Update the .mcp.json file to reference these variables securely.

What happens if an MCP server fails during runtime?

If an MCP server fails, verify its configuration in .mcp.json, check internet connectivity (if remote), and inspect database/path availability if using local transport.


Official reference: Claude Code documentation.