mcp Python SDK lets you call all Cognee MCP tools programmatically, without an IDE or chat client.
The MCP server exposes the v1.0 memory tools (
remember, recall, forget), code_search for structured code-graph queries, improve for the self-improvement loop, and cognify_status. For lower-level control — explicit search types beyond recall’s options, custom graph models, dataset listing and creation — use the Python SDK or REST API.Prerequisites
- Python 3.10+
uvinstalledLLM_API_KEYenvironment variable set (OpenAI key or equivalent)mcppackage 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 initializedClientSession; the tool-calling code is shared in the next section.
- stdio
- HTTP
- SSE
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 theconnect_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
To give your own LLM what Cognee retrieved rather than Cognee’s answer, callrecall with only_context: True, then pass the text to your LLM as part of the system or user prompt. Without only_context, recall returns an answer an LLM already wrote. For completion search types the returned text is the user prompt Cognee built around the retrieved context, and the first line of the response is a memory-hit summary.
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.