-
Notifications
You must be signed in to change notification settings - Fork 967
Feat/mcp add support for non standalone mode #1523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Vasilije1990
merged 13 commits into
dev
from
feat/mcp-add-support-for-non-standalone-mode
Oct 12, 2025
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
806298d
create cognee_client for handling api calls
daukadolt 3e23c96
route server tools calls through cognee_client
daukadolt bd49dd7
Configure `cognee-cli -ui` mcp to connect to cognee backend
daukadolt 6730678
docs: update README.md
daukadolt c58d9ad
switch docker image from dev to main
daukadolt 0031a13
Refactor initialization of CogneeClient to use bool for API mode dete…
daukadolt 079a552
handle mcp shutdown cleanly, and remove the need for .env if in stand…
daukadolt 2c8d8e8
feat: handle cli processes cleanup when terminal window is closed
daukadolt fb03f9c
Merge branch 'dev' into feat/mcp-add-support-for-non-standalone-mode
daukadolt 446a378
chore: update Docker image for MCP server to feature branch for testing
daukadolt c7ca4c6
chore: update Docker image comment and improve import handling for Co…
daukadolt d480ea2
docs: clarify API_TOKEN requirement in README and improve JSON handli…
daukadolt 4ac49dd
Merge branch 'dev' into feat/mcp-add-support-for-non-standalone-mode
Vasilije1990 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,61 +14,94 @@ HTTP_PORT=${HTTP_PORT:-8000} | |
| echo "Debug port: $DEBUG_PORT" | ||
| echo "HTTP port: $HTTP_PORT" | ||
|
|
||
| # Run Alembic migrations with proper error handling. | ||
| # Note on UserAlreadyExists error handling: | ||
| # During database migrations, we attempt to create a default user. If this user | ||
| # already exists (e.g., from a previous deployment or migration), it's not a | ||
| # critical error and shouldn't prevent the application from starting. This is | ||
| # different from other migration errors which could indicate database schema | ||
| # inconsistencies and should cause the startup to fail. This check allows for | ||
| # smooth redeployments and container restarts while maintaining data integrity. | ||
| echo "Running database migrations..." | ||
| # Check if API mode is enabled | ||
| if [ -n "$API_URL" ]; then | ||
| echo "API mode enabled: $API_URL" | ||
| echo "Skipping database migrations (API server handles its own database)" | ||
| else | ||
| echo "Direct mode: Using local cognee instance" | ||
| # Run Alembic migrations with proper error handling. | ||
| # Note on UserAlreadyExists error handling: | ||
| # During database migrations, we attempt to create a default user. If this user | ||
| # already exists (e.g., from a previous deployment or migration), it's not a | ||
| # critical error and shouldn't prevent the application from starting. This is | ||
| # different from other migration errors which could indicate database schema | ||
| # inconsistencies and should cause the startup to fail. This check allows for | ||
| # smooth redeployments and container restarts while maintaining data integrity. | ||
| echo "Running database migrations..." | ||
|
|
||
| MIGRATION_OUTPUT=$(alembic upgrade head) | ||
| MIGRATION_EXIT_CODE=$? | ||
| MIGRATION_OUTPUT=$(alembic upgrade head) | ||
| MIGRATION_EXIT_CODE=$? | ||
|
|
||
| if [[ $MIGRATION_EXIT_CODE -ne 0 ]]; then | ||
| if [[ "$MIGRATION_OUTPUT" == *"UserAlreadyExists"* ]] || [[ "$MIGRATION_OUTPUT" == *"User [email protected] already exists"* ]]; then | ||
| echo "Warning: Default user already exists, continuing startup..." | ||
| else | ||
| echo "Migration failed with unexpected error." | ||
| exit 1 | ||
| if [[ $MIGRATION_EXIT_CODE -ne 0 ]]; then | ||
| if [[ "$MIGRATION_OUTPUT" == *"UserAlreadyExists"* ]] || [[ "$MIGRATION_OUTPUT" == *"User [email protected] already exists"* ]]; then | ||
| echo "Warning: Default user already exists, continuing startup..." | ||
| else | ||
| echo "Migration failed with unexpected error." | ||
| exit 1 | ||
| fi | ||
| fi | ||
| fi | ||
|
|
||
| echo "Database migrations done." | ||
| echo "Database migrations done." | ||
| fi | ||
|
|
||
| echo "Starting Cognee MCP Server with transport mode: $TRANSPORT_MODE" | ||
|
|
||
| # Add startup delay to ensure DB is ready | ||
| sleep 2 | ||
|
|
||
| # Build API arguments if API_URL is set | ||
| API_ARGS="" | ||
| if [ -n "$API_URL" ]; then | ||
| # Handle localhost in API_URL - convert to host-accessible address | ||
| if echo "$API_URL" | grep -q "localhost" || echo "$API_URL" | grep -q "127.0.0.1"; then | ||
| echo "⚠️ Warning: API_URL contains localhost/127.0.0.1" | ||
| echo " Original: $API_URL" | ||
|
|
||
| # Try to use host.docker.internal (works on Mac/Windows and recent Linux with Docker Desktop) | ||
| FIXED_API_URL=$(echo "$API_URL" | sed 's/localhost/host.docker.internal/g' | sed 's/127\.0\.0\.1/host.docker.internal/g') | ||
|
|
||
| echo " Converted to: $FIXED_API_URL" | ||
| echo " This will work on Mac/Windows/Docker Desktop." | ||
| echo " On Linux without Docker Desktop, you may need to:" | ||
| echo " - Use --network host, OR" | ||
| echo " - Set API_URL=http://172.17.0.1:8000 (Docker bridge IP)" | ||
|
|
||
| API_URL="$FIXED_API_URL" | ||
| fi | ||
|
|
||
| API_ARGS="--api-url $API_URL" | ||
| if [ -n "$API_TOKEN" ]; then | ||
| API_ARGS="$API_ARGS --api-token $API_TOKEN" | ||
| fi | ||
| fi | ||
|
|
||
| # Modified startup with transport mode selection and error handling | ||
| if [ "$ENVIRONMENT" = "dev" ] || [ "$ENVIRONMENT" = "local" ]; then | ||
| if [ "$DEBUG" = "true" ]; then | ||
| echo "Waiting for the debugger to attach..." | ||
| if [ "$TRANSPORT_MODE" = "sse" ]; then | ||
| exec python -m debugpy --wait-for-client --listen 0.0.0.0:$DEBUG_PORT -m cognee-mcp --transport sse --host 0.0.0.0 --port $HTTP_PORT --no-migration | ||
| exec python -m debugpy --wait-for-client --listen 0.0.0.0:$DEBUG_PORT -m cognee-mcp --transport sse --host 0.0.0.0 --port $HTTP_PORT --no-migration $API_ARGS | ||
| elif [ "$TRANSPORT_MODE" = "http" ]; then | ||
| exec python -m debugpy --wait-for-client --listen 0.0.0.0:$DEBUG_PORT -m cognee-mcp --transport http --host 0.0.0.0 --port $HTTP_PORT --no-migration | ||
| exec python -m debugpy --wait-for-client --listen 0.0.0.0:$DEBUG_PORT -m cognee-mcp --transport http --host 0.0.0.0 --port $HTTP_PORT --no-migration $API_ARGS | ||
| else | ||
| exec python -m debugpy --wait-for-client --listen 0.0.0.0:$DEBUG_PORT -m cognee-mcp --transport stdio --no-migration | ||
| exec python -m debugpy --wait-for-client --listen 0.0.0.0:$DEBUG_PORT -m cognee-mcp --transport stdio --no-migration $API_ARGS | ||
| fi | ||
| else | ||
| if [ "$TRANSPORT_MODE" = "sse" ]; then | ||
| exec cognee-mcp --transport sse --host 0.0.0.0 --port $HTTP_PORT --no-migration | ||
| exec cognee-mcp --transport sse --host 0.0.0.0 --port $HTTP_PORT --no-migration $API_ARGS | ||
| elif [ "$TRANSPORT_MODE" = "http" ]; then | ||
| exec cognee-mcp --transport http --host 0.0.0.0 --port $HTTP_PORT --no-migration | ||
| exec cognee-mcp --transport http --host 0.0.0.0 --port $HTTP_PORT --no-migration $API_ARGS | ||
| else | ||
| exec cognee-mcp --transport stdio --no-migration | ||
| exec cognee-mcp --transport stdio --no-migration $API_ARGS | ||
| fi | ||
| fi | ||
| else | ||
| if [ "$TRANSPORT_MODE" = "sse" ]; then | ||
| exec cognee-mcp --transport sse --host 0.0.0.0 --port $HTTP_PORT --no-migration | ||
| exec cognee-mcp --transport sse --host 0.0.0.0 --port $HTTP_PORT --no-migration $API_ARGS | ||
| elif [ "$TRANSPORT_MODE" = "http" ]; then | ||
| exec cognee-mcp --transport http --host 0.0.0.0 --port $HTTP_PORT --no-migration | ||
| exec cognee-mcp --transport http --host 0.0.0.0 --port $HTTP_PORT --no-migration $API_ARGS | ||
| else | ||
| exec cognee-mcp --transport stdio --no-migration | ||
| exec cognee-mcp --transport stdio --no-migration $API_ARGS | ||
| fi | ||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.