Skip to content

Commit

Permalink
fix: mcp CODE search error (#495)
Browse files Browse the repository at this point in the history
<!-- .github/pull_request_template.md -->

## Description
<!-- Provide a clear description of the changes in this PR -->

## DCO Affirmation
I affirm that all code in every commit of this pull request conforms to
the terms of the Topoteretes Developer Certificate of Origin


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Enhanced search functionality now returns JSON formatted results for
code-based queries for clearer response presentation.
  
- **Refactor**
- Updated the search logic to differentiate result handling based on
query type, maintaining string output for non-code queries.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
hande-k authored Feb 4, 2025
1 parent 1260fc7 commit 690d028
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cognee-mcp/src/server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
import os

import cognee
import logging
import importlib.util
Expand All @@ -12,6 +12,7 @@
from cognee.api.v1.cognify.code_graph_pipeline import run_code_graph_pipeline
from cognee.modules.search.types import SearchType
from cognee.shared.data_models import KnowledgeGraph
from cognee.modules.storage.utils import JSONEncoder

mcp = Server("cognee")

Expand Down Expand Up @@ -143,9 +144,11 @@ async def search(search_query: str, search_type: str) -> str:
query_type=SearchType[search_type.upper()], query_text=search_query
)

results = retrieved_edges_to_string(search_results)

return results
if search_type.upper() == "CODE":
return json.dumps(search_results, cls=JSONEncoder)
else:
results = retrieved_edges_to_string(search_results)
return results


async def prune():
Expand Down

0 comments on commit 690d028

Please sign in to comment.