BrainAPI is a knowledge graph–powered AI memory layer that transforms unstructured data into structured knowledge, enabling intelligent search, recommendations, and contextual memory for AI agents and applications.
Python ai-agentsai-memoryknowledge-graphknowledge-managementknowledge-representationreccomendation-system
feat(mcp)
Christian570a5e9703f6
diff --git a/Makefile b/Makefileindex 79894fc..7d2dc2d 100644--- a/Makefile+++ b/Makefile@@ -51,10 +51,16 @@ delete-mongo-volumes:docker compose -f src/lib/mongo/docker-compose.yaml down -v --remove-orphansstart-api:- ENV=development poetry run uvicorn src.services.api.app:app --host 0.0.0.0 --port 8000 --access-log --log-level info --reload+ ENV=development poetry run python -m uvicorn src.services.api.app:app --host 0.0.0.0 --port 8000 --access-log --log-level info --reloadstop-api:- pkill -f uvicorn+ pkill -f "uvicorn src.services.api.app"++start-mcp:+ ENV=development poetry run python -m uvicorn src.services.mcp.app:app --host 0.0.0.0 --port 8001 --access-log --log-level info --reload++stop-mcp:+ pkill -f "uvicorn src.services.mcp.app"DEBUG_ENVS := LANGCHAIN_DEBUG="true" LANGCHAIN_VERBOSE="true" DEBUG="true"@@ -66,16 +72,18 @@ start-all:$(MAKE) start-redis DEBUG=true & \$(MAKE) start-neo4j DEBUG=true & \$(MAKE) start-mongo DEBUG=true & \+ $(MAKE) start-mcp DEBUG=true & \ENV="development" $(MAKE) start-api DEBUG=true & \- bash -c "export $(DEBUG_ENVS) ENV="development" && poetry run celery -A src.workers.app worker --loglevel=info --pool=threads --concurrency=10"; \+ bash -c "export $(DEBUG_ENVS) ENV="development" && poetry run celery -A src.workers.app worker --loglevel=info --pool=threads"; \else \$(MAKE) start-milvus & \$(MAKE) start-rabbitmq & \$(MAKE) start-redis & \$(MAKE) start-neo4j & \$(MAKE) start-mongo & \+ $(MAKE) start-mcp & \ENV="development" $(MAKE) start-api & \- ENV="development" poetry run celery -A src.workers.app worker --loglevel=info --pool=threads --concurrency=10; \+ ENV="development" poetry run celery -A src.workers.app worker --loglevel=info --pool=threads; \fidebug:@@ -88,6 +96,7 @@ stop-all:make stop-neo4jmake stop-mongomake stop-api+ make stop-mcppkill -f celeryclear-all-volumes:diff --git a/src/services/api/app.py b/src/services/api/app.pyindex 9d0dfb8..c564a22 100644--- a/src/services/api/app.py+++ b/src/services/api/app.py@@ -3,8 +3,8 @@ File: /app.pyCreated Date: Sunday October 19th 2025Author: Christian Nonis <[email protected]>------Last Modified: Saturday December 27th 2025-Modified By: the developer formerly known as Christian Nonis at <[email protected]>+Last Modified: Monday February 9th 2026 9:48:30 pm+Modified By: Christian Nonis <[email protected]>-----"""diff --git a/src/services/api/middlewares/auth.py b/src/services/api/middlewares/auth.pyindex 9e37262..ef42031 100644--- a/src/services/api/middlewares/auth.py+++ b/src/services/api/middlewares/auth.py@@ -4,7 +4,7 @@ Created Date: Thursday November 27th 2025Author: Christian Nonis <[email protected]>-----Last Modified: Thursday November 27th 2025 10:20:03 pm-Modified By: the developer formerly known as Christian Nonis at <[email protected]>+Modified By: Christian Nonis <[email protected]>-----"""@@ -27,6 +27,12 @@ class BrainPATMiddleware(BaseHTTPMiddleware):brainpat = request.headers.get("BrainPAT") or getattr(request.state, "pat", None)+ if not brainpat:+ brainpat = request.headers.get("Authorization")+ if brainpat:+ brainpat = brainpat.split(" ")[1]+ if brainpat:+ brainpat = brainpat.rstrip()system_pat = os.getenv("BRAINPAT_TOKEN")if request.url.path.startswith("/system") or request.url.path == "/":diff --git a/src/services/api/middlewares/brains.py b/src/services/api/middlewares/brains.pyindex 3871c0f..11f7d23 100644--- a/src/services/api/middlewares/brains.py+++ b/src/services/api/middlewares/brains.py@@ -4,7 +4,7 @@ Created Date: Monday December 1st 2025Author: Christian Nonis <[email protected]>-----Last Modified: Monday December 1st 2025 9:06:30 pm-Modified By: the developer formerly known as Christian Nonis at <[email protected]>+Modified By: Christian Nonis <[email protected]>-----"""diff --git a/src/services/mcp/__init__.py b/src/services/mcp/__init__.pynew file mode 100644index 0000000..736d5f8--- /dev/null+++ b/src/services/mcp/__init__.py@@ -0,0 +1,10 @@+"""+File: /__init__.py+Project: mcp+Created Date: Tuesday February 10th 2026+Author: Christian Nonis <[email protected]>+-----+Last Modified: Tuesday February 10th 2026 8:30:05 pm+Modified By: Christian Nonis <[email protected]>+-----+"""diff --git a/src/services/mcp/app.py b/src/services/mcp/app.pynew file mode 100644index 0000000..56c4090--- /dev/null+++ b/src/services/mcp/app.py@@ -0,0 +1,10 @@+from pathlib import Path++import dotenv++_project_root = Path(__file__).resolve().parent.parent.parent+dotenv.load_dotenv(_project_root / ".env")++from src.services.mcp.main import mcp++app = mcp.streamable_http_app()diff --git a/src/services/mcp/main.py b/src/services/mcp/main.pynew file mode 100644index 0000000..c685a13--- /dev/null+++ b/src/services/mcp/main.py@@ -0,0 +1,64 @@+"""+File: /main.py+Project: mcp+Created Date: Tuesday February 10th 2026+Author: Christian Nonis <[email protected]>+-----+Last Modified: Tuesday February 10th 2026 8:30:11 pm+Modified By: Christian Nonis <[email protected]>+-----+"""++from typing import Any+from mcp.server import FastMCP+from pydantic import BaseModel+from src.lib.neo4j.client import _neo4j_client+from src.services.data.main import data_adapter+from src.services.kg_agent.main import graph_adapter++mcp = FastMCP("brainapi-mcp", stateless_http=True)+++def get_search_operation_instructions(message: str) -> str:+ """+ This tool will provide instructions on how to use the search_memory tool.+ """+ return f"""+ The brains are a storage for information and memories, they are powered by multiple dbs.+ The `search_memory` tool will execute graph operations to search the knowledge graph that contains informations.+ {_neo4j_client.graphdb_description}.+ The input must be a JSON object with the following fields:+ - db_query: str: the operation to execute on the graph.+ - brain_id: str: the brain to search in.+ """+++class SearchMemoryInput(BaseModel):+ db_query: str+ brain_id: str+++def search_memory(db_query: str, brain_id: str) -> Any:+ """+ Search the brain for memories and information.+ This tool will search into the knowledge graph.++ Input must be a JSON object with the following fields:+ - db_query: str: the operation to execute on the graph.+ - brain_id: str: the brain to search in.+ """+ try:+ return graph_adapter.execute_operation(db_query, brain_id)+ except Exception as e:+ return f"Error executing graph operation: {e}"+++def list_brains() -> list[str]:+ """+ This tool lists all the brains/memory stores available+ """+ brains = data_adapter.get_brains_list()+ return [brain.name_key for brain in brains]diff --git a/src/services/webserver/nginx/nginx.conf b/src/services/webserver/nginx/nginx.confindex 77fdce1..ceb5ebc 100644--- a/src/services/webserver/nginx/nginx.conf+++ b/src/services/webserver/nginx/nginx.conf@@ -12,6 +12,15 @@ server {client_max_body_size 50m;+ location /mcp {+ proxy_pass http://127.0.0.1:8001;+ proxy_http_version 1.1;+ proxy_set_header Host $host;+ proxy_set_header X-Real-IP $remote_addr;+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;+ proxy_set_header X-Forwarded-Proto $scheme;+ }+location / {proxy_pass http://127.0.0.1:8000;proxy_http_version 1.1;