Debugging
Learn how to debug and log in easy-mcp-use
Debugging Easy-MCP-Use
Easy-MCP-Use provides built-in debugging functionality that increases log verbosity and helps diagnose issues in your agent implementation.
Enabling Debug Mode
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 set to the desired level:
This sets the debug level only for the duration of that specific Node.js process. This is particularly useful for quickly troubleshooting issues without modifying your code. Alternatively you can set the environment variable MCP_USE_DEBUG as such:
2. Setting the Debug Flag Programmatically
You can set the global debug flag directly in your code, which is useful for debugging specific parts of your application or conditionally enabling debug mode based on your application state:
Debug Levels
Easy-MCP-Use supports different levels of debugging:
Level | Environment Variable | Program Setting | Description |
---|---|---|---|
0 | (not set) | setDebug(0) | Normal operation, only WARNING and above messages are shown |
1 | DEBUG=1 | setDebug(1) | INFO level messages are shown - useful for basic operational information. Shows tool calls. |
2 | DEBUG=2 | setDebug(2) | Full DEBUG level - all detailed debugging information is shown |
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.
Langsmith
Langchain offers a very nice tool to debug agent behaviour which integrates seamlessly with easy-mcp-use. You can visit https://smith.langchain.com/ and login, they will give you a set of variables to copy in an .env file you will be then able to visualize the agent behaviour on their platform.
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.