pica-langchain
Original:🇺🇸 English
Translated
Integrate PICA into a LangChain/LangGraph Python application via MCP. Use when adding PICA tools to a LangChain agent, setting up PICA MCP with LangChain, or when the user mentions PICA with LangChain or LangGraph.
31installs
Sourcepicahq/skills
Added on
NPX Install
npx skill4agent add picahq/skills pica-langchainTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →PICA MCP Integration with LangChain
PICA provides a unified API platform that connects AI agents to third-party services (CRMs, email, calendars, databases, etc.) through MCP tool calling.
PICA MCP Server
PICA exposes its capabilities through an MCP server distributed as . It uses stdio transport — it runs as a local subprocess via .
@picahq/mcpnpxMCP Configuration
json
{
"mcpServers": {
"pica": {
"command": "npx",
"args": ["@picahq/mcp"],
"env": {
"PICA_SECRET": "your-pica-secret-key"
}
}
}
}- Package: (run via
@picahq/mcp, no install needed)npx - Auth: environment variable (obtain from the PICA dashboard https://app.picaos.com/settings/api-keys)
PICA_SECRET - Transport: stdio (standard input/output)
Environment Variable
Always store the PICA secret in an environment variable, never hardcode it:
PICA_SECRET=sk_test_...Add it to and load with .
.envpython-dotenvUsing PICA with LangChain
LangChain provides MCP client support via the package. Always refer to the latest docs before implementing. See langchain-mcp-reference.md.
langchain-mcp-adaptersRequired packages
bash
pip install langchain-mcp-adapters langgraph langchain-anthropic mcp python-dotenvBefore implementing: look up the latest docs
The API has changed across versions (e.g., is no longer a context manager as of v0.1.0). Always check the latest docs before writing code. See langchain-mcp-reference.md.
langchain-mcp-adaptersMultiServerMCPClientIntegration pattern
- Create an MCP client using with stdio transport pointed at
MultiServerMCPClientnpx @picahq/mcp - Get tools from the client via
await client.get_tools() - Create a ReAct agent using from
create_react_agent(model, tools)langgraph.prebuilt - Stream or invoke the agent with your messages
- Pass environment variables (,
PICA_SECRET,PATH) to the MCP client'sHOMEconfigenv
Minimal example
python
from langchain_anthropic import ChatAnthropic
from langchain_mcp_adapters.client import MultiServerMCPClient
from langgraph.prebuilt import create_react_agent
model = ChatAnthropic(model="claude-haiku-4-5-20251001", streaming=True)
client = MultiServerMCPClient({
"pica": {
"command": "npx",
"args": ["@picahq/mcp"],
"transport": "stdio",
"env": {
"PICA_SECRET": os.environ.get("PICA_SECRET", ""),
"PATH": os.environ.get("PATH", ""),
"HOME": os.environ.get("HOME", ""),
},
},
})
tools = await client.get_tools()
agent = create_react_agent(model, tools)
# Invoke
result = await agent.ainvoke({"messages": [{"role": "user", "content": "..."}]})
# Or stream events
async for event in agent.astream_events({"messages": messages}, version="v2"):
kind = event["event"]
if kind == "on_chat_model_stream":
content = event["data"]["chunk"].content
# content may be a list of content blocks (Anthropic models) or a stringImportant: Anthropic content blocks
When streaming with , Anthropic models return as a list of content blocks, not plain strings. Always handle both:
astream_events(version="v2")chunk.contentpython
if isinstance(content, list):
text = "".join(
block.get("text", "") if isinstance(block, dict) else str(block)
for block in content
)
elif isinstance(content, str):
text = contentChecklist
When setting up PICA MCP with LangChain:
- ,
langchain-mcp-adapters,langgraph,langchain-anthropicare installedmcp - is set in
PICA_SECRET.env - is loaded via
.env(python-dotenvat top of file)load_dotenv() - MCP client uses stdio transport with
npx @picahq/mcp - and
PATHare passed in the MCP clientHOMEconfigenv - is NOT used as a context manager (API changed in v0.1.0)
MultiServerMCPClient - Streaming handles both list and string content from Anthropic models
- Tool events (,
on_tool_start) are handled for UI renderingon_tool_end
Additional resources
- For LangChain MCP adapter docs and API details, see langchain-mcp-reference.md