Agent guides

Use IPMusk with the MCP Python SDK

Talk to the IPMusk MCP server directly from Python with the official MCP SDK. Useful for scripts and for building your own agent loop.

Who this is for

Python developers who want to call IPMusk tools directly, without an agent framework.

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.
  • Python 3.10 or later and pip install mcp httpx.

Set it up

  • build_proxy_url needs the connect scope. Tool results come back as structuredContent plus the same JSON as text.
  • Version 1 of the SDK uses streamablehttp_client(url, headers=...) instead of passing an httpx client. Check the SDK docs for your version.
client.py
import asyncio
import os

import httpx
from mcp import ClientSession
from mcp.client.streamable_http import streamable_http_client

MCP_URL = "https://ipmusk.com/mcp"


async def main() -> None:
    headers = {"Authorization": f"Bearer {os.environ['IPMUSK_API_KEY']}"}
    async with httpx.AsyncClient(headers=headers, follow_redirects=True) as http:
        async with streamable_http_client(url=MCP_URL, http_client=http) as streams:
            read, write = streams[0], streams[1]
            async with ClientSession(read, write) as session:
                await session.initialize()
                tools = await session.list_tools()
                print([tool.name for tool in tools.tools])
                result = await session.call_tool(
                    "build_proxy_url", {"country": "US", "session": "rotating"}
                )
                print(result.structuredContent)


asyncio.run(main())

Check it works

Run the script. It should print the list of tool names, then one proxy URL.

Try these prompts

  • Call get_account to see which account the key belongs to.
  • Call get_usage with {"days": 7} to see recent traffic.
  • Call build_proxy_url with {"country": "DE", "session": "sticky", "sticky_minutes": 10}.

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.
  • A tool result has isError set: read its text, which starts with an error code such as forbidden or not_found.
  • 429 rate_limited: too many calls in one minute (read 60, connect 20, support 30, order 10). Wait a minute and try again.
  • ImportError for streamable_http_client: you have SDK version 1. Use streamablehttp_client, or upgrade.

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 the script runs in.