Introduction

Model Context Protocol (MCP) servers provide a structured interface between Large Language Models (LLMs) and external systems. Instead of allowing models direct access to databases, APIs, or internal logic, MCP defines a standardized way to expose capabilities safely and transparently.

In Python-based MCP implementations (such as FastMCP), these capabilities are registered using decorators. While they may appear as simple syntactic sugar, decorators represent fundamental architectural primitives in MCP:

Understanding these decorators is essential when building production-grade AI systems that are secure, scalable, and maintainable.

This article explores their purpose, behavior, and usage in detail.

MCP Architecture Overview

At a high level, an MCP server exposes structured interfaces to an LLM:

LLM Client

Decorators register Python functions into these categories so they can be discovered and invoked through the MCP protocol.

Decorators in MCP Servers

Decorators in MCP servers are used to attach metadata to functions, enabling automatic registration with the server runtime.

Example base setup:

from mcp.server.fastmcp import FastMCP

mcp = FastMCP("Example Server")

Functions decorated with MCP annotations become part of the server interface.

Tool Decorator (@mcp.tool)

Purpose

Expose a function that performs an action or computation which the LLM can invoke.

Typical Use Cases

Example

@mcp.tool()
def calculate_bonus(salary: float, rating: int) -> float:
    return salary * (0.1 + rating * 0.02)

Behavior

Architectural Role

Tools extend the LLM’s capability beyond language generation by enabling:

Key Characteristics

PropertyValue
ExecutionYes
DeterministicYes
Side EffectsPossible
Security EnforcementHigh

Prompt Decorator (@mcp.prompt)

Purpose

Define reusable prompt templates available to clients or orchestrators.

Typical Use Cases

Example

@mcp.prompt()
def summarize_policy(text: str):
    return f"""
    Summarize the following HR policy:
    {text}
    """

Behavior

Architectural Role

Prompts enable:

They act as instruction assets, separate from execution or data retrieval.

Key Characteristics

PropertyValue
ExecutionNo
Generates TextYes
Side EffectsNone
PurposeGuidance

Resource Decorator (@mcp.resource)

Purpose

Expose read-only data accessible via URI-like identifiers.

Typical Use Cases

Example

@mcp.resource("employee://{emp_id}")
def employee_record(emp_id: str):
    return database.fetch_employee(emp_id)

Behavior

Architectural Role

Resources supply controlled data without execution logic, enabling:

Comparing MCP Decorators

FeatureToolPromptResource
Performs ActionsYesNoNo
Returns InstructionsNoYesNo
Provides DataYesNoYes
Security LevelHighestMediumMedium
Use CaseOperationsGuidanceContext

How Decorators Enable MCP Discovery

When decorators are applied:

  1. Function metadata is captured

  2. Schema is generated

  3. Server registers capability

  4. Client can discover and invoke

This removes manual interface wiring and enables protocol standardization.

Practical System Design Example

HR Assistant MCP Server

Tool

@mcp.tool()
def get_leave_balance(emp_id: int):
    return hr_db.leave(emp_id)

Resource

@mcp.resource("policy://leave")
def leave_policy():
    return load_policy_doc()

Prompt

@mcp.prompt()
def explain_policy(text):
    return f"Explain policy clearly:\n{text}"

This separation results in:

Design Principles Behind MCP Decorators

Minimal Interface Philosophy

MCP intentionally exposes only three primitives:

This simplicity improves:

Separation of Concerns

LayerResponsibility
ToolAction
ResourceData
PromptInstruction

Clear separation prevents architectural coupling.

Safety and Governance

Decorators enforce boundaries:

Essential for enterprise deployment.

Conclusion

MCP server decorators are not merely syntactic conveniences — they define the structural contract between LLMs and external systems. By mapping functionality into tools, prompts, and resources, developers gain:

Understanding these decorators allows architects to design robust AI integrations that balance flexibility with control — a necessity as LLM-powered systems become core infrastructure components.

These primitives represent the foundation of MCP-based orchestration and will continue to play a central role in scalable AI application development.

The example codes are available at Jayant0516 (Jayant Kumar).