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:
Tools — Executable actions
Prompts — Reusable instructions
Resources — Readable data
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
Database queries
API calls
Calculations
Workflow execution
System automation
Example
@mcp.tool()
def calculate_bonus(salary: float, rating: int) -> float:
return salary * (0.1 + rating * 0.02)
Behavior
Registered in the tool registry
Automatically converted to schema
Discoverable by MCP clients
Executed when invoked
Architectural Role
Tools extend the LLM’s capability beyond language generation by enabling:
Key Characteristics
| Property | Value |
|---|
| Execution | Yes |
| Deterministic | Yes |
| Side Effects | Possible |
| Security Enforcement | High |
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
| Property | Value |
|---|
| Execution | No |
| Generates Text | Yes |
| Side Effects | None |
| Purpose | Guidance |
Resource Decorator (@mcp.resource)
Purpose
Expose read-only data accessible via URI-like identifiers.
Typical Use Cases
Files
Database records
Documents
Configurations
Structured datasets
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:
Context grounding
Secure data access
Data abstraction
Comparing MCP Decorators
| Feature | Tool | Prompt | Resource |
|---|
| Performs Actions | Yes | No | No |
| Returns Instructions | No | Yes | No |
| Provides Data | Yes | No | Yes |
| Security Level | Highest | Medium | Medium |
| Use Case | Operations | Guidance | Context |
How Decorators Enable MCP Discovery
When decorators are applied:
Function metadata is captured
Schema is generated
Server registers capability
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:
System predictability
Maintainability
Observability
Separation of Concerns
| Layer | Responsibility |
|---|
| Tool | Action |
| Resource | Data |
| Prompt | Instruction |
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:
Security
Modularity
Discoverability
Maintainability
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).