2025.01.14

Implementing MCP in Claude Desktop

こんにちは、次世代システム研究室のN.M.です。

 

Claude’s Model Context Protocol (MCP) is an open standard that streamlines how AI models connect with external data and tools using a client-server setup.

Key Features of MCP

  • Standardized Communication: Utilizes JSON-RPC 2.0 for consistent messaging between AI models and data sources.
  • Flexible Transport Methods: Supports various communication methods, including standard input/output for local processes and HTTP with Server-Sent Events for remote connections.
  • Resource Management: Efficiently handles both local and remote resources through a unified interface.

Setting Up MCP with Claude Desktop

To set up MCP, ensure you have the following prerequisites:

Claude Desktop Application: Download and install the latest version compatible with your operating system (Windows or macOS).

Node.js: Install Node.js version 20.x or later from the [official website](https://nodejs.org/). After installation, verify by running node –version and npm –version in your command line interface.

Python: For Python-based MCP servers, install Python version 3.10 or later from [python.org](https://www.python.org/downloads/). During installation, ensure you add Python to your system’s PATH. Verify the installation by running python –version.

Package Managers:

  • npm: Included with Node.js, used for managing Node.js-based server packages.
  • pip: Included with Python, used for managing Python-based server packages.

uv Tool: Install the uv tool globally using npm:

npm install -g uv

Verify the installation by running uv –version.

Text Editor: Have a text editor ready for editing configuration files. Options include Visual Studio Code, Sublime Text, or any editor you’re comfortable with.

Administrative Privileges: Ensure you have administrative rights on your system to install software and modify system configurations.

Optional: Docker for Running Server Containers

If you prefer to run MCP servers within isolated environments, installing Docker is recommended:

  • Docker: Install Docker Desktop or some type of Docker engine to manage containerized MCP servers. This approach simplifies setup by encapsulating server dependencies within containers. Download Docker from [docker.com](https://www.docker.com/get-started). After installation, verify by running docker –version.

I used colima for this with no problems.

Once these prerequisites are in place, proceed with configuring MCP servers and integrating them with Claude Desktop. Detailed setup instructions can be found in the [official documentation](https://modelcontextprotocol.io/quickstart/server).

Configuring MCP Servers

In general, configuring is done as follows.

Edit Configuration File: Locate and edit the claude_desktop_config.json file in your system’s application support directory to define the MCP servers you want to integrate. For example, to add a filesystem server:

{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-filesystem",
        "/Users/yourusername/Desktop",
        "/Users/yourusername/Downloads"
      ]
    }
  }
}

Ensure the specified directories exist and that Node.js is installed on your system.

Restart Claude Desktop: After updating the configuration file, restart the application to apply the changes. You should see a hammer icon in the input box, indicating the availability of MCP tools.

Use MCP Tools: You can now instruct Claude to perform tasks that utilize the integrated MCP servers. For instance, asking Claude to save a document to your desktop will prompt it to use the filesystem server to execute the action.

In my claude_desktop_config.json, I configured several Model Context Protocol (MCP) servers to enhance Claude’s capabilities. Here’s an overview of each server and the allowDevTools option:

{
  "mcpServers": {
    "brave-search": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "BRAVE_API_KEY",
        "mcp/brave-search"
      ],
      "env": {
        "BRAVE_API_KEY": "YOUR_BRAVE_API_KEY"
      }
    },
    "filesystem": {
      "command": "/path/to/node",
      "args": [
        "/path/to/node_modules/@modelcontextprotocol/server-filesystem/dist/index.js",
        "/Users/yourusername/Desktop",
        "/Users/yourusername/Downloads"
      ]
    },
    "puppeteer": {
      "command": "/path/to/node",
      "args": [
        "/path/to/node_modules/@modelcontextprotocol/server-puppeteer/dist/index.js"
      ]
    },
    "sqlite": {
      "command": "uv",
      "args": [
        "--directory",
        "/path/to/servers/src/sqlite",
        "run",
        "mcp-server-sqlite",
        "--db-path",
        "/path/to/.data/test.db"
      ]
    },
    "fetch": {
      "command": "uv",
      "args": [
        "--directory",
        "/path/to/servers/src/fetch",
        "run",
        "mcp-server-fetch"
      ]
    },
    "memory": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-v",
        "/path/to/.memory:/app/memory",
        "-e",
        "MEMORY_FILE_PATH=/app/memory/memory.json",
        "mcp/memory"
      ]
    }
  },
  "allowDevTools": true
}

 

Note: I had already checked out the servers repository: https://github.com/modelcontextprotocol/servers
– This is referenced by the /path/to/servers in the configuration file.
– This is where I was able to fix the memory server persistence.

Configured MCP Servers

Brave Search:

  • Purpose: Enables web and local search capabilities using Brave’s Search API.
  • Configuration: Runs within a Docker container, utilizing the BRAVE_API_KEY for authentication.
  • Prerequisite: You will need to register for a Brave API key to use this server. Credit card information is required for registration. The first 2000 requests/month are free, after which you will be charged.
  • Troubleshooting: I tried to use a brave search server running on the host, but couldn’t get it to start, so I used the docker container.
  • Usage: Allows Claude to perform searches and retrieve information from the web.

Filesystem:

  • Purpose: Provides secure file operations with configurable access controls.
  • Configuration: Executed via Node.js, granting access to specified directories like /Users/yourusername/Desktop and /Users/yourusername/Downloads.
  • Usage: Enables Claude to read from and write to your local file system, facilitating tasks such as file manipulation.
  • Security: In Claude Desktop all MCP actions require user approval. The image below shows an approval request for a file move operation by the filesystem server.

