
Overview
LangChain is a framework for developing applications powered by language models. By connecting your MCP servers to LangChain, you can create agents that leverage your custom tools alongside LLM capabilities.Setup Instructions
1
Install required dependencies
Run:
pip install langchain requests
2
Copy the Python code below to your project
Use the generated Python integration code
3
Replace tool names with actual names from your MCP server
Update the tool configuration to match your server’s tools
4
Initialize your LLM (OpenAI, Anthropic, etc.)
Set up your preferred language model
5
Run the agent with your prompts
Execute the agent with your queries
Python Integration Code
Replace
your_tool_name
with actual tool names from your MCP server’s documentation.Getting Your Configuration
1
Navigate to Toolbox
Go to the Toolbox section in NimbleBrain Studio
2
Find Your Server
Locate the MCP server you want to connect
3
Click Connect
Click the Connect button on the server card
4
Select LangChain
Choose “LangChain” from the integration options
5
Copy Code
Copy the generated Python code to your clipboard
Complete Example
Here’s a complete example using Claude and a knowledge base MCP server:TypeScript/JavaScript Integration
You can also use MCP servers with LangChain.js:Advanced Features
Multiple MCP Servers
Connect multiple MCP servers as different tools:Error Handling
Add robust error handling:Caching
Cache MCP tool results for better performance:Troubleshooting
Authentication errors
Authentication errors
Possible causes:
- Invalid or expired token
- Token not set in environment
- Generate a new token in Studio
- Set
NIMBLEBRAIN_TOKEN
environment variable - Verify token has correct permissions
Tool not being called
Tool not being called
Possible causes:
- Tool description not clear enough
- Agent choosing wrong tool
- Tool name mismatch
- Improve tool description to be more specific
- Use
verbose=True
to debug agent decisions - Verify tool name matches MCP server
Connection timeouts
Connection timeouts
Possible causes:
- Server not running
- Network issues
- Long-running tool
- Check server status in Toolbox
- Increase timeout value
- Verify network connectivity
JSON parsing errors
JSON parsing errors
Possible causes:
- Unexpected response format
- MCP server error
- Missing content field
- Add error handling for JSON parsing
- Check MCP server logs in Studio
- Verify API endpoint is correct
Best Practices
Clear Tool Descriptions
Clear Tool Descriptions
Write detailed descriptions so the agent knows when to use each tool:
Environment Variables
Environment Variables
Store sensitive data in environment variables:
Error Handling
Error Handling
Always handle potential errors gracefully to prevent agent failures.
Logging
Logging
Enable verbose mode during development: