This document provides a developer-focused guide on how to integrate Vinci’s MCP server with your own LangChain agent. It’s structured as a cookbook with recipes to guide you through the implementation.
This guide shows how you can connect your LangChain agent to Vinci’s MCP (Multi-tool Control Plane) server. This enables your agent to dynamically discover and utilize our powerful external tools, extending its capabilities beyond simple chat.
To run the examples in this guide, you need to configure the following environment variables in your .env file.
# .env# Vinci MCP server URLVINCI_MCP_URL=https://vinci-backend2-serving-382403086889.us-central1.run.app/agent/mcp# Your Vinci User ID (from Vinci Dashboard → API)VINCI_USER_ID=your-user-id# Your Google Gemini API keyGEMINI_API_KEY=your-google-api-key
This recipe shows how to connect to Vinci’s MCP server, retrieve the available tools, and print their names and descriptions. This is the foundational step for integrating Vinci’s tools into any LangChain agent.Code:
# agents/vinci_mcp_tools.pyimport osimport asynciofrom langchain_mcp_adapters.client import MultiServerMCPClientfrom dotenv import load_dotenvload_dotenv()async def get_vinci_tools(): """ Connects to Vinci's MCP server using the MultiServerMCPClient and retrieves available tools as LangChain-compatible tools. """ server_url = os.getenv("VINCI_MCP_URL") user_id = os.getenv("VINCI_USER_ID") if not server_url or not user_id: raise EnvironmentError("Missing VINCI_MCP_URL or VINCI_USER_ID in environment.") client = MultiServerMCPClient( { # Vinci’s MCP server "vinci": { "transport": "streamable_http", "url": server_url, "headers": {"X-User-ID": user_id}, }, } ) # Fetch tools from Vinci’s MCP server tools = await client.get_tools() return toolsasync def main(): """ Fetches tools and prints their details. """ tools = await get_vinci_tools() for tool in tools: print(f"Tool Name: {tool.name}, Description: {tool.description}") print(f"Retrieved {len(tools)} tools from Vinci MCP server.")if __name__ == "__main__": asyncio.run(main())
Once you can fetch the tools, you can integrate them into a LangChain agent. This example demonstrates how to build an agent that can use the Vinci tools to perform tasks.Code:
By following these recipes, you can seamlessly integrate Vinci’s powerful MCP tools into your own LangChain agents. This allows you to build sophisticated, tool-augmented applications with ease. We encourage you to experiment with the available tools and explore the creative possibilities they unlock.