Difference between revisions of "Module6-New"

From CSE330 Wiki
Jump to navigationJump to search
Line 11: Line 11:
  
 
== Using the Wiki ==
 
== Using the Wiki ==
 +
 
{{RequiredInstructions|content=
 
{{RequiredInstructions|content=
 
Text enclosed by <syntaxhighlight lang="bash" inline><</syntaxhighlight> and <syntaxhighlight lang="bash" inline>></syntaxhighlight> should be replaced by content unique to you.
 
Text enclosed by <syntaxhighlight lang="bash" inline><</syntaxhighlight> and <syntaxhighlight lang="bash" inline>></syntaxhighlight> should be replaced by content unique to you.
  
−
'''Example'''
+
Example
  
 
<source lang="bash">
 
<source lang="bash">
 
$ sudo useradd -r -m -c "<My Full Name>" <usernameHere>
 
$ sudo useradd -r -m -c "<My Full Name>" <usernameHere>
 
</source>
 
</source>
 +
 
becomes
 
becomes
 +
 
<source lang="bash">
 
<source lang="bash">
 
$ sudo useradd -r -m -c "Zach Cohn" zcohn
 
$ sudo useradd -r -m -c "Zach Cohn" zcohn
Line 27: Line 30:
 
== Reading ==
 
== Reading ==
  
−
The following articles on the online class wiki textbook contain information that will help you complete the assignments.
+
The following articles contain information that will help you complete the assignments.
  
 
* [[Python]]
 
* [[Python]]
 
* [[Regular Expressions]]
 
* [[Regular Expressions]]
−
* [[MCP Fundamentals|Model Context Protocol (MCP)]]
+
* [[MCP-Fundamentals|Model Context Protocol (MCP)]]
 
* [[FAQ - Mod 6]]
 
* [[FAQ - Mod 6]]
  
Line 38: Line 41:
 
=== Learn Python and Regular Expressions ===
 
=== Learn Python and Regular Expressions ===
  
−
Up to this point in CSE 330, you have used only one programming language: PHP. 
+
Up to this point in CSE 330 you have used only one programming language: PHP.
−
In this module, you will learn a new language: Python.
 
  
−
Before starting this assignment, you should look over the [[Python|online textbook article about Python]]. 
+
In this module you will learn Python.
−
You should be using version 3 (or greater) of Python.
 
  
−
Additionally, you may find it helpful to look over the [[Regular Expressions|online textbook article about Regular Expressions]].
+
Before starting this assignment review:
  
−
=== Write some Regular Expressions ===
+
* [[Python]]
 +
* [[Regular Expressions]]
  
−
Please write regular expressions that do each of the following:
+
You should use Python 3.
  
−
# Match the substring "hello world" in a string.
+
=== Write some Regular Expressions ===
−
# Match all character strings in an input string that contain three or more consecutive vowels. The regex should match strings containing three or more consecutive vowels regardless of case.
 
−
# Match an input string that is '''entirely''' a flight code, of the format AA#### where '''AA''' is a two-letter uppercase airline code and '''####''' is a three or four digit flight number.
 
  
−
Save your regexes to text files – one each.
+
Write regular expressions that do the following:
  
−
=== Baseball Stats Counter ===
+
# Match the substring "hello world"
 +
# Match strings containing three or more consecutive vowels
 +
# Match a flight code of format AA####
  
−
The St. Louis Cardinals are one of the most legendary baseball teams in the National League.
+
Save them as:
  
−
In this exercise, you will create a Python script that reads box scores from a file and computes the Cardinals players’ batting averages in a particular season.
+
<code>regex1.txt</code> 
 +
<code>regex2.txt</code> 
 +
<code>regex3.txt</code>
  
−
==== Tips and Instructions ====
+
=== Baseball Stats Counter ===
  
−
* Write a Python script file to solve this problem.
+
You will write a Python script that reads box score data and computes batting averages.
−
* Use a regular expression to parse players’ names, at-bats, hits, and runs from the input file.
 
−
* You may want to create a class to hold player information.
 
−
* Your script should take one command-line argument: the path to an input file.
 
−
* If no argument is given, your program should print a usage message.
 
  
 
==== Input ====
 
==== Input ====
  
−
Sample input files may be found here:
+
Sample files:
  
 
http://classes.engineering.wustl.edu/cse330/content/cardinals/
 
http://classes.engineering.wustl.edu/cse330/content/cardinals/
  
−
Each game begins with a header line.
+
Each game begins with a header:
−
 
 
−
Example:
 
  
 
<pre>
 
<pre>
Line 84: Line 82:
 
</pre>
 
</pre>
  
−
Each player performance line follows the format:
+
Each player line follows:
  
 
<pre>
 
<pre>
 
XXX batted # times with # hits and # runs
 
XXX batted # times with # hits and # runs
 
</pre>
 
</pre>
−
 
−
Where:
 
−
 
−
* '''XXX''' is the player name
 
−
* '''#''' values are integers
 
  
 
==== Output ====
 
==== Output ====
  
−
Your script must compute batting averages for all players.
+
Compute batting average:
−
 
 
−
Batting Average:
 
  
 
<pre>
 
<pre>
Line 105: Line 96:
 
</pre>
 
</pre>
  
−
Example output format:
+
Example:
  
 
<pre>
 
<pre>
Line 111: Line 102:
 
</pre>
 
</pre>
  
−
Players should be sorted by batting average.
+
Sort players by batting average.
  
 
=== Baseball Stats MCP Extension ===
 
=== Baseball Stats MCP Extension ===
  
−
In this project you will build a '''custom MCP server''' that allows Claude Desktop to explore historical St. Louis Cardinals batting data from the '''1930''' and '''1940''' seasons.
+
In this project you will build a '''custom MCP server''' that allows Claude Desktop to explore historical Cardinals batting data from the '''1930''' and '''1940''' seasons.
−
 
 
−
Your MCP server will read batting averages from text files generated in the previous assignment and expose tools that allow Claude to query that data.
 
  
−
For all parts of this assignment, feel free to use your favorite AI tools to assist you.
+
Your server will expose tools that Claude can use to query the dataset.
  
 
==== Goal ====
 
==== Goal ====
Line 125: Line 114:
 
Your MCP server should:
 
Your MCP server should:
  
−
* read Cardinals batting data
+
* read Cardinals batting averages
−
* provide tools to analyze player statistics
+
* expose tools to analyze the data
 
* run inside Docker
 
* run inside Docker
 
* connect to Claude Desktop
 
* connect to Claude Desktop
−
 
−
==== Example Prompts ====
 
−
 
−
After your MCP server is running, Claude should be able to answer questions such as:
 
−
 
−
<pre>
 
−
Use CardinalsMCP to list the top 10 hitters from 1940.
 
−
</pre>
 
−
 
−
<pre>
 
−
Show Johnny Mize's batting averages for 1930 and 1940.
 
−
</pre>
 
−
 
−
<pre>
 
−
Search for players with "Martin" in their name.
 
−
</pre>
 
−
 
−
Claude will automatically call your MCP tools and display the results.
 
  
 
==== Project Structure ====
 
==== Project Structure ====
−
 
−
Your project directory should look like this:
 
  
 
<source lang="text">
 
<source lang="text">
Line 162: Line 131:
 
</source>
 
</source>
  
−
==== Docker Setup ====
+
==== Verify Your MCP Server Works ====
 +
 
 +
Before connecting Claude Desktop verify the container runs.
 +
 
 +
<source lang="bash">
 +
docker run --rm -it cardinals-mcp-server
 +
</source>
 +
 
 +
You should see a startup message.
  
−
Install:
+
If this fails fix the error before continuing.
  
−
* Docker Desktop
+
==== Common Setup Mistakes ====
−
* Claude Desktop
 
  
−
Enable the Docker MCP Toolkit in Docker Desktop settings.
+
'''Docker image not built'''
  
−
==== MCP Tools ====
+
<source lang="bash">
 +
docker build -t cardinals-mcp-server .
 +
</source>
 +
 
 +
'''Container name mismatch'''
 +
 
 +
The Docker name must match the name in Claude config.
  
−
Your server must implement at least two tools.
+
'''Claude not restarted'''
  
−
Possible examples include:
+
Restart Claude Desktop after editing the config.
  
−
* <code>get_player_stats</code>
+
'''Container exits immediately'''
−
* <code>get_team_roster</code>
 
−
* <code>get_top_players</code>
 
−
* <code>search_players</code>
 
  
−
Each tool should be registered using the <code>@mcp.tool()</code> decorator.
+
Run the container manually to view the error.
  
−
==== Testing ====
+
==== What Claude Is Actually Doing ====
  
−
Build your Docker container:
+
When you ask Claude:
  
−
<source lang="bash">
+
<pre>
−
docker build -t cardinals-mcp-server .
+
Use CardinalsMCP to list the top hitters from 1940
−
</source>
+
</pre>
 +
 
 +
the system behaves like this:
 +
 
 +
<pre>
 +
User prompt
 +
      ↓
 +
Claude reads prompt
 +
      ↓
 +
Claude decides tool
 +
      ↓
 +
Claude calls MCP server
 +
      ↓
 +
Docker launches container
 +
      ↓
 +
Python tool runs
 +
      ↓
 +
Results returned
 +
</pre>
 +
 
 +
Claude does not execute Python directly.
 +
 
 +
==== Debugging Your MCP Server ====
 +
 
 +
If Claude cannot return results:
 +
 
 +
1. Verify container runs
 +
2. Verify Python script loads
 +
3. Verify Claude configuration
 +
4. Restart Claude Desktop
 +
 
 +
==== Example Prompts ====
  
−
Run it:
+
<pre>
 +
Use the CardinalsMCP tool to list the 1940 roster
 +
</pre>
  
−
<source lang="bash">
+
<pre>
−
docker run --rm -it cardinals-mcp-server
+
Use the CardinalsMCP tool to show Johnny Mize batting averages
−
</source>
+
</pre>
  
−
Then connect Claude Desktop to your MCP server and test the example prompts.
+
<pre>
 +
Search for players with Martin in their name
 +
</pre>
  
 
== Grading ==
 
== Grading ==
  
−
There are '''50 points total'''.
+
Total: 50 points.
−
 
 
−
Assignments must be committed to GitHub by the end of class on the due date.
 
  
−
=== Regular Expressions (15 Points) ===
+
=== Regular Expressions (15 points) ===
  
−
* regex1.txt correct (5)
+
* regex1 correct (5)
−
* regex2.txt correct (5)
+
* regex2 correct (5)
−
* regex3.txt correct (5)
+
* regex3 correct (5)
  
−
=== Baseball Stats Counter (25 Points) ===
+
=== Baseball Stats Counter (25 points) ===
  
 
* Python implementation (5)
 
* Python implementation (5)
Line 219: Line 231:
 
* Correct output (12)
 
* Correct output (12)
  
−
=== Baseball Stats MCP Extension (10 Points) ===
+
=== Baseball Stats MCP Extension (10 points) ===
  
−
* Docker image builds successfully (5)
+
* Docker image builds (5)
−
* At least two working MCP tools (3)
+
* Two MCP tools implemented (3)
−
* README includes three Claude prompts (2)
+
* README with example prompts (2)
  
 
[[Category:Module 6]]
 
[[Category:Module 6]]
 
[[Category:Modules]]
 
[[Category:Modules]]

Revision as of 15:13, 11 March 2026


In Module 6, you will learn the fundamentals of Python, Regular Expressions, and the Model Context Protocol (MCP).

This article contains your assignments for Module 6.

Learning Goals

  • Regular Expressions
  • Python
  • MCP Fundamentals

Using the Wiki

Text enclosed by < and > should be replaced by content unique to you.

Example

$ sudo useradd -r -m -c "<My Full Name>" <usernameHere>

becomes

$ sudo useradd -r -m -c "Zach Cohn" zcohn

Reading

The following articles contain information that will help you complete the assignments.

Individual Assignments

Learn Python and Regular Expressions

Up to this point in CSE 330 you have used only one programming language: PHP.

In this module you will learn Python.

Before starting this assignment review:

You should use Python 3.

Write some Regular Expressions

Write regular expressions that do the following:

  1. Match the substring "hello world"
  2. Match strings containing three or more consecutive vowels
  3. Match a flight code of format AA####

Save them as:

regex1.txt regex2.txt regex3.txt

Baseball Stats Counter

You will write a Python script that reads box score data and computes batting averages.

Input

Sample files:

http://classes.engineering.wustl.edu/cse330/content/cardinals/

Each game begins with a header:

=== St.Louis Cardinals vs. Chicago Cubs, 1940-04-19 ===

Each player line follows:

XXX batted # times with # hits and # runs

Output

Compute batting average:

hits / at-bats

Example:

Johnny Hopp: 0.275

Sort players by batting average.

Baseball Stats MCP Extension

In this project you will build a custom MCP server that allows Claude Desktop to explore historical Cardinals batting data from the 1930 and 1940 seasons.

Your server will expose tools that Claude can use to query the dataset.

Goal

Your MCP server should:

  • read Cardinals batting averages
  • expose tools to analyze the data
  • run inside Docker
  • connect to Claude Desktop

Project Structure

cardinals-mcp/
├── Dockerfile
├── cardinals_server.py
├── requirements.txt
└── data/
    ├── cardinals-1930.txt
    └── cardinals-1940.txt

Verify Your MCP Server Works

Before connecting Claude Desktop verify the container runs.

docker run --rm -it cardinals-mcp-server

You should see a startup message.

If this fails fix the error before continuing.

Common Setup Mistakes

Docker image not built

docker build -t cardinals-mcp-server .

Container name mismatch

The Docker name must match the name in Claude config.

Claude not restarted

Restart Claude Desktop after editing the config.

Container exits immediately

Run the container manually to view the error.

What Claude Is Actually Doing

When you ask Claude:

Use CardinalsMCP to list the top hitters from 1940

the system behaves like this:

User prompt
      ↓
Claude reads prompt
      ↓
Claude decides tool
      ↓
Claude calls MCP server
      ↓
Docker launches container
      ↓
Python tool runs
      ↓
Results returned

Claude does not execute Python directly.

Debugging Your MCP Server

If Claude cannot return results:

1. Verify container runs 2. Verify Python script loads 3. Verify Claude configuration 4. Restart Claude Desktop

Example Prompts

Use the CardinalsMCP tool to list the 1940 roster
Use the CardinalsMCP tool to show Johnny Mize batting averages
Search for players with Martin in their name

Grading

Total: 50 points.

Regular Expressions (15 points)

  • regex1 correct (5)
  • regex2 correct (5)
  • regex3 correct (5)

Baseball Stats Counter (25 points)

  • Python implementation (5)
  • Correct regex parsing (5)
  • Usage message (3)
  • Correct output (12)

Baseball Stats MCP Extension (10 points)

  • Docker image builds (5)
  • Two MCP tools implemented (3)
  • README with example prompts (2)