Integration Guides

OpenAI Agents

Bridge HyperMemory MCP tools to OpenAI function calling

OpenAI Agents

OpenAI’s function calling API does not speak MCP natively. You bridge it by calling the HyperMemory MCP endpoint over HTTP and mapping the results back to OpenAI’s tool format.

HTTP client

import os
import httpx

class HyperMemoryMCP:
    def __init__(self):
        self.url = "https://api.hypermemory.io/mcp"
        self.key = os.environ["HYPERMEMORY_API_KEY"]

    def call(self, tool: str, args: dict) -> dict:
        r = httpx.post(
            self.url,
            json={
                "jsonrpc": "2.0",
                "id": 1,
                "method": "tools/call",
                "params": {"name": tool, "arguments": args},
            },
            headers={"Authorization": f"Bearer {self.key}"},
            timeout=30.0,
        )
        return r.json().get("result", {})

Define OpenAI functions

Map hm_store and hm_recall to OpenAI function schemas. See hm_store and hm_recall for exact parameter shapes.

TOOLS = [
    {
        "type": "function",
        "function": {
            "name": "hm_store",
            "description": "Store a memory node in the knowledge graph",
            "parameters": {
                "type": "object",
                "properties": {
                    "key": {"type": "string", "description": "Unique node key, format: {type}_{name}"},
                    "description": {"type": "string", "description": "What this memory represents"},
                    "node_type": {"type": "string", "description": "Node type (person, decision, concept, etc.)"},
                    "data": {"type": "object", "description": "Structured metadata"},
                },
                "required": ["key", "description"],
            },
        },
    },
    {
        "type": "function",
        "function": {
            "name": "hm_recall",
            "description": "Search memory using hybrid search (BM25 + vector + regex)",
            "parameters": {
                "type": "object",
                "properties": {
                    "query": {"type": "string", "description": "Search query"},
                },
                "required": ["query"],
            },
        },
    },
]

Dispatch tool calls

import json
from openai import OpenAI

client = OpenAI()
memory = HyperMemoryMCP()

def handle_tool_call(tool_call):
    name = tool_call.function.name
    args = json.loads(tool_call.function.arguments)
    return memory.call(name, args)

Pass TOOLS to client.chat.completions.create(tools=TOOLS), then dispatch each tool_call through handle_tool_call. See the OpenAI function calling docs for the full loop.

REST API alternative

You can also use the REST API instead of the MCP JSON-RPC format. REST endpoints accept standard JSON bodies with Authorization: Bearer hm_YOUR_KEY headers.