Back to Blog
Tutorial

How to Set Up MCP Servers in Claude Code: Complete Guide

December 9, 202510 min readBy Shodh Team · Developer Experience
claude-codeMCPtutorialAI-agentsdeveloper-tools

Claude Code is Anthropic's powerful CLI tool that brings Claude directly into your terminal. But its true power unlocks when you connect it to MCP (Model Context Protocol) servers—giving Claude access to external tools, databases, and services. This guide walks you through setting up MCP servers from scratch, with a practical example using Shodh Memory for persistent AI memory.

What is MCP (Model Context Protocol)?

MCP is an open protocol that allows AI assistants like Claude to securely connect to external data sources and tools. Think of it as a USB standard for AI—a universal way to plug capabilities into your AI assistant.

With MCP servers, Claude Code can:

  • Remember across sessions — Store and recall information persistently
  • Access databases — Query PostgreSQL, MongoDB, or custom data stores
  • Integrate with APIs — Connect to GitHub, Linear, Slack, and more
  • Execute specialized tools — Run domain-specific operations

Prerequisites

Before starting, ensure you have:

  • Claude Code installed (npm install -g @anthropic-ai/claude-code)
  • Node.js 18+ (for running MCP servers)
  • A working terminal (macOS, Linux, or Windows with WSL)

Understanding MCP Configuration

Claude Code uses a JSON configuration file to know which MCP servers to connect to. The location depends on your platform:

Configuration Locationstext
# macOS
~/.config/claude-code/settings.json

# Linux
~/.config/claude-code/settings.json

# Windows
%APPDATA%\claude-code\settings.json

# Project-specific (any platform)
./.mcp.json  (in your project root)

Method 1: Using the CLI (Recommended)

The easiest way to add MCP servers is through Claude Code's built-in commands:

Terminalbash
# Add an MCP server from npm
claude mcp add @shodh/memory-mcp

# Add with custom configuration
claude mcp add @shodh/memory-mcp --env SHODH_API_URL=http://localhost:3030

# List configured servers
claude mcp list

# Remove a server
claude mcp remove @shodh/memory-mcp

When you run claude mcp add, Claude Code automatically:

  1. Creates the configuration file if it doesn't exist
  2. Adds the server entry with the correct format
  3. Validates the server can be started

Method 2: Manual Configuration

For more control, you can edit the configuration file directly. Here's the complete structure:

settings.jsonjson
{
  "mcpServers": {
    "shodh-memory": {
      "command": "npx",
      "args": ["-y", "@shodh/memory-mcp"],
      "env": {
        "SHODH_API_URL": "http://127.0.0.1:3030",
        "SHODH_API_KEY": "your-api-key-here",
        "SHODH_USER_ID": "claude-code"
      }
    },
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_xxxxxxxxxxxx"
      }
    },
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/allowed/dir"]
    }
  }
}

Configuration Fields Explained

FieldRequiredDescription
commandYesExecutable to run (npx, node, python, etc.)
argsYesArguments passed to the command
envNoEnvironment variables for the server process
cwdNoWorking directory for the server

Method 3: Project-Specific Configuration

For project-specific MCP servers, create a .mcp.json file in your project root:

.mcp.jsonjson
{
  "mcpServers": {
    "project-memory": {
      "command": "npx",
      "args": ["-y", "@shodh/memory-mcp"],
      "env": {
        "SHODH_API_URL": "http://127.0.0.1:3030",
        "SHODH_USER_ID": "my-project"
      }
    }
  }
}

Project-specific servers are only available when Claude Code is running in that directory. This is useful for:

  • Project-specific databases or APIs
  • Different configurations per project
  • Sharing MCP setup with your team (commit .mcp.json to git)

Setting Up Shodh Memory Server

Let's walk through a complete example: adding persistent memory to Claude Code using Shodh Memory. This gives Claude the ability to remember information across sessions—preferences, project context, decisions, and learnings.

Step 1: Start the Shodh Memory Server

First, download and run the Shodh Memory server. You can use the pre-built binary or run from source:

Terminalbash
# Option A: Using pre-built binary (recommended)
# Download from: https://github.com/varun29ankuS/shodh-memory/releases

# macOS/Linux
chmod +x shodh-memory-server
./shodh-memory-server

# Windows
shodh-memory-server.exe

# Option B: From source
git clone https://github.com/varun29ankuS/shodh-memory
cd shodh-memory
cargo run --release

# Server starts on http://127.0.0.1:3030 by default

Verify the server is running:

Terminalbash
curl http://127.0.0.1:3030/health
# Response: {"status":"ok"}

Step 2: Add the MCP Server to Claude Code

Terminalbash
# Using the CLI
claude mcp add @shodh/memory-mcp \
  --env SHODH_API_URL=http://127.0.0.1:3030 \
  --env SHODH_API_KEY=your-api-key \
  --env SHODH_USER_ID=claude-code

Or manually add to your settings.json:

settings.jsonjson
{
  "mcpServers": {
    "shodh-memory": {
      "command": "npx",
      "args": ["-y", "@shodh/memory-mcp"],
      "env": {
        "SHODH_API_URL": "http://127.0.0.1:3030",
        "SHODH_API_KEY": "sk-shodh-dev-4f8b2c1d9e3a7f5b6d2c8e4a1b9f7d3c",
        "SHODH_USER_ID": "claude-code"
      }
    }
  }
}

Step 3: Restart Claude Code

After configuring, restart Claude Code to load the new MCP server:

Terminalbash
# Exit Claude Code (Ctrl+C or type /exit)
# Then restart
claude