Puppeteer:

  • Purpose: Facilitates browser automation and web scraping.
  • Configuration: Runs through Node.js, leveraging Puppeteer for headless browser interactions.
  • Usage: Allows Claude to automate web page interactions, extract information, and perform web-based tasks, with access via the Javascript APIs.

SQLite:

  • Purpose: Provides database interaction.
  • Configuration: Launched using the python uv tool, specifying the working directory and database path.
  • Usage: Enables Claude to query and interact with SQLite databases, supporting data retrieval and analysis.
    • The image below shows me asking about the tables in a database I configured with the sqlite server. Here we can see that it checks the memory plugin first, finds no relevant data there and then uses sqlite.

Fetch:

  • Purpose: Enables web content fetching and conversion for efficient large language model (LLM) usage.
  • Configuration Started with the uv tool, pointing to the appropriate directory.
  • Usage: Allows Claude to fetch web content and convert it into a format suitable for processing, such as Markdown.
    • The image below shows results of fetching top articles from Hacker News website

Memory:

  • Purpose: Implements a knowledge graph-based persistent memory system.
  • Configuration:
    • Operates within a Docker container, mounting a local directory to persist memory data between the container restarts.
    • Requires a special system prompt that can be set in Claude Desktop’s Personal Preferences, in Settings/Profile
  • Usage: Provides Claude with a persistent memory, enabling it to retain information across sessions.
  • Troubleshooting:
    • Similar to the brave search server, I switched use the docker container to get a running server.
    • I had to mount a local directory to persist memory data, which was not initially configured.
    • I had to set the MEMORY_FILE_PATH environment variable to the memory file path and change the server code to use the environment variable:
const MEMORY_FILE_PATH = process.env.MEMORY_FILE_PATH || path.join(__dirname, 'memory.json');

 

  • Then rebuild the docker image:
docker build -t mcp/memory -f src/memory/Dockerfile .

allowDevTools Option

  • Purpose: The allowDevTools setting, when set to true, enables the Developer Tools (DevTools) within Claude Desktop.
  • Usage: This feature is beneficial for debugging and inspecting the interactions between Claude and the configured MCP servers. It allows you to monitor network activity, view console logs, and troubleshoot issues effectively.
  • Note:
    • To be able to view DevTools you need to select the dev option in Claude Desktop
    • Shift + Alt + Command + I (macOS) brings up the DevTools.
    • I used this to debug the brave search server, and was able to view the DevTools console to see that Claude Desktop was unable to connect to the server running on the host.
    • I checked running processes and found that the server was not running, so I switched to the docker container.
    • The image below shows the 2 DevTool windows, where you can do trouble shooting.

By configuring these servers and enabling DevTools, you can significantly extended Claude’s functionality, allowing it to interact seamlessly with various tools and data sources and perform complex tasks efficiently.

Available MCP Servers

The Model Context Protocol offers a variety of servers that extend AI capabilities by providing access to different tools and data sources. Here are some notable servers:

  • Filesystem: Secure file operations with configurable access controls
  • Git: Tools to read, search, and manipulate Git repositories
  • GitHub: Repository management, file operations, and GitHub API integration
  • Google Drive: File access and search capabilities for Google Drive
  • Google Maps: Location services, directions, and place details
  • Memory: Knowledge graph-based persistent memory system
  • PostgreSQL: Read-only database access with schema inspection
  • Puppeteer: Browser automation and web scraping
  • Slack: Channel management and messaging capabilities
  • Sqlite: Database interaction and business intelligence capabilities
  • Time: Time and timezone conversion capabilities.

These servers demonstrate MCP’s versatility in extending AI functionalities across various domains. For a comprehensive list and detailed information, visit the Model Context Protocol Servers repository.

 

Debugging

In addition to the DevTools option already discussed, you can tail the logs of Claude Desktop:

tail -n 20 -f ~/Library/Logs/Claude/mcp*.log

You can also test the MCP servers directly through an API client:

npx @modelcontextprotocol/inspector node ~/.asdf/installs/nodejs/20.3.1/.npm/lib/node_modules/@modelcontextprotocol/server-brave-search/dist/index.js

or for a python server:

➜ npx @modelcontextprotocol/inspector uv --directory src/fetch run mcp-server-fetch

Benefits of MCP

  • Enhanced AI Capabilities: By integrating various tools and data sources, MCP allows AI models to perform a wider range of tasks, from file manipulation to web scraping
  • Simplified Development: MCP’s standardized protocol makes it easier to connect AI models with external resources, reducing the complexity and time required for agent development and integration.

In summary, Claude’s Model Context Protocol streamlines the integration between AI models and external tools, enhancing functionality. Implementing MCP can lead to more efficient and capable AI applications.

 

次世代システム研究室では、グループ全体のインテグレーションを支援してくれるアーキテクトを募集しています。インフラ設計、構築経験者の方、次世代システム研究室にご興味を持って頂ける方がいらっしゃいましたら、ぜひ募集職種一覧からご応募をお願いします。

  • Twitter
  • Facebook
  • はてなブックマークに追加

グループ研究開発本部の最新情報をTwitterで配信中です。ぜひフォローください。

 
  • AI研究開発室
  • 大阪研究開発グループ

関連記事