diff --git a/cognee-mcp/src/__init__.py b/cognee-mcp/src/__init__.py index a9f366bde..3081d5c25 100644 --- a/cognee-mcp/src/__init__.py +++ b/cognee-mcp/src/__init__.py @@ -1,5 +1,6 @@ from .server import mcp + def main(): """Main entry point for the package.""" mcp.run(transport="stdio") diff --git a/cognee-mcp/src/client.py b/cognee-mcp/src/client.py index d972fb84c..202b109fb 100644 --- a/cognee-mcp/src/client.py +++ b/cognee-mcp/src/client.py @@ -4,9 +4,9 @@ from mcp.client.stdio import stdio_client # Create server parameters for stdio connection server_params = StdioServerParameters( - command="mcp", # Executable - args=["run", "src/server.py"], # Optional command line arguments - env=None # Optional environment variables + command="mcp", # Executable + args=["run", "src/server.py"], # Optional command line arguments + env=None, # Optional environment variables ) text = """ @@ -27,6 +27,7 @@ brain, that can ‘learn’ from available data and make increasingly more accurate classifications or predictions over time. """ + async def run(): async with stdio_client(server_params) as (read, write): async with ClientSession(read, write, timedelta(minutes=3)) as session: @@ -37,6 +38,8 @@ async def run(): print(f"Cognify result: {toolResult}") + if __name__ == "__main__": import asyncio + asyncio.run(run()) diff --git a/cognee-mcp/src/server.py b/cognee-mcp/src/server.py index 3584163f0..ed603febb 100644 --- a/cognee-mcp/src/server.py +++ b/cognee-mcp/src/server.py @@ -1,6 +1,7 @@ import os import cognee import importlib.util + # from PIL import Image as PILImage from mcp.server.fastmcp import FastMCP from cognee.api.v1.search import SearchType @@ -8,6 +9,7 @@ from cognee.shared.data_models import KnowledgeGraph mcp = FastMCP("cognee", timeout=120000) + @mcp.tool() async def cognify(text: str, graph_model_file: str = None, graph_model_name: str = None) -> str: """Build knowledge graph from the input text""" @@ -19,9 +21,9 @@ async def cognify(text: str, graph_model_file: str = None, graph_model_name: str await cognee.add(text) try: - await cognee.cognify(graph_model=graph_model) + await cognee.cognify(graph_model=graph_model) except Exception as e: - raise ValueError(f"Failed to cognify: {str(e)}") + raise ValueError(f"Failed to cognify: {str(e)}") return "Ingested" @@ -57,7 +59,6 @@ async def prune() -> str: # raise ValueError(f"Failed to create visualization: {str(e)}") - def node_to_string(node): node_data = ", ".join( [f'{key}: "{value}"' for key, value in node.items() if key in ["id", "name"]]