Step 4: Test the Memory Tools

Once connected, Claude has access to memory tools. Try these commands:

Claude Codetext
> Remember that I prefer dark mode and use Vim keybindings
[Claude uses the remember tool to store this preference]

> What are my preferences?
[Claude uses the recall tool to search memories]

> Give me a summary of what you know about me
[Claude uses context_summary to get categorized memories]

Available Memory Tools

The Shodh Memory MCP server exposes these tools to Claude:

ToolDescription
rememberStore a new memory with content, type, and optional tags
recallSemantic search for relevant memories
context_summaryGet categorized summary of recent learnings and decisions
list_memoriesList all stored memories
forgetDelete a specific memory by ID
memory_statsGet statistics about stored memories
recall_by_tagsSearch memories by tags
recall_by_dateSearch memories within a date range
forget_by_tagsDelete memories matching tags
forget_by_dateDelete memories within a date range

Memory Types for Better Organization

When storing memories, you can specify types to help with retrieval and prioritization:

Memory Typestext
Observation  — General observations and facts
Decision     — Choices made and their rationale
Learning     — New knowledge acquired
Error        — Mistakes to avoid
Discovery    — Findings from exploration
Pattern      — Recurring behaviors identified
Context      — Session or project context
Task         — Work items and todos
CodeEdit     — Code changes made
FileAccess   — Files accessed
Search       — Search queries performed
Command      — Commands executed
Conversation — Notable conversation points

Practical Examples

Example 1: Project Onboarding

When starting work on a new project, Claude can build up context that persists:

Claude Code Sessiontext
> Explore this codebase and remember the key architectural decisions

[Claude explores and stores memories like:]
- "This project uses Next.js 14 with App Router"
- "Authentication is handled by NextAuth with GitHub OAuth"
- "Database is PostgreSQL accessed via Prisma ORM"
- "Tests use Vitest with React Testing Library"

# Next session, same project:
> What's the tech stack here?

[Claude recalls from memory without re-exploring]

Example 2: User Preferences

Claude Code Sessiontext
> Remember: I prefer functional components over class components,
> use TypeScript strict mode, and always add JSDoc comments to public APIs

[Claude stores as Decision type memories]

# Later, when writing code:
> Create a new React component for user profiles

[Claude automatically applies remembered preferences]

Example 3: Learning from Errors

Claude Code Sessiontext
> The tests are failing with "Cannot find module '@/lib/auth'"

[After investigation]
> Remember: path aliases in this project require tsconfig paths
> to be mirrored in vitest.config.ts

[Claude stores as Error type memory]

# Future similar issues are caught faster

Troubleshooting Common Issues

Server Connection Failed

Debuggingbash
# Check if server is running
curl http://127.0.0.1:3030/health

# Check Claude Code logs
claude --verbose

# Verify configuration
cat ~/.config/claude-code/settings.json | jq .

Tools Not Appearing

If MCP tools don't show up in Claude:

  1. Ensure the server is running before starting Claude Code
  2. Check for typos in the configuration file
  3. Verify the args array is correctly formatted
  4. Look for error messages in Claude Code's output

Permission Errors

Fix Permissionsbash
# Ensure npx can run the package
npx -y @shodh/memory-mcp --help

# If using a local server, check firewall rules
# On macOS, you may need to allow incoming connections

Security Best Practices

  • Use environment variables for API keys, never hardcode them
  • Limit server scope — only expose necessary tools and data
  • Run locally when possible — avoid sending sensitive data to external servers
  • Review MCP server code before using third-party servers
  • Use project-specific configs to isolate different projects

Popular MCP Servers

Beyond Shodh Memory, here are other useful MCP servers:

ServerPackageUse Case
GitHub@modelcontextprotocol/server-githubRepository operations, issues, PRs
Filesystem@modelcontextprotocol/server-filesystemRead/write files (sandboxed)
PostgreSQL@modelcontextprotocol/server-postgresDatabase queries
Brave Search@modelcontextprotocol/server-brave-searchWeb search
Puppeteer@modelcontextprotocol/server-puppeteerBrowser automation
Linear@linear/mcp-serverIssue tracking

Building Your Own MCP Server

MCP servers can be built in any language that supports JSON-RPC over stdio. The official SDK is available for TypeScript/Node.js:

Custom MCP Servertypescript
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";

const server = new Server({
  name: "my-custom-server",
  version: "1.0.0",
}, {
  capabilities: {
    tools: {},
  },
});

// Define a tool
server.setRequestHandler("tools/list", async () => ({
  tools: [{
    name: "my_tool",
    description: "Does something useful",
    inputSchema: {
      type: "object",
      properties: {
        query: { type: "string", description: "The input" }
      },
      required: ["query"]
    }
  }]
}));

// Handle tool calls
server.setRequestHandler("tools/call", async (request) => {
  if (request.params.name === "my_tool") {
    const query = request.params.arguments.query;
    return { content: [{ type: "text", text: `Processed: ${query}` }] };
  }
});

// Start server
const transport = new StdioServerTransport();
await server.connect(transport);

Conclusion

MCP servers transform Claude Code from a powerful assistant into an extensible platform. With persistent memory via Shodh Memory, Claude remembers your preferences, learns from experience, and maintains context across sessions—just like a human colleague would.

The setup takes less than 5 minutes, but the productivity gains compound over time. Every preference remembered, every pattern learned, every error avoided adds up.

Start with the basics: add Shodh Memory for persistent context. Then explore other MCP servers for GitHub integration, database access, or build your own for domain-specific needs.

Blog | Shodh | Shodh RAG