Difference between revisions of "MCP Fundamentals"
(Created page with "__NOTOC__ = Model Context Protocol (MCP) = Large Language Models (LLMs) like Claude, ChatGPT, and other AI assistants are powerful, but they normally operate in isolation....") |
|||
| Line 9: | Line 9: | ||
Instead of executing code directly, the language model communicates with an '''MCP server''', which exposes specific capabilities that the model can use. | Instead of executing code directly, the language model communicates with an '''MCP server''', which exposes specific capabilities that the model can use. | ||
| − | |||
| − | |||
Learn more: | Learn more: | ||
[https://modelcontextprotocol.io/docs/getting-started/intro Model Context Protocol Documentation] | [https://modelcontextprotocol.io/docs/getting-started/intro 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'''. | ||
| + | |||
| + | <pre> | ||
| + | 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 | ||
| + | </pre> | ||
| + | |||
| + | '''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 == | == MCP Architecture == | ||
| Line 31: | Line 51: | ||
</pre> | </pre> | ||
| − | The language model analyzes the | + | The language model analyzes the prompt and determines whether a tool should be used. |
If a tool is needed: | If a tool is needed: | ||
| − | 1. The | + | 1. The model selects a tool |
| − | 2. The MCP client sends the request | + | 2. The MCP client sends the request |
| − | 3. The server | + | 3. The MCP server runs the function |
| − | 4. The result is returned to the model | + | 4. The result is returned to the model |
| − | 5. The model formats the response | + | 5. The model formats the final response |
| − | |||
| − | |||
== MCP Building Blocks == | == MCP Building Blocks == | ||
| Line 58: | Line 76: | ||
* calling APIs | * calling APIs | ||
* searching datasets | * searching datasets | ||
| − | |||
| − | |||
Example tool: | Example tool: | ||
| Line 67: | Line 83: | ||
</pre> | </pre> | ||
| − | The MCP server runs the function and returns the result | + | The MCP server runs the function and returns the result. |
=== Resources === | === Resources === | ||
| − | '''Resources''' are data sources | + | '''Resources''' are the data sources your MCP tools use. |
Examples include: | Examples include: | ||
* files | * files | ||
| + | * documents | ||
* databases | * databases | ||
| − | * | + | * logs |
* datasets | * datasets | ||
| − | |||
| − | |||
| − | |||
For example, a tool might read a dataset stored in a file. | For example, a tool might read a dataset stored in a file. | ||
| Line 92: | Line 106: | ||
<pre> | <pre> | ||
| − | + | Show the top hitters on the 1940 Cardinals. | |
</pre> | </pre> | ||
| − | The | + | The model interprets the prompt and determines if a tool should be used. |
| − | The user never | + | The user never runs the tool directly. |
== Example Workflow == | == Example Workflow == | ||
| Line 104: | Line 118: | ||
<pre> | <pre> | ||
| − | + | Show the top hitters on the 1940 Cardinals. | |
</pre> | </pre> | ||
| − | The system | + | The system behaves like this: |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | 1. Claude reads the prompt | |
| + | 2. Claude decides the <code>get_top_players</code> 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 == | == Why MCP Matters == | ||
| Line 121: | Line 133: | ||
Without MCP, language models can only generate text. | Without MCP, language models can only generate text. | ||
| − | With MCP, | + | With MCP, models can: |
* access real data | * access real data | ||
| Line 129: | Line 141: | ||
* automate workflows | * automate workflows | ||
| − | This transforms AI systems from | + | This transforms AI systems from chatbots into '''agents'''. |
== MCP in This Course == | == MCP in This Course == | ||
| Line 137: | Line 149: | ||
Your server will expose tools that allow Claude Desktop to analyze historical St. Louis Cardinals batting statistics. | Your server will expose tools that allow Claude Desktop to analyze historical St. Louis Cardinals batting statistics. | ||
| − | Claude will automatically call your tools when | + | Claude will automatically call your tools when needed. |
[[Category:Module 6]] | [[Category:Module 6]] | ||
[[Category:Modules]] | [[Category:Modules]] | ||
Revision as of 15:12, 11 March 2026
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.