Skip to content

Strategy guide

Connect a LangChain trading agent to Fensory

LangChain can connect to the remote Fensory MCP server through its current MCPAdapter and a FastMCP client configured for browser OAuth. The verified setup opens the Fensory authorization screen, returns the current tool catalogue and keeps credentials out of the script.

Start by proving the connection and reading account capabilities without placing an order. Tool discovery confirms that the client can see the server. It does not prove that a market is available, that trading is enabled or that an order would pass the account controls. LangChain labels this MCP integration as beta, so pin and retest the dependency before deploying it.

Copy this prompt

Use the connected Fensory tools in read-only mode. First confirm the current tool catalogue and identify the signed-in account. Call get-my-wallets, get_perps_status, get_spot_metadata and get_user_fees. Report which account is connected, whether perpetual-futures trading is ready, which Hyperliquid spot markets are visible and what fee information the account returns. Separate tool availability from account permission and market availability. Do not place, modify, cancel or close an order. Do not change leverage or margin. Do not infer that trading is enabled because a write tool appears in the catalogue. If authentication, account identity or a required read fails, report the exact failed step and stop.

Who this is for

This guide is for a Python developer or technical operator connecting a LangChain agent to an eligible Fensory account through the remote MCP endpoint.

What it is not

It is not a hosted agent, an unattended trading loop or a CrewAI setup guide. It does not require a copied bearer token and it does not place an order during connection verification.

What you need

  • Python and the LangChain MCP extra

    The verified environment used Python 3.12, LangChain 1.4.6 and FastMCP 4.1.1. LangChain marks the MCP adapter as beta, so keep the package version visible in the project and re-run discovery after an upgrade.

  • An eligible Fensory account

    Fensory is not available to US persons. Browser OAuth signs the MCP client into one Fensory account. Confirm the account shown during authorization before accepting access.

  • A local browser callback

    FastMCP opens an authorization page and listens on a temporary localhost callback. Keep the Python process running until the browser reports that authentication succeeded.

Connect LangChain

Install the current LangChain MCP integration

pip install "langchain[mcp]>=1.4.0"

Open Fensory OAuth and verify tool discovery

import asyncio from fastmcp import Client from langchain.mcp import MCPAdapter async def main() -> None: client = Client("https://mcp.fensory.com/mcp", auth="oauth") async with MCPAdapter(client) as adapter: tools = await adapter.list_tools() print(f"Connected to {len(tools)} Fensory tools") if __name__ == "__main__": asyncio.run(main())

What the agent does

  1. 01

    Install and pin the MCP dependency

    Install the LangChain MCP extra in an isolated environment and record the resolved LangChain and FastMCP versions. The integration is beta, so an unpinned upgrade can change the adapter or authentication behavior.

  2. 02

    Configure browser OAuth explicitly

    Create a FastMCP Client for the Fensory endpoint with auth set to oauth, then pass that client to MCPAdapter. Passing only the URL does not start the required browser authorization flow.

  3. 03

    Discover the current tools

    Call list_tools inside the adapter context and print the returned count. Read the live list rather than hard-coding a count because the MCP surface can change independently of this guide.

  4. 04

    Verify account and market reads

    Run read tools before attaching a model to any write-capable workflow. Confirm the signed-in account, trading readiness, visible spot markets and fee state. A visible write tool is not proof that the account will permit an order.

    Tools: get-my-wallets · get_perps_status · get_spot_metadata · get_user_fees

  5. 05

    Attach tools to the agent last

    After the connection and account checks pass, provide the discovered tools to the LangChain agent and begin with the read-only prompt on this page. Add write behavior only with explicit account limits, action previews and confirmation rules.

Failure modes and limits

  • The browser never opens

    Check that the FastMCP Client was created with auth set to oauth. A URL passed directly to MCPAdapter does not configure the browser flow for this protected endpoint.

  • The callback does not complete

    Keep the Python process running, allow the temporary localhost callback and finish authorization in the same browser session. Restart the process if its callback has already closed.

  • The wrong Fensory account is authorized

    OAuth follows the Fensory session active in the browser. Stop and sign into the intended account before authorizing if the consent screen shows a different identity.

  • Tool discovery is treated as trading access

    The catalogue describes what the server can expose. Market availability, account status, allow-lists, access expiry and order caps still determine whether an action can proceed.

  • CrewAI is assumed to use the same login path

    It does not today. CrewAI 1.15.28 supports Streamable HTTP with supplied authorization headers, but its native client did not launch Fensory browser OAuth and returned 401 in the live test. Do not copy tokens into a workaround.

  • A dependency upgrade changes the beta API

    Re-run the discovery script after changing LangChain or FastMCP. Keep the last verified versions and date with the deployment so a connection failure can be separated from a Fensory account issue.

Read the result in the terminal

OAuth result
The browser should report successful authentication for the Fensory MCP endpoint before the script proceeds to tool discovery.
Tool catalogue
Use the list returned during the current session. Do not infer account permissions from names alone and do not preserve an old count as a capability guarantee.
Account reads
Record the signed-in wallet, perpetual-futures readiness, spot metadata and fee state before a model receives any write-capable tool.

Where this runs

This workflow runs in your Python process through LangChain. Fensory provides the remote MCP server, browser authorization and account tools. The framework process, model configuration and runtime remain under your control.

Questions people ask

Does LangChain support remote MCP servers?
Yes. The current LangChain MCPAdapter is built on FastMCP and accepts a FastMCP client for a remote Streamable HTTP endpoint. LangChain currently marks this integration as beta.
Does the Fensory login token go in the Python file?
No. Configure the FastMCP client with browser OAuth. The user signs into Fensory in the browser and the script does not contain a copied bearer token.
Does discovering the tools enable trading?
No. Discovery confirms that the client can read the server catalogue. Account status, allowed markets, access expiry, order caps and the requested action are checked separately.
Can I use this same setup with CrewAI?
Not as written. CrewAI supports Streamable HTTP, but its native MCP HTTP client did not complete Fensory browser OAuth in the verified test. The combined CrewAI setup remains unpublished until that login path works end to end.
Should the first LangChain prompt place a trade?
No. Begin with account identity, status, market and fee reads. Add write behavior only after the connection is stable and the agent has explicit action previews, confirmation instructions and account limits.