Skip to content

LangChain Integration

Use Aerostack workspace tools as LangChain tools. Every MCP tool becomes a DynamicStructuredTool — works with ReAct agents, LangGraph workflows, and any LLM.

Terminal window
npm install @aerostack/sdk-langchain @langchain/openai @langchain/langgraph
import { ChatOpenAI } from '@langchain/openai';
import { createReactAgent } from '@langchain/langgraph/prebuilt';
import { getTools } from '@aerostack/sdk-langchain';
const { tools } = await getTools({
workspace: 'my-workspace',
token: 'mwt_...',
});
const agent = createReactAgent({
llm: new ChatOpenAI({ model: 'gpt-4o' }),
tools,
});
const result = await agent.invoke({
messages: [{ role: 'user', content: 'Create a GitHub issue for the login bug' }],
});
console.log(result.messages.at(-1)?.content);

The SDK:

  1. Fetches all MCP tools from your workspace
  2. Wraps each as a DynamicStructuredTool with name, description, and JSON schema
  3. Each tool’s func property proxies calls through the workspace gateway
  4. Errors are returned as string results (not thrown), keeping agent flow intact

LangChain supports many providers. Aerostack tools work with all of them:

import { ChatAnthropic } from '@langchain/anthropic';
import { getTools } from '@aerostack/sdk-langchain';
const { tools } = await getTools({
workspace: 'my-workspace',
token: 'mwt_...',
});
// Bind tools directly to a model
const model = new ChatAnthropic({
model: 'claude-sonnet-4-20250514',
}).bindTools(tools);
const response = await model.invoke('Search Notion for meeting notes');

Build multi-step workflows with LangGraph:

import { ChatOpenAI } from '@langchain/openai';
import { createReactAgent } from '@langchain/langgraph/prebuilt';
import { getTools } from '@aerostack/sdk-langchain';
const { tools } = await getTools({
workspace: 'my-workspace',
token: 'mwt_...',
});
const agent = createReactAgent({
llm: new ChatOpenAI({ model: 'gpt-4o' }),
tools,
});
// Multi-turn conversation
const thread = { configurable: { thread_id: 'my-session' } };
const r1 = await agent.invoke(
{ messages: [{ role: 'user', content: 'Find open GitHub issues labeled "bug"' }] },
thread,
);
const r2 = await agent.invoke(
{ messages: [{ role: 'user', content: 'Create a Notion page summarizing them' }] },
thread,
);
Section titled “Factory Pattern (Recommended for Production)”
import { createAerostackLangChain } from '@aerostack/sdk-langchain';
const aerostack = createAerostackLangChain({
workspace: 'my-workspace',
token: process.env.AEROSTACK_WORKSPACE_TOKEN!,
});
// Reuse across requests
const { tools } = await aerostack.tools();
const result = await getTools(config);
result.tools // DynamicStructuredTool[] — pass to agents or model.bindTools()
result.raw // McpTool[] — raw MCP tool definitions for inspection