Logging
Learn how to debug and log in mcp-use
Logging MCP-Use
MCP-Use provides built-in logging functionality that helps diagnose issues in your agent implementation.
Enabling Debug Mode
Choose the debug method that best fits your workflow - environment variables for one-off debugging or programmatic control for conditional debugging.
There are two primary ways to enable debug mode:
1. Environment Variable (Recommended for One-off Runs)
Run your script with the DEBUG
environment variable:
This sets the debug level only for that specific Python process - perfect for quick troubleshooting.
Run your script with the DEBUG
environment variable:
This sets the debug level only for that specific Python process - perfect for quick troubleshooting.
Set the environment variable in your shell:
Or add it to your .env
file:
2. Setting the Debug Flag Programmatically
Programmatic control is useful for debugging specific parts of your application or conditionally enabling debug mode based on your application state.
You can conditionally enable debugging based on environment or configuration:
Debug Levels
Level 0 - Normal
Minimal Output
Only WARNING and above messages are shown
set_debug(0)
Level 1 - Info
Default Operation
Shows INFO level messages and tool calls - useful for basic operational information
DEBUG=1
or set_debug(1)
(default)
Level 2 - Full Debug
Maximum Verbosity
Shows all detailed debugging information including internal operations
DEBUG=2
or set_debug(2)
Agent-Specific Verbosity
If you only want to increase verbosity for the agent component without enabling full debug mode for the entire package, you can use the verbose
parameter when creating an MCPAgent:
This option is useful when you want to see the agent’s steps and decision-making process without all the low-level debug information from other components.
Debug Information
When debug mode is enabled, you’ll see more detailed information about:
- Server initialization and connection details
- Tool registration and resolution
- Agent steps and decision-making
- Request and response formats
- Communication with MCP servers
- Error details and stack traces
This can be extremely helpful when diagnosing issues with custom MCP servers or understanding why an agent might be behaving unexpectedly.
Troubleshooting Common Issues
Server Connection Problems
If you’re having issues connecting to MCP servers, enabling debug mode will show detailed information about the connection attempts, server initialization, and any errors encountered.
Agent Not Using Expected Tools
When debug mode is enabled, you’ll see each tool registration and the exact prompts being sent to the LLM, which can help diagnose why certain tools might not be used as expected.
Performance Issues
Debug logs can help identify potential bottlenecks in your implementation by showing timing information for various operations.