Articles

How to Use Model Context Protocol (MCP) with Claude

Learn how to use Model Context Protocol (MCP) with Claude desktop to standardize connections between AI and external tools like GitHub and Slack using this step-by-step guide.

Have you ever felt overwhelmed by the complexity of configuring different tools and APIs while building AI agents? Imagine if there were a standardized way for the large language models (LLMs) to connect to the tools and APIs? That’s exactly what Anthropic’s model context protocol (MCP) is designed to do.

This article will discuss what the model context protocol is and why we need it. We will also discuss the MCP architecture to understand how MCP works. Finally, we will discuss a hands-on example using the Claude Desktop app, GitHub MCP server, and Slack MCP server to build an application that fetches data from a GitHub repository, creates reports, and provides updates in a Slack channel.

What is the model context protocol (MCP)?

Model context protocol (MCP) is a standardized protocol introduced by Anthropic that lets LLM applications connect to databases, external tools, and APIs using a uniform interface.

Similar to how OpenAPI standardizes HTTP APIs or JSON Schema standardizes JSON data, Anthropic’s MCP provides a formal standard for communication between MCP clients and servers by defining standardized requests and responses.

Think of MCP as a USB-C port for AI applications that helps them access different tools, databases, and APIs using a standardized interface created by Anthropic.

Related Course

Introduction to Claude Analysis

Utilize Claude for data insights by managing CSV files, handling data, performing statistical analysis, using natural language queries, and creating visualizations.Try it for free

Why do we need model context protocol?

If we can build AI agents that can access data and tools using APIs, why do we need MCP?

We need to integrate different tools while building AI systems using APIs. Each tool or API has a unique interface with separate code, documentation, and authentication methods.

  • We need to write custom integrations to integrate different tools and APIs into our LLM applications, which makes the development process lengthy and error-prone.
  • Integrating all the tools manually into an LLM application also makes it challenging to keep up with maintenance and updates.
  • The developers write their own prompt and method descriptions to access the same tool, which might lead to inconsistent development practices across teams.

To avoid manual integration, updates, and maintenance, we can use model context protocol that provides a uniform and standard interface to different tools and resources.

Let’s discuss the model context protocol architecture to understand how that works.

Understanding the model context protocol architecture

The model context protocol architecture enables us to integrate data sources and external tools into LLM applications in a standard way without worrying about security and compliance.

The general architecture of an AI application with model context protocol looks as follows:

MCP Architecture

The host, MCP client, MCP server, tools, databases, and external APIs constitute major components of the MCP architecture. Let’s discuss each element individually.

Host

Hosts are applications like Claude desktop, IDEs like VS Code, or standalone applications that want to access data or tools through MCP. The hosts create and manage MCP clients, enforce security policies, handle consent and authorization requests, and manage the application context to coordinate between different MCP clients.

MCP client

MCP clients are connectors within the hosts. They maintain 1:1 stateful sessions with MCP servers and implement the client side of the model context protocol. You can think of MCP clients as AI agents that want to access external data and tools. They are responsible for selecting which tool to use, querying MCP servers for resources, and generating prompts for the LLM applications. If a client is MCP compatible, it can connect to any MCP server to access its data and tools.

The MCP client and server support protocol version compatibility negotiation, tools discovery, resource management, prompt handling, and sampling support for model interactions.

MCP server

MCP servers expose tools and resources to the client using the model context protocol. Servers don’t implement complex functionalities on their own. They work as a coordination layer between the MCP client and databases, tools, or APIs to facilitate tasks.

Each MCP server has a fixed number of tools and responsibilities. Once a server is built, any MCP client can connect to it to access the tools and resources provided by the server. The server provides all the tools with descriptions to the MCP client, and the client decides when to use them.

Examples of MCP servers include GitHub MCP, GitLab MCP, Slack MCP, Brave search MCP, and Google Maps MCP. Many companies have launched pre-built MCP servers that we can plug into our LLM applications to perform all the tasks we perform using APIs.

  • In the first interaction between the MCP client and the server, the server and client establish protocol version compatibility. They also share details about their capabilities and implementation.
  • After initialization, the MCP client and the server exchange messages for different tasks according to the protocols and capabilities agreed upon during the first interaction.
  • When we close the host application, the MCP client terminates the connections to the server.

