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:
# 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:
# 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-mcpWhen you run claude mcp add, Claude Code automatically:
- Creates the configuration file if it doesn't exist
- Adds the server entry with the correct format
- 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:
{
"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
| Field | Required | Description |
|---|---|---|
command | Yes | Executable to run (npx, node, python, etc.) |
args | Yes | Arguments passed to the command |
env | No | Environment variables for the server process |
cwd | No | Working directory for the server |
Method 3: Project-Specific Configuration
For project-specific MCP servers, create a .mcp.json file in your project root:
{
"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.jsonto 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:
# 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 defaultVerify the server is running:
curl http://127.0.0.1:3030/health
# Response: {"status":"ok"}Step 2: Add the MCP Server to Claude Code
# 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-codeOr manually add to your settings.json:
{
"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:
# Exit Claude Code (Ctrl+C or type /exit)
# Then restart
claudeStep 4: Test the Memory Tools
Once connected, Claude has access to memory tools. Try these commands:
> 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:
| Tool | Description |
|---|---|
remember | Store a new memory with content, type, and optional tags |
recall | Semantic search for relevant memories |
context_summary | Get categorized summary of recent learnings and decisions |
list_memories | List all stored memories |
forget | Delete a specific memory by ID |
memory_stats | Get statistics about stored memories |
recall_by_tags | Search memories by tags |
recall_by_date | Search memories within a date range |
forget_by_tags | Delete memories matching tags |
forget_by_date | Delete memories within a date range |
Memory Types for Better Organization
When storing memories, you can specify types to help with retrieval and prioritization:
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 pointsPractical Examples
Example 1: Project Onboarding
When starting work on a new project, Claude can build up context that persists:
> 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
> 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
> 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 fasterTroubleshooting Common Issues
Server Connection Failed
# 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:
- Ensure the server is running before starting Claude Code
- Check for typos in the configuration file
- Verify the
argsarray is correctly formatted - Look for error messages in Claude Code's output
Permission Errors
# 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 connectionsSecurity 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:
| Server | Package | Use Case |
|---|---|---|
| GitHub | @modelcontextprotocol/server-github | Repository operations, issues, PRs |
| Filesystem | @modelcontextprotocol/server-filesystem | Read/write files (sandboxed) |
| PostgreSQL | @modelcontextprotocol/server-postgres | Database queries |
| Brave Search | @modelcontextprotocol/server-brave-search | Web search |
| Puppeteer | @modelcontextprotocol/server-puppeteer | Browser automation |
| Linear | @linear/mcp-server | Issue 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:
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.