Skip to main content
Connect your own Python LLM agent to Cognee MCP to give it persistent knowledge graph memory. The mcp Python SDK lets you call all Cognee MCP tools programmatically, without an IDE or chat client.
Prefer the v1.0 memory tools (remember, recall, forget) for new agent integrations. The legacy tools (cognify, search, delete) are still available when you need lower-level control.

Prerequisites

  • Python 3.10+
  • uv installed
  • LLM_API_KEY environment variable set (OpenAI key or equivalent)
  • mcp package installed in your agent environment:

Connection Options

Choose the transport that matches how you want your Python code to connect to Cognee MCP. Each option below creates the same kind of initialized ClientSession; the tool-calling code is shared in the next section.
Use stdio when your Python process should launch Cognee MCP as a subprocess and communicate over stdin/stdout.
Replace /absolute/path/to/cognee/cognee-mcp with the absolute path to the cognee-mcp directory in your cloned repository.

Send Requests

After you define one of the connect_to_cognee() functions above, the rest of your agent code is transport-agnostic. This example stores a fact with remember, then retrieves it with recall.

Inject context into your LLM calls

Once you have the retrieved context string, pass it to your LLM as part of the system or user prompt:

Key tools for agent context

See the Tools Reference for all available tools and parameters.

Need Help?

Join Our Community

Get support and connect with other developers using Cognee MCP.