Claude Code MCP: A Practical Tutorial

Alex18 Expert 1h ago Updated Jul 26, 2026 534 views 5 likes 1 min read

Connecting an AI model to custom internal APIs or databases no longer requires writing bespoke integrations for every single tool. The Model Context Protocol (MCP) acts as the "USB-C" of the LLM world, providing a standardized way to expose tools and data to clients like Claude Code. I managed to get a custom server up and running in about 10 minutes using Python.

Project Setup

I used uv for this because it's significantly faster than standard pip for managing environments.

uv init word-count-mcp
cd word-count-mcp
uv add "mcp[cli]"

Implementation

The official SDK makes the deployment straightforward. You just need a single file to define your logic. The key is using type hints and docstrings; the SDK uses these to generate the schema that tells the LLM exactly how to use the tool.

Create server.py:

from mcp.server.fastmcp import FastMCP

mcp = FastMCP("word-count")

@mcp.tool()
def word_count(text: str) -> dict:
 """Count the words, characters, and lines in a block of text.

 Args:
 text: The text to analyze.
 """
 words = text.split()
 return {
 "words": len(words),
 "characters": len(text),
 "characters_no_spaces": len("".join(text.split())),
 "lines": len(text.splitlines()),
 }

if __name__ == "__main__":
 mcp.run(transport="stdio")

Connecting to Claude Code

Since this is a stdio-based server, it stays idle until a client connects via stdin/stdout. To link this to your AI workflow, register it directly within the Claude Code CLI:

claude mcp add word-count -- uv run --directory "$(pwd)" server.py

The command following the -- tells Claude exactly how to execute the server. Once registered, the model can autonomously decide when to call the word_count tool based on the user's prompt. This is a highly efficient way to build a custom LLM agent without the overhead of managing complex API endpoints.

ClaudeLLMmcpLarge Language Model

All Replies (4)

N
Nova25 Novice 9h ago
used this for my postgres db last week, saves so much manual querying.
0 Reply
R
Riley82 Advanced 9h ago
Worth mentioning that setting up the environment variables can be a bit finicky at first.
0 Reply
R
Riley2 Advanced 9h ago
@Riley82 For sure. I spent an hour fighting with my zshrc before it finally clicked.
0 Reply
Q
QuinnPilot Novice 9h ago
Finally got my legacy Jira docs piped in via MCP; way faster than copy-pasting snippets.
0 Reply

Write a Reply

Markdown supported