MCP Fundamentals
Model Context Protocol (MCP)
Large Language Models (LLMs) like Claude, ChatGPT, and other AI assistants are powerful, but they normally operate in isolation. They cannot directly access your computer, read files, run programs, or query databases.
The Model Context Protocol (MCP) is a standard that allows language models to safely interact with external tools and data sources.
Instead of executing code directly, the language model communicates with an MCP server, which exposes specific capabilities that the model can use.
Learn more: Model Context Protocol Documentation
Mental Model: How MCP Actually Works
A helpful way to think about MCP is that the language model is a decision maker and the MCP server is a toolbox.
User asks question
↓
Claude decides which tool to use
↓
Claude calls the MCP server
↓
Your Python function runs
↓
The result is returned to Claude
↓
Claude explains the result to the user
Important: The language model does not run your code directly. It decides which tool should be executed. The MCP server runs the code and returns the result.
MCP Architecture
The interaction between the user, the language model, and your MCP server looks like this:
User Prompt
↓
Language Model (Claude)
↓
MCP Client
↓
MCP Server
↓
Tools / Data Sources
The language model analyzes the prompt and determines whether a tool should be used.
If a tool is needed:
1. The model selects a tool 2. The MCP client sends the request 3. The MCP server runs the function 4. The result is returned to the model 5. The model formats the final response
MCP Building Blocks
MCP servers provide three types of capabilities.
Tools
Tools are executable functions that perform actions or retrieve data.
Examples include:
- querying a database
- reading files
- performing calculations
- calling APIs
- searching datasets
Example tool:
get_weather(city="St. Louis")
The MCP server runs the function and returns the result.
Resources
Resources are the data sources your MCP tools use.
Examples include:
- files
- documents
- databases
- logs
- datasets
For example, a tool might read a dataset stored in a file.
Prompts
Prompts are the instructions given by the user.
Example:
Show the top hitters on the 1940 Cardinals.
The model interprets the prompt and determines if a tool should be used.
The user never runs the tool directly.
Example Workflow
Suppose the user asks:
Show the top hitters on the 1940 Cardinals.
The system behaves like this:
1. Claude reads the prompt
2. Claude decides the get_top_players tool is needed
3. Claude calls the MCP server
4. The server runs the Python function
5. The results are returned to Claude
Why MCP Matters
Without MCP, language models can only generate text.
With MCP, models can:
- access real data
- run programs
- query databases
- analyze datasets
- automate workflows
This transforms AI systems from chatbots into agents.
MCP in This Course
In this module, you will build a simple MCP server using Python.
Your server will expose tools that allow Claude Desktop to analyze historical St. Louis Cardinals batting statistics.
Claude will automatically call your tools when needed.
Example MCP Tool: hello
Below is a simple example of an MCP tool:
@mcp.tool()
async def hello(name: str = "world") -> str:
"""Return a simple greeting to verify the server is working."""
return f"Hello CSE 3300 Student, {name}!"
This function defines a tool that Claude Desktop can call through the MCP server.
What This Function Does
This tool returns a simple greeting message. It is primarily used to verify that:
- your MCP server is running
- Docker is working correctly
- Claude Desktop is connected to your server
If this tool works, your MCP setup is likely correct.
Line-by-Line Explanation
@mcp.tool()
This is a decorator that registers the function as an MCP tool.
Without this line, Claude will not be able to see or use the function.
async def hello(...)
This defines the function.
hellois the tool name- Claude will refer to this function by this name when calling it
The keyword async indicates that the function runs within the MCP system. You do not need to fully understand asynchronous programming for this assignment.
name: str = "world"
This defines an input parameter:
nameis the parameter namestrindicates it should be a string"world"is the default value
If no value is provided, the function will use "world".
-> str
This is a return type hint.
It indicates that the function returns a string.
Note: Python does not strictly enforce this, but it is important for clarity.
Docstring
"""Return a simple greeting to verify the server is working."""
This is a docstring.
It serves two purposes:
- explains the function to humans
- helps Claude understand what the tool does and when to use it
return statement
return f"Hello CSE 3300 Student, {name}!"
This returns the output of the tool.
For example:
hello("Todd") → Hello CSE 3300 Student, Todd!
How Claude Uses This Tool
When you type a prompt such as:
Use CardinalsMCP to say hello to Todd
Claude will:
- recognize that the
hellotool is relevant - call the function with
name="Todd" - receive the returned string
- display the result in the chat
Key Takeaway
An MCP tool is just a Python function that:
- is decorated with
@mcp.tool() - has clearly defined inputs (parameters)
- returns a result (usually a string)
Claude reads the function name, parameters, and docstring to decide how to use it.
Try It
After your MCP server is running, test this tool in Claude Desktop:
Use CardinalsMCP to say hello
If it works, your MCP server is correctly configured.