- Create a simple chatbot using Anthropic
- Connect to the Galileo MCP server to add tools to your chatbot
- Add logging with Galileo
Before you start
Before you begin, ensure you have:- Python 3.10+ installed
- A Galileo API key
- An Anthropic API key
Install dependencies
To use Galileo, you need to install some package dependencies, and configure environment variables.Install Required Dependencies
Create a .env file, and add the following values
Create a simple chat bot with logging to Galileo
Create a project file
app.py. Add the following code to this file to create a basic chatbot to interact with your chosen Anthropic model:Run the code

Add tool calling against an MCP server to the chat bot
Create a file for the MCP client
mcp_client.py. Add the following code to this file to create an MCP client:MCPClient class that connects to the Galileo MCP server.Import the MCPClient
app.py file, import the MCP Client, and create an instance of it. Add the following import statement to the top of the app.py:Create and initialize the MCP client
main function, connect the MCP client to the Galileo MCP server. Add the following line of code to the top of the main function:Pass the tools list to the LLM
call_llm function to take a boolean parameter called use_tools. Then if this is set, set the tools parameter on the call to anthropic.messages.create to use the tools from the MCP client.Change the call_llm function to the following:use_tools parameter allows the calling code to control if tools are used, and turn them off when the tool response is processed. You will set this up in a later step.Process a tool use request from the LLM
for content in response.content: block, add another clause after the if content.type == "text": block for if the content type is tool use:Run the code
Log the tool call as a tool span
Capture the start time of the tool call
mcp_client.call_tool to get the start time of the call. This will allow you to time the tool call and add this duration to the span.Log the tool span
mcp_client.call_tool:Run the code
