Command Palette

Search for a command to run...

MCP Code Examples

Full examples using the official MCP SDKs to connect and use tools.

Python MCP Client
Using the official mcp Python SDK.
pip install
pip install mcp
python - main.py
import asyncio
from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client

API_KEY = "YOUR_API_KEY"
MCP_URL = "https://api.xobni.ai/mcp/"

async def main():
    headers = {"Authorization": f"Bearer {API_KEY}"}

    async with streamablehttp_client(MCP_URL, headers=headers) as (read, write, _):
        async with ClientSession(read, write) as session:
            await session.initialize()

            # List available tools
            tools = await session.list_tools()
            print("Available tools:")
            for t in tools.tools:
                print(f"  - {t.name}: {t.description[:60]}...")

            # Get agent info
            result = await session.call_tool("get_agent_info", {})
            print(f"\nAgent: {result}")

            # Read inbox (latest 5 emails)
            result = await session.call_tool("read_inbox", {"limit": 5})
            print(f"\nInbox: {result}")

            # Send an email
            result = await session.call_tool("send_email", {
                "to": ["friend@example.com"],
                "subject": "Hello from my AI agent!",
                "body_text": "This email was sent via MCP through Xobni.ai."
            })
            print(f"\nSent: {result}")

            # Search emails semantically
            result = await session.call_tool("search_emails", {
                "query": "meeting next week",
                "limit": 5
            })
            print(f"\nSearch results: {result}")

asyncio.run(main())
TypeScript / Node.js
Using the @modelcontextprotocol/sdk package.
npm install
npm install @modelcontextprotocol/sdk
typescript - index.ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";

const API_KEY = "YOUR_API_KEY";

async function main() {
  const transport = new StreamableHTTPClientTransport(
    new URL("https://api.xobni.ai/mcp/"),
    { requestInit: { headers: { Authorization: `Bearer ${API_KEY}` } } }
  );

  const client = new Client({ name: "my-app", version: "1.0.0" });
  await client.connect(transport);

  // List tools
  const { tools } = await client.listTools();
  console.log("Tools:", tools.map(t => t.name));

  // Read inbox
  const inbox = await client.callTool({
    name: "read_inbox",
    arguments: { limit: 5 }
  });
  console.log("Inbox:", inbox);

  // Search
  const search = await client.callTool({
    name: "search_emails",
    arguments: { query: "project update", limit: 3 }
  });
  console.log("Search:", search);

  await client.close();
}

main();