AI-101

Lesson 25

MCP Integration

AI Confidence: 90%

AI-generated

MCP Integration

Learning Objectives

Understand what MCP is and why it matters

Configure MCP servers in Claude Code

Use MCP tools from external services

Access MCP resources (files, databases, APIs)

Know the security considerations of MCP

Introduction

Model Context Protocol (MCP) is an open standard that lets AI assistants connect to external tools and data sources. With MCP, Claude Code can access databases, APIs, file systems, and services beyond what comes built in.

Think of MCP as a plugin system. Someone builds an MCP server that exposes capabilities. You configure Claude Code to connect to that server. Now Claude has new tools.

This lesson teaches you how to use MCP with Claude Code.

What MCP Provides

MCP servers can provide three things:

Tools - Actions Claude can take. A Slack MCP server might provide send_message and search_channels tools. A database server might provide query and insert tools.

Resources - Data Claude can read. A file system server provides file contents. A GitHub server provides repository data. Resources appear like files Claude can access.

Prompts - Pre-built instructions. Some MCP servers include prompts that help Claude use the tools effectively.

When you connect an MCP server, its tools appear alongside Claude Code's built-in tools. Claude can use them just like Bash or Edit.

Configuring MCP Servers

MCP servers are configured in your settings file.

Project-level (recommended):

Create .claude/mcp.json in your project:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

User-level:

Add to ~/.claude/settings.json:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Configuration fields:

command - The executable to run

args - Arguments passed to the command

env - Environment variables for the server

cwd - Working directory (optional)

Common MCP Servers

Several MCP servers are widely used:

Filesystem:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Provides file read/write access. Useful for accessing directories outside your project.

PostgreSQL:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Provides SQL query capabilities against your database.

Slack:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Send messages, search channels, read history.

GitHub:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Manage issues, PRs, repositories.

Brave Search:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Web search capabilities.

Using MCP Tools

Once configured, MCP tools appear as available actions. Use them naturally:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop
[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop
[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Claude invokes the MCP tool just like a built-in tool. You see the tool name and inputs, and can approve or deny.

Listing available tools:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Claude lists the connected servers and their tools.

Using MCP Resources

MCP resources appear as readable content:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop
[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Resources provide context without you having to copy-paste data into the conversation.

Permission Control for MCP

MCP tools follow the same permission system as built-in tools.

Allow rules:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Deny rules:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

In auto mode:

MCP tools are evaluated by the safety classifier just like Bash commands. Risky operations still require approval.

In default mode:

Claude asks before using MCP tools unless you have allow rules.

Running Your Own MCP Server

MCP is an open protocol. You can build custom servers for internal tools.

Basic server structure:

An MCP server is a process that speaks JSON-RPC over stdio. You implement handlers for:

list_tools - Return available tools

call_tool - Execute a tool

list_resources - Return available resources

read_resource - Return resource content

SDKs exist for Python, TypeScript, and other languages to simplify implementation.

Example use cases:

Internal API wrapper

Custom database interface

Proprietary system integration

Company-specific workflow tools

Building custom servers is advanced but powerful for enterprise integration.

Security Considerations

MCP servers have significant access. Consider carefully:

Server trust:

Only run MCP servers you trust. A malicious server could expose data or take harmful actions.

Environment variables:

Secrets like API keys go in the MCP config. Keep your settings file private.

Permission rules:

Use deny rules to block dangerous MCP operations:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Network access:

MCP servers may make network requests. Audit what servers connect to.

Scope appropriately:

Use project-level MCP config when possible. Avoid exposing production credentials globally.

Troubleshooting MCP

Server does not start:

Check that the command exists and is executable:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Tools not appearing:

Restart Claude Code after changing MCP config:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Permission errors:

Check environment variables are set correctly and the server has necessary access.

Debug mode:

Check Claude Code logs for MCP connection errors:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop
Practical Examples

Database exploration:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop
[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Cross-system workflow:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

External file access:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Research and search:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop
Key Takeaways

MCP is an open protocol for connecting AI to external tools

Configure MCP servers in .claude/mcp.json or settings.json

Servers provide tools (actions), resources (data), and prompts

Common servers include filesystem, database, Slack, and GitHub

MCP tools follow the same permission system as built-in tools

Use deny rules to block dangerous operations

Only run trusted MCP servers

Restart Claude Code after changing MCP config

Try It Yourself

Set up a simple MCP server:

Create .claude/mcp.json in your project:

[@portabletext/react] Unknown block type "codeBlock", specify a component for it in the `components.types` prop

Create the test directory: mkdir -p /tmp/mcp-test

Add a test file: echo "Hello from MCP" > /tmp/mcp-test/greeting.txt

Start Claude Code in your project.

Ask: what MCP servers are connected?

Ask: read the greeting.txt file from the MCP filesystem

Ask: write a new file called test.txt with any content

Verify the file was created: cat /tmp/mcp-test/test.txt

Delete the MCP config and test directory when done.

This exercise shows MCP server configuration and usage.

Sources

https://code.claude.com/docs/en/mcp - Claude Code MCP documentation

https://modelcontextprotocol.io/introduction - MCP protocol specification

https://code.claude.com/docs/en/mcp#using-mcp-servers - Server configuration guide