Skip to content
Courses/Agents and automation/Create a Custom MCP Server

Create a Custom MCP Server

Installing public MCP servers is fine for learning. But the useful leap comes when you expose your own tools: search your documentation, validate a repo, query an internal database, or generate a focused report.

  • Design a minimal MCP server with narrow tools.
  • Separate business logic, validation, and MCP transport.
  • Test it before connecting it to Claude Code, Hermes, or another client.
Terminal
# Minimal structure
mcp-debug/
  server.py
  pyproject.toml
  tests/
    test_tools.py

# Useful tool:
# run_lint(project_path) -> runs only allowed commands
# search_docs(query) -> searches a specific folder
Terminal
from mcp.server.fastmcp import FastMCP
from pathlib import Path
import subprocess

mcp = FastMCP("aulafy-debug-tools")
ROOT = Path("/Users/me/proyectos").resolve()

def safe_path(path: str) -> Path:
    target = Path(path).resolve()
    if ROOT not in target.parents and target != ROOT:
        raise ValueError("Path outside the allowed workspace")
    return target

@mcp.tool()
def list_markdown_files(path: str) -> list[str]:
    base = safe_path(path)
    return [str(p.relative_to(base)) for p in base.rglob("*.md")][:100]

@mcp.tool()
def run_lint(path: str) -> str:
    base = safe_path(path)
    result = subprocess.run(
        ["npm", "run", "lint"],
        cwd=base,
        text=True,
        capture_output=True,
        timeout=120,
    )
    return result.stdout[-6000:] + result.stderr[-3000:]

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

Checklist Before Connecting an Agent

  • The tool rejects paths outside the workspace.
  • There is a timeout and output limit.
  • It does not accept arbitrary commands.
  • It logs arguments, decision, and result.
  • It has tests with malicious inputs.

Official Sources

  • Model Context Protocol introduction
  • MCP: build a server
  • MCP Python SDK
  • MCP Python SDK GitHub
Complete Aulafy mapSee how this lesson fits without leaving your path.

Complete Aulafy map

How all courses connect

This is not a checklist. Start with the foundation, choose an outcome, and go deeper only when your project needs more control.

  1. 1Understand
  2. 2Apply or build
  3. 3Operate with confidence
01

Choose an application

Turn the foundation into a visible outcome: a website, a business improvement, media, or an interactive experience.

Continue into the technical branch when you need to maintain code, data, or infrastructure.

02

Build with code

Prepare your environment, work with coding agents, and run models while keeping control of your projects.

This branch prepares you to design and operate reliable AI systems.

03

Take systems to production

Combine retrieval, agents, evaluation, security, deployment, and model adaptation when the problem requires it.

You do not need every course: choose the component your system needs and return as it grows.

View full catalogue