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
Tools (execute logic
Prompts (instruction templates)
Resources (data access)
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:
Deterministic execution
Access-controlled operations
Integration with enterprise systems
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
Summarization templates
Standard reasoning instructions
Task-specific guidance
Controlled prompting pipelines
Example
@mcp.prompt()
def summarize_policy(text: str):
return f"""
Summarize the following HR policy:
{text}
"""Behavior
Registered as prompt resource
Callable by clients
Encourages consistent prompting
Architectural Role
Prompts enable:
Centralized instruction management
Reusability
Standardized LLM behavior
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
Accessible through resource URIs
Provides structured context
Used by clients or LLMs
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:
Secure operations
Structured data access
Reusable instruction templates
Design Principles Behind MCP Decorators
Minimal Interface Philosophy
MCP intentionally exposes only three primitives:
Execute
Guide
Read
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:
No uncontrolled data exposure
No arbitrary execution
Traceable interfaces
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).

Join the conversation! Your thoughts help the community grow.