Databases, APIs, and Tools

MCP servers can access the databases, APIs, and tools to perform tasks. An MCP server can access one or more data sources, tools, and APIs.

Now that we have a brief understanding of the model context protocol and the MCP architecture, let’s discuss configuring and using GitHub and Slack MCP servers with Claude desktop as the host application.

How to use MCP servers with Claude desktop?

To use MCP servers with the Claude desktop, you must first install the Claude desktop app. If you haven’t already, download and install the Claude desktop app. We also need Node.js to use MCP servers. If you don’t have Node installed on your machine, you must download and install Node.js too.

With Claude desktop and Node.js installed, let’s discuss how to integrate the GitHub MCP server with Claude desktop.

Integrating GitHub MCP server with Claude desktop

To integrate the GitHub MCP server with the Claude desktop, we need a personal access token associated with our GitHub account. If you don’t have a personal access token or don’t know how to create one, you can read the first article in the GitHub privacy, security, and administration course to get the same. After getting the personal access token, we can configure the GitHub MCP server on the Claude desktop.

After launching the Claude desktop app and logging in, we get a new chat screen. At the top left of the chat screen, we get a hamburger menu icon.

Claude homepage

When we click on the hamburger menu icon, we get a file menu as follows:

File menu

Click on the File button. Next, we get a menu with the Settings button:

Settings button

Click on the Settings button. This takes us to the settings page.

Settings page

We get a Developer tab on the settings page. When we click on the Developer button, it takes us to the following page with the Edit Config button.

Develper settings page

Click on the Edit Config button. After this, the Claude desktop app sends us to the directory where the cloud_desktop_config.json file is stored. We need to update the config file to configure the GitHub MCP server.

When we open the JSON file in a text editor like Notepad for the first time, it contains an empty JSON object.

Empty config file

After updating the personal access token, you can paste the following configuration into this config file.

{
"mcpServers": {
"github": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-github"
],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "your_personal_access_token"
}
}
}
}

After pasting the above JSON data, the file should look as follows.

GitHub MCP Configured JSON

Save the file and close it. Then, restart the Claude desktop app.

After restarting the Claude desktop app, we get the chat page with a slightly changed interface with a menu in place of the Use style button.

Claude homepage after MCP integration

The menu contains a list of all the MCP servers. If you click on the menu button, we get a list, as shown below:

GitHub MCP list

You can see that GitHub is on the list. Hence, we have successfully integrated GitHub MCP with Claude desktop. You can get a list of all the tools in the GitHub MCP server by clicking on github in the list.

GitHub MCP tools list

To check if the integration actually works, let’s ask Claude AI to fetch the status of a pull request from the Codecademy/Docs GitHub Repo. You can ask for the details of a pull request from any repository you can access.

GitHub MCP instruction

When we hit enter after typing the instruction, the Claude desktop app asks permission to use tools from the GitHub MCP server.

GitHub MCP permissions popup

After providing permissions, Claude fetches the pull request status from the GitHub repository.

GitHub MCP result

Thus, we have successfully integrated the GitHub MCP server with the Claude desktop app. Now, we can create issues, approve pull requests, and perform other tasks the GitHub personal access token allows through the Claude desktop app.

Now, let’s integrate the Slack MCP server into the Claude desktop app. This will enable us to send updates about the GitHub activities to Slack channels.

Integrating Slack MCP with Claude desktop

For integrating Slack MCP to Claude desktop, we need a Slack app with a bot token starting with characters xoxb. If you don’t have a Slack app for your workspace, you can create one using the Slack app quickstart.

Along with the bot token, we also need the workspace ID and the channel ID for sending messages to Slack. To get the workspace ID and the channel ID, open the Slack channel in a browser. In the browser, any channel will open with the URL https://app.slack.com/client/workspace_id/channel_id, as shown in the following image:

Slack URL

You can copy the workspace ID and the channel ID from the URL. Next, we will add Slack MCP to the Claude desktop app. To do this, open the cloud_desktop_config.json file using the steps discussed while configuring the GitHub MCP. The file should have only the GitHub MCP configuration, as follows:

Config file with GitHub MCP

We need to add the following config to the mcpServers attribute in the configuration file.

"slack": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-slack"
],
"env": {
"SLACK_BOT_TOKEN": "xoxb-your-bot-token",
"SLACK_TEAM_ID": "workspace_id",
"SLACK_CHANNEL_IDS": "channel_1_id, channel_2_id"
}
}

The updated JSON file should look as follows:

Config file with slack configuration

After saving the details, close the config file and restart the Claude desktop app.

Now, if you click on the menu icon in the chat, we get slack along with github in the servers list.

GitHub Slack Dropdown

If you click on slack, we get a list of all the tools in the Slack MCP server.

Slack tools list

Let’s check if the Slack MCP server has been properly configured. To do so, let’s post a message using the Claude desktop app in the #updates channel of the Slack Codecademy workspace.

Slack MCP instruction

Once we hit enter, a pop-up asks permission to post the message.

Slack permissions popup

After giving permissions, we get the following output.

Slack message Claude output

If we go to the #updates channel in Slack, we can see that the bot has posted the message.

Slack message in channel

Thus, we have successfully integrated the Slack MCP server with the Claude desktop. Now, let’s combine the GitHub MCP and Slack MCP for a task.

Working with GitHub and Slack MCP servers on Claude desktop

As we have configured the GitHub and Slack MCP servers in the Claude desktop app, it will automatically decide what tools to use for a given task. If the task requires fetching any information from GitHub, the app will automatically use the tools defined in the GitHub MCP server. Similarly, if the app needs to post any message to Slack, it will automatically connect to the Slack MCP server.

To check this, let’s ask Claude AI to fetch the status of a pull request and send it to the #updates channel in Slack.

GitHub Slack MCP instruction

While processing this instruction, you might get popups for permissions. After giving permissions and executing the above instruction, we get the following output in Claude.

GitHub Slack output in Claude

When we go to the #updates channel in Slack, we can see the status message the bot sent.

GitHub Slack Message Output

Thus, we have successfully integrated GitHub and Slack MCP servers into the Claude desktop app and used them for our tasks.

Conclusion

Anthropic’s Model Context Protocol (MCP) provides a standardized way for creating intelligent, context-aware interactions between LLM applications and various external tools. With MCP, Claude and other AI applications can dynamically discover and identify which tools to use for a given task. This helps developers avoid the hassle of individually integrating tools into AI applications, resulting in improved development time and reduced maintenance.

You can go through the Introduction to Claude artifacts course to learn more about generative AI tools. You might also like this Introduction to Claude analysis course that discusses utilizing Claude for data insights by managing CSV files, handling data, performing statistical analysis, using natural language queries, and creating visualizations.

Frequently asked questions

1. Why do we use MCP?

Model Context Protocol (MCP) is used to connect LLM applications with external tools like GitHub, Slack, and APIs through a standardized interface created by Anthropic, eliminating the need for custom integrations.

2. Can Chatgpt use MCP?

No. ChatGPT doesn’t use MCP.

3. How is MCP different from RAG?

MCP is a standardized interface for LLM applications to interact with external tools and APIs. Retrieval-Augmented Generation (RAG) enhances the capabilities of LLM applications by retrieving relevant information from databases and other external sources before generating a response.

  • RAG first retrieves relevant documents from a database or external API using a retriever model. Then, it uses a large language model to generate the response using content from the retrieved documents.
  • MCP helps the AI agents choose what tools to use while generating real-time responses. For a given task and the current context, the agents analyze the requirements and decide on which tool to use through MCP.

4. What’s the difference between MCP and API?

MCP is a specific protocol for interactions between LLM applications and external tools. API consists of rules and protocols that we use to implement data transfer and communication between software applications.

5. What is the difference between the model context protocol and LangChain?

LangChain is an open-source framework that helps us build applications with LLMs by providing tools for implementing prompt templates, memory, and agents. The model context protocol helps AI agents communicate with MCP servers to access external tools and APIs.

Codecademy Team

'The Codecademy Team, composed of experienced educators and tech experts, is dedicated to making tech skills accessible to all. We empower learners worldwide with expert-reviewed content that develops and enhances the technical skills needed to advance and succeed in their careers.'

Meet the full team