Skip to content

dbhub sometimes crashed when mcp client (dify, cursor) started to use it run SQL #38

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

Open
manzhu opened this issue May 1, 2025 · 8 comments
Assignees

Comments

@manzhu
Copy link

manzhu commented May 1, 2025

Running dbhub in docker and use Dify to test the MCP. However the docker instance got corrupted in each test.

Could you please advise what may cause the error below? Thank you so much!

=====
Successfully connected to MySQL database
Using transport: sse
Transport source: command line argument


| __ | _ | | | | | |
| | | | |) | || |_ | |_
| | | | _ <| _ | | | | '_ \
| || | |) | | | | || | |_) |
|
_/|/|| ||_,|_./

v0.4.0 - Universal Database MCP Server

Port source: command line argument
DBHub server listening at http://localhost:8080
Connect to MCP server at http://localhost:8080/sse
Client connected 608594b2-fe14-4c5c-a0e4-c482f093d279
Client Message 608594b2-fe14-4c5c-a0e4-c482f093d279
Client Message 608594b2-fe14-4c5c-a0e4-c482f093d279
Client Message 608594b2-fe14-4c5c-a0e4-c482f093d279
Client Disconnected 608594b2-fe14-4c5c-a0e4-c482f093d279
Client Message 608594b2-fe14-4c5c-a0e4-c482f093d279
file:///app/node_modules/.pnpm/@modelcontextprotocol+sdk@1.6.1/node_modules/@modelcontextprotocol/sdk/dist/esm/server/sse.js:53
throw new Error(message);
^

Error: SSE connection not established
at SSEServerTransport.handlePostMessage (file:///app/node_modules/.pnpm/@modelcontextprotocol+sdk@1.6.1/node_modules/@modelcontextprotocol/sdk/dist/esm/server/sse.js:53:19)
at file:///app/dist/index.js:3257:25
at Layer.handle [as handle_request] (/app/node_modules/.pnpm/express@4.21.2/node_modules/express/lib/router/layer.js:95:5)
at next (/app/node_modules/.pnpm/express@4.21.2/node_modules/express/lib/router/route.js:149:13)
at Route.dispatch (/app/node_modules/.pnpm/express@4.21.2/node_modules/express/lib/router/route.js:119:3)
at Layer.handle [as handle_request] (/app/node_modules/.pnpm/express@4.21.2/node_modules/express/lib/router/layer.js:95:5)
at /app/node_modules/.pnpm/express@4.21.2/node_modules/express/lib/router/index.js:284:15
at Function.process_params (/app/node_modules/.pnpm/express@4.21.2/node_modules/express/lib/router/index.js:346:12)
at next (/app/node_modules/.pnpm/express@4.21.2/node_modules/express/lib/router/index.js:280:10)
at expressInit (/app/node_modules/.pnpm/express@4.21.2/node_modules/express/lib/middleware/init.js:40:5)

Node.js v22.15.0

@tianzhou
Copy link
Contributor

tianzhou commented May 1, 2025

Could you please paste the screenshot showing how dbhub is configured in dify and which command triggers the crash?

The log suggests the dbhub docker container started successfully. Other than that, the pasted log doesn't reveal any useful clue.

@zhengyi73
Copy link

zhengyi73 commented May 5, 2025

I got exactly same error. The mcp server crashed and service stopped running.
May 5 22:41:19 ecs-14876993 rc.local[1081]: INFO: xx.xx.xx.xx:58580 - "POST /v1/chat/completions HTTP/1.1" 200 OK
May 5 22:41:19 ecs-14876993 rc.local[1081]: INFO 05-05 22:41:18 [async_llm.py:252] Added request chatcmpl-fd53a682d9294674952fc41d61b02fd8.
May 5 22:41:19 ecs-14876993 rc.local[1710]: Client Message 456f13bd-9c98-43e9-9f2f-30a6316a09e5
May 5 22:41:19 ecs-14876993 rc.local[1710]: file:///root/.npm/_npx/e23b069b9efbbb8f/node_modules/@modelcontextprotocol/sdk/dist/esm/server/sse.js:61
May 5 22:41:19 ecs-14876993 rc.local[1710]: throw new Error(message);
May 5 22:41:19 ecs-14876993 rc.local[1710]: ^
May 5 22:41:19 ecs-14876993 rc.local[1710]: Error: SSE connection not established
May 5 22:41:19 ecs-14876993 rc.local[1710]: at SSEServerTransport.handlePostMessage (file:///root/.npm/_npx/e23b069b9efbbb8f/node_modules/@modelcontextprotocol/sdk/dist/esm/server/sse.js:61:19)
May 5 22:41:19 ecs-14876993 rc.local[1710]: at file:///root/.npm/_npx/e23b069b9efbbb8f/node_modules/@bytebase/dbhub/dist/index.js:3280:25
May 5 22:41:19 ecs-14876993 rc.local[1710]: at Layer.handle [as handle_request] (/root/.npm/_npx/e23b069b9efbbb8f/node_modules/express/lib/router/layer.js:95:5)
May 5 22:41:19 ecs-14876993 rc.local[1710]: at next (/root/.npm/_npx/e23b069b9efbbb8f/node_modules/express/lib/router/route.js:149:13)
May 5 22:41:19 ecs-14876993 rc.local[1710]: at Route.dispatch (/root/.npm/_npx/e23b069b9efbbb8f/node_modules/express/lib/router/route.js:119:3)
May 5 22:41:19 ecs-14876993 rc.local[1710]: at Layer.handle [as handle_request] (/root/.npm/_npx/e23b069b9efbbb8f/node_modules/express/lib/router/layer.js:95:5)
May 5 22:41:19 ecs-14876993 rc.local[1710]: at /root/.npm/_npx/e23b069b9efbbb8f/node_modules/express/lib/router/index.js:284:15
May 5 22:41:19 ecs-14876993 rc.local[1710]: at Function.process_params (/root/.npm/_npx/e23b069b9efbbb8f/node_modules/express/lib/router/index.js:346:12)
May 5 22:41:19 ecs-14876993 rc.local[1710]: at next (/root/.npm/_npx/e23b069b9efbbb8f/node_modules/express/lib/router/index.js:280:10)
May 5 22:41:19 ecs-14876993 rc.local[1710]: at expressInit (/root/.npm/_npx/e23b069b9efbbb8f/node_modules/express/lib/middleware/init.js:40:5)
May 5 22:41:19 ecs-14876993 rc.local[1710]: Node.js v20.19.1

Here is the response from dify agent:
{
"output": {
"llm_response": "\n\n\n\n\n\n",
"tool_responses": [
{
"tool_call_id": "chatcmpl-tool-d9b0984aba094e10b13f6de3ef7fde6c",
"tool_call_input": {
"sql": "SELECT * FROM obs_order_info ORDER BY create_time DESC LIMIT 1"
},
"tool_call_name": "execute_sql",
"tool_response": "Error executing tool: Server error '500 Internal Server Error' for url 'http://xx.xx.xx.xx:16605/message?sessionId=0f927bd4-e9a8-4b4d-bc0b-f03bee0fdbbb'\nFor more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500"
}
]
}
}

I run dbhub like this: npx @bytebase/dbhub --readonly --transport sse --port 16605 --dsn "mysql://root:mypwd@127.0.0.1:3306/mydb" &

and mcp server setting in dify:
{
"server_name1": {
"transport": "sse",
"url": "http://xx.xx.xx.xx:16605/sse"
}
}

It was working perfectly for the past two days, and now all of a sudden I'm getting this error tonight.
The sql is correct, I can run it on db console. I replaced the real ip with xx.xx.xx.xx.

@tianzhou
Copy link
Contributor

tianzhou commented May 6, 2025

@zhengyi73 just to confirm the network topology:

  1. Where dify is running (self-hosted or its cloud version)
  2. Where dbhub is running?

You seem to have dbhub and mysql running on the same host. One possibility is dbhub somehow OOMed. How much memories that you have allocated for the host machine?

"SELECT * FROM obs_order_info ORDER BY create_time DESC LIMIT 1", does this query works fine before and suddenly returns 500? I am trying to understand if it's the particular problem with this query.

  • What's schema of obs_order_info
  • How many total rows in obs_order_info

@tianzhou tianzhou self-assigned this May 6, 2025
@zhengyi73
Copy link

Dify is self-hosted and running on same server with dbhub. MySQL is exposed to the server using Frp. The server has 256G memory, it is not very likely to run OOM. It has 4xA100, 40G each. I am using Qwen3 32B.

It seems working fine now after rebooting.

The following is the schema of obs_order_info, which has around 1000 rows.
CREATE TABLE obs_order_info (
id varchar(36) COLLATE utf8mb4_general_ci NOT NULL,
merchant_id varchar(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
order_no varchar(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
buyer_id varchar(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
orders_time timestamp NULL DEFAULT NULL,
confirm_receiving_time timestamp NULL DEFAULT NULL,
freight decimal(10,2) unsigned DEFAULT NULL,
merchant_all_price decimal(10,2) unsigned DEFAULT NULL,
orders_all_price decimal(10,2) DEFAULT NULL,
pay_way varchar(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
order_status varchar(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
voucher decimal(10,2) DEFAULT NULL,
settlement_status varchar(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
discount decimal(10,2) DEFAULT NULL,
state bit(1) NOT NULL DEFAULT b'1',
create_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
create_user varchar(36) COLLATE utf8mb4_general_ci NOT NULL,
last_modify_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
last_modify_user varchar(36) COLLATE utf8mb4_general_ci NOT NULL,
payable_dollar decimal(10,2) DEFAULT NULL,
is_evaluate varchar(2) COLLATE utf8mb4_general_ci NOT NULL,
deliver_type varchar(1) COLLATE utf8mb4_general_ci DEFAULT '0',
free_deliver varchar(1) COLLATE utf8mb4_general_ci DEFAULT '0',
remark varchar(255) COLLATE utf8mb4_general_ci DEFAULT '',
discount_fix_time decimal(10,2) DEFAULT NULL,
pay_status varchar(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
delivery_date date DEFAULT NULL,
delivery_time varchar(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
freight_type varchar(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
notes_on_settlement varchar(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
voucher_id varchar(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
total_order_no varchar(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
order_group_no varchar(36) COLLATE utf8mb4_general_ci NOT NULL,
pay_order_no varchar(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
trade_no varchar(64) COLLATE utf8mb4_general_ci DEFAULT NULL,
pay_time timestamp NULL DEFAULT NULL,
deduction_integral varchar(255) COLLATE utf8mb4_general_ci DEFAULT '0',
cons_integral_proportion varchar(36) COLLATE utf8mb4_general_ci DEFAULT '0',
one_order_integral varchar(36) COLLATE utf8mb4_general_ci DEFAULT '0',
refund_price decimal(10,2) DEFAULT '0.00',
merchant_confirm varchar(6) COLLATE utf8mb4_general_ci DEFAULT 'N',
cost_ratio varchar(10) COLLATE utf8mb4_general_ci DEFAULT NULL,
auto_back_order_time double(11,0) DEFAULT '0',
orders_type int DEFAULT '0',
activity_number varchar(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
team_id varchar(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
user_delete bit(1) DEFAULT b'0',
verification_code varchar(10) COLLATE utf8mb4_general_ci DEFAULT NULL,
verification_time timestamp NULL DEFAULT NULL,
source tinyint DEFAULT NULL,
payment_rate decimal(10,6) NOT NULL DEFAULT '0.000000',
estimated_shipping_time date DEFAULT NULL,
create_type int DEFAULT '0',
tenant_id varchar(36) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '0',
union_id varchar(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
cancel_reason varchar(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
cancel_notes varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL,
other_notes varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL,
union_member_id bigint DEFAULT NULL,
order_tags json DEFAULT NULL,
PRIMARY KEY (id),
KEY hlsc_order_info_index_order_no (order_no),
KEY obs_order_info_order_no_index (order_no),
KEY obs_order_info_buyer_id_index (buyer_id DESC),
KEY order_info_index (buyer_id,order_no,order_status,pay_way,create_time,is_evaluate,state,orders_time)
);

@tianzhou
Copy link
Contributor

tianzhou commented May 6, 2025

@zhengyi73 thanks for the info.

Do you mean SELECT * FROM obs_order_info ORDER BY create_time DESC LIMIT 1 is running fine now?

@zhengyi73
Copy link

yes

@tianzhou tianzhou changed the title dbhub crashed when mcp client started to use it run SQL dbhub crashed when mcp client (Dify) started to use it run SQL May 10, 2025
@xiezongming
Copy link

我在测试中也遇到同样的问题,容器报错如下:
Client Message a054d4d5-0068-46f8-be1e-a7f9917a280a
file:///app/node_modules/.pnpm/@modelcontextprotocol+sdk@1.6.1/node_modules/@modelcontextprotocol/sdk/dist/esm/server/sse.js:53
throw new Error(message);
^
Error: SSE connection not established
at SSEServerTransport.handlePostMessage (file:///app/node_modules/.pnpm/@modelcontextprotocol+sdk@1.6.1/node_modules/@modelcontextprotocol/sdk/dist/esm/server/sse.js:53:19)
at file:///app/dist/index.js:3409:25
at Layer.handle [as handle_request] (/app/node_modules/.pnpm/express@4.21.2/node_modules/express/lib/router/layer.js:95:5)
at next (/app/node_modules/.pnpm/express@4.21.2/node_modules/express/lib/router/route.js:149:13)
at Route.dispatch (/app/node_modules/.pnpm/express@4.21.2/node_modules/express/lib/router/route.js:119:3)
at Layer.handle [as handle_request] (/app/node_modules/.pnpm/express@4.21.2/node_modules/express/lib/router/layer.js:95:5)
at /app/node_modules/.pnpm/express@4.21.2/node_modules/express/lib/router/index.js:284:15
at Function.process_params (/app/node_modules/.pnpm/express@4.21.2/node_modules/express/lib/router/index.js:346:12)
at next (/app/node_modules/.pnpm/express@4.21.2/node_modules/express/lib/router/index.js:280:10)
at expressInit (/app/node_modules/.pnpm/express@4.21.2/node_modules/express/lib/middleware/init.js:40:5)
Node.js v22.15.0

页面在执行工具:
{"mcp_sse_call_tool": {"tool_name": "query_people_by_name", "arguments": "{"name": "小肖"}"}}

{"mcp_sse_call_tool": "Error calling MCP Server tool: server_name - MCP Server connection failed: [Errno 111] Connection refused"}

@krajicj
Copy link

krajicj commented May 21, 2025

Same here when cursor starts using MCP via sse


Client connected a5b49c02-213f-477f-b05e-873b0d85f163

Client Disconnected a5b49c02-213f-477f-b05e-873b0d85f163

Client connected 5352e7a5-1cb8-44df-a5af-1cc83ecb09c0

Client Message 5352e7a5-1cb8-44df-a5af-1cc83ecb09c0

Client Message 5352e7a5-1cb8-44df-a5af-1cc83ecb09c0

Client Message 5352e7a5-1cb8-44df-a5af-1cc83ecb09c0

Client Message 5352e7a5-1cb8-44df-a5af-1cc83ecb09c0

Client Message 5352e7a5-1cb8-44df-a5af-1cc83ecb09c0

Client Message 5352e7a5-1cb8-44df-a5af-1cc83ecb09c0

Client Disconnected 5352e7a5-1cb8-44df-a5af-1cc83ecb09c0

Client connected beaf58f3-8139-42a3-9004-aa0a5eac937f

Client Disconnected beaf58f3-8139-42a3-9004-aa0a5eac937f

Client connected 56f05c0f-9b3b-4d9c-b079-103f86d92f01

Client Disconnected 56f05c0f-9b3b-4d9c-b079-103f86d92f01

Client connected fe8d0eed-5542-4ce9-a99f-a5922cb389ae

Client Disconnected fe8d0eed-5542-4ce9-a99f-a5922cb389ae

Client Message fe8d0eed-5542-4ce9-a99f-a5922cb389ae

file:///usr/local/lib/node_modules/@bytebase/dbhub/node_modules/@modelcontextprotocol/sdk/dist/esm/server/sse.js:61

            throw new Error(message);

                  ^


Error: SSE connection not established

    at SSEServerTransport.handlePostMessage (file:///usr/local/lib/node_modules/@bytebase/dbhub/node_modules/@modelcontextprotocol/sdk/dist/esm/server/sse.js:61:19)

    at file:///usr/local/lib/node_modules/@bytebase/dbhub/dist/index.js:3409:25

    at Layer.handle [as handle_request] (/usr/local/lib/node_modules/@bytebase/dbhub/node_modules/express/lib/router/layer.js:95:5)

    at next (/usr/local/lib/node_modules/@bytebase/dbhub/node_modules/express/lib/router/route.js:149:13)

    at Route.dispatch (/usr/local/lib/node_modules/@bytebase/dbhub/node_modules/express/lib/router/route.js:119:3)

    at Layer.handle [as handle_request] (/usr/local/lib/node_modules/@bytebase/dbhub/node_modules/express/lib/router/layer.js:95:5)

    at /usr/local/lib/node_modules/@bytebase/dbhub/node_modules/express/lib/router/index.js:284:15

    at Function.process_params (/usr/local/lib/node_modules/@bytebase/dbhub/node_modules/express/lib/router/index.js:346:12)

    at next (/usr/local/lib/node_modules/@bytebase/dbhub/node_modules/express/lib/router/index.js:280:10)

    at expressInit (/usr/local/lib/node_modules/@bytebase/dbhub/node_modules/express/lib/middleware/init.js:40:5)


Node.js v18.20.8

@tianzhou tianzhou changed the title dbhub crashed when mcp client (Dify) started to use it run SQL dbhub sometimes crashed when mcp client (dify, cursor) started to use it run SQL May 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants