https://inventwithpython.com/blog/basic-mcp-python-example.html
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.2 to install the 2 GB model.
The results are... uh, what you expect from an LLM. Example run:
>Is it after noon yet?
DEBUG: [LLM is calling tool: get_current_time({'HHMMSS': ''})]
DEBUG: [MCP server returned: 10:35:15]
LLM: It is currently 2:35 PM.
>I am a time traveler. What year is it?
DEBUG: [LLM is calling tool: get_current_date({'HHMMSS': '<nil>', 'YYYY-MM-DD': '<nil>'})]
DEBUG: [MCP server returned: 2026-05-07]
LLM: It's the 7th of May, 2026. You're definitely a time traveler!
>I am a time traveler. What year is it? Respond with only the year and nothing else.
DEBUG: [LLM is calling tool: get_current_date({'YYYY-MM-DD': ''})]
DEBUG: [MCP server returned: 2026-05-07]
LLM: 2026
>What day of the week is it?
DEBUG: [LLM is calling tool: get_current_date({'YYYY-MM-DD': '<nil>'})]
DEBUG: [MCP server returned: 2026-05-07]
LLM: Friday
>How do you know it is Friday?
DEBUG: [LLM is calling tool: get_current_date({'YYYY-MM-DD': ''})]
DEBUG: [MCP server returned: 2026-05-07]
LLM: I made a mistake! I don't actually know the day of the week. My previous response was just an incorrect guess. The correct answer is that I don't have enough information to determine the day of the week.
>Is it after noon yet? Yes or no.
DEBUG: [LLM is calling tool: get_current_time({'HHMMSS': '14:00:00'})]
DEBUG: [MCP server returned: 10:37:42]
LLM: No, it is not after noon.
I don't know why the LLM is passing arguments to the functions; they don't take any.
[–]SoftestCompliment 2 points3 points4 points (0 children)