Agent guides

Use IPMusk with LangChain

Load the IPMusk tools into a LangChain or LangGraph agent with the langchain-mcp-adapters package.

Who this is for

Python developers building agents with LangChain or LangGraph.

What you need

  • An IPMusk account with a verified email address.
  • An IPMusk API key. Create it in Settings → API keys (/app/settings/api-keys). For typical use tick read and connect. Add support only if the assistant should open tickets, and order only if it should create orders that end in a payment link.
  • The key in an environment variable named IPMUSK_API_KEY, for example export IPMUSK_API_KEY="ipm_live_YOUR_KEY" in your shell profile. The examples below read it from there.
  • pip install langchain langchain-mcp-adapters, plus the package for your model provider.

Set it up

  • get_tools() returns every tool the key's scopes allow, as LangChain tools.
  • Older versions of langchain-mcp-adapters name the transport "streamable_http". Check the package docs for your version.
agent.py
import asyncio
import os

from langchain.agents import create_agent
from langchain_mcp_adapters.client import MultiServerMCPClient


async def main() -> None:
    client = MultiServerMCPClient(
        {
            "ipmusk": {
                "transport": "http",
                "url": "https://ipmusk.com/mcp",
                "headers": {"Authorization": f"Bearer {os.environ['IPMUSK_API_KEY']}"},
            }
        }
    )
    tools = await client.get_tools()
    agent = create_agent("YOUR_PROVIDER:YOUR_MODEL", tools)
    result = await agent.ainvoke(
        {"messages": [{"role": "user", "content": "How much residential traffic do I have left?"}]}
    )
    print(result["messages"][-1].content)


asyncio.run(main())

Check it works

Run the script. It should print an answer based on your real traffic balance.

To see the tools, print [tool.name for tool in tools].

Try these prompts

  • Which IPMusk account am I connected as?
  • How much residential traffic do I have left?
  • Build a rotating US residential proxy URL.

If it fails

  • KeyError: 'IPMUSK_API_KEY': the variable is not set in the shell that runs the script.
  • 401 authentication_required: the key is missing, wrong, revoked or expired. Check that IPMUSK_API_KEY is set where the client starts. echo ${#IPMUSK_API_KEY} prints its length without showing the key.
  • 403 forbidden on one tool: the key lacks that tool's scope, or your email is not verified. Scopes cannot be added to a key, so create a new key with the scope and swap it in.
  • 429 rate_limited: too many calls in one minute (read 60, connect 20, support 30, order 10). Wait a minute and try again.
  • Unsupported transport: upgrade langchain-mcp-adapters, or use streamable_http.

Remove access

  • Revoke the key in Settings → API keys (/app/settings/api-keys). It stops working at once.
  • Then remove the key from the environment or secret store the agent runs with.