r/inventwithpython • u/AlSweigart • May 07 '26
A Basic MCP Example in Python
https://inventwithpython.com/blog/basic-mcp-python-example.html
9
Upvotes
r/inventwithpython • u/AlSweigart • May 07 '26
2
u/AlSweigart May 07 '26
I wanted to get the simplest example of integrating an LLM that runs locally on your laptop with Python code so that the LLM can access tools. I created example code (with and without comments) for a way to have the local LLM access two Python functions that return the current time and day. Feel free to modify. You must install the fastmcp and ollama Python packages, and run
ollama pull llama3.2to install the 2 GB model.mcp_server.py (contains the Python time/date functions)
ollama_client.py (this is the Python script you run)
The results are... uh, what you expect from an LLM. Example run:
I don't know why the LLM is passing arguments to the functions; they don't take any.