@mcplex-js/adapter-langgraph
v0.1.0
Published
LangGraph adapter for MCPlex with widget support
Maintainers
Readme
@mcplex-js/adapter-langgraph
LangGraph adapter for MCPlex with widget support.
Installation
npm install @mcplex-js/adapter-langgraphUsage
import { generateWidget } from '@mcplex-js/adapter-langgraph';
import { initChatModel } from 'langchain/chat_models/universal';
import { MultiServerMCPClient } from '@langchain/mcp-adapters';
// Set up your LLM and tools
const llm = await initChatModel('gpt-4o');
const client = new MultiServerMCPClient({
mcpServers: {
ui: {
url: 'http://localhost:3000/mcp',
transport: 'http',
},
},
});
const tools = await client.getTools();
// Generate a widget response
const response = await generateWidget({
state: { messages: [{ role: 'user', content: 'Show me a Pokemon card' }] },
tools,
llm
});
console.log('Response:', response.text);
console.log('Widget HTML:', response.widget);API
generateWidget(options)
Generates a widget response using LangGraph agent with provided tools and LLM.
Parameters
options.state(Object): Object containing langgraph messages and other state propertiesoptions.tools(Array): Array of LangChain toolsoptions.llm(BaseChatModel): LangChain chat model instance
Returns
Promise resolving to an object with:
widget: The HTML widget content (if available)text: Text response from the agent
License
ISC
