Integrate real-time context to your LangChain AI agents via Membit MCP..
Enhance your LangChain applications with real-time social media context from Membit. This integration allows your AI agents to access up-to-the-minute discussions, trends, and insights from platforms like X (Twitter), Farcaster, and more.
Make sure you have mcp-remote installed globally via npm for this to work.
Replace <your-api-key> with your actual Membit API key. Keep this credential secure and don’t share it with unauthorized users.
4
Create agent prompt
Define a prompt template that encourages the agent to use Membit tools:
Copy
prompt = ChatPromptTemplate.from_messages( [ ( "system", "Make sure you utilize membit tools to get the most trending data." ), MessagesPlaceholder(variable_name="messages"), MessagesPlaceholder(variable_name="agent_scratchpad"), ])
5
Create and run your agent
Connect to Membit and create your LangChain agent:
Copy
async def main(): async with stdio_client(server_params) as (read, write): async with ClientSession(read, write) as session: # Initialize the MCP connection await session.initialize() # Load Membit tools from MCP session mcp_tools = await load_mcp_tools(session) # Create the LangChain agent agent = create_openai_tools_agent( llm=llm, tools=mcp_tools, prompt=prompt ) # Create executor agent_executor = AgentExecutor( agent=agent, tools=mcp_tools, verbose=True ) # Query your agent await agent_executor.ainvoke({ "messages": [HumanMessage(content= "What are the most trending discussions about AI today?" )] })if __name__ == "__main__": asyncio.run(main())
Your LangChain agent is now powered by real-time social media context from Membit!