Skip to main content

Install

pip install mcp

Connect

import asyncio
from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client

API_KEY = "YOUR_API_KEY"

async def main():
    async with streamablehttp_client(
        url="https://mcp.actionlayer.dev/mcp",
        headers={"Authorization": f"Bearer {API_KEY}"}
    ) as (read, write, _):
        async with ClientSession(read, write) as session:
            await session.initialize()

            # List available tools
            tools = await session.list_tools()
            print([t.name for t in tools.tools])

asyncio.run(main())

Call a Tool

async with ClientSession(read, write) as session:
    await session.initialize()

    # List threads needing review
    result = await session.call_tool(
        "list_threads",
        arguments={"needs_review": True, "limit": 10}
    )
    print(result.content)

Submit a Draft

result = await session.call_tool(
    "submit_draft",
    arguments={
        "thread_id": "THREAD_ID",
        "identity_id": "IDENTITY_ID",
        "based_on_message_id": "MESSAGE_ID",
        "subject": "Re: Your inquiry",
        "body": "Thank you for reaching out...",
        "rationale": "Customer asked about pricing."
    }
)
The draft enters the approval queue. Nothing is sent until a human approves it (or the identity has approval_mode: auto).

Read Resources

# Get current workspace info
resource = await session.read_resource("workspace://current")

# Get active identities
resource = await session.read_resource("identities://active")

# Get recent threads
resource = await session.read_resource("threads://recent")

Error Handling

Authentication failures raise PermissionError. Invalid tool arguments return a structured error in result.content.