mcp用的是streamableHttpServer,在智能分诊系统utils目录tools_config中加入以下代码,
sql_query(sql_statement: ) -> :
MCP_ENDPOINT = headers = {
: ,
: ,
}
:
request_id = (uuid.uuid4())
initialize_payload = {
: ,
: ,
: {
: ,
: ,
: {
: ,
: },
: {
: ,
: }
},
: request_id
}
init_response = requests.post(
=MCP_ENDPOINT,
=json.dumps(initialize_payload),
=headers,
=)
init_response.status_code != :
init_response.status_codeinit_response.textexecute_payload = {
: ,
: ,
: {
: sql_statement,
: {
: ,
: }
},
: request_id
}
response = requests.post(
=MCP_ENDPOINT,
=json.dumps(execute_payload),
=headers,
=,
=)
response.status_code != :
response.status_coderesponse.textresults = []
line response.iter_lines():
line:
decoded_line = line.decode().strip()
decoded_line.startswith():
data_content = decoded_line[:].strip()
:
data_json = json.loads(data_content)
data_json:
error = data_json.get(, {})
error.get(, )error.get(, )data_json:
results.append(data_json[])
data_json:
results.append(data_json[])
json.JSONDecodeError:
results.append(data_content)
results:
json.dumps(results, =, =)
requests.exceptions.RequestException e:
(e)e:
(e)[retriever_tool, multiply, sql_query]
”
rag日志为:
“
025-06-24 09:55:18,005 - __main__ - INFO - Loading and caching prompt template from prompts/prompt_template_generate.txt
Tool Output [sql_query]: MCP错误 (代码 -32602): Invalid request parameters
2025-06-24 09:55:31,173 - httpx - INFO - HTTP Request: POST https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions "HTTP/1.1 200 OK"
Assistant: 您好!根据您提供的信息,似乎遇到了一个关于查询数据库表的问题。但是,已知内容中提到的是“MCP错误 (代码 -32602): Invalid request parameters”,这表明可能存在请求参数无效的情况,并没有直接提供如何查询数据库有哪些表的方法。
要查询数据库中有哪些表,通常可以使用SQL语句来实现。不同的数据库系统可能有不同的命令。例如,在MySQL中,您可以使用如下命令:
```sql
SHOW TABLES;
```
在PostgreSQL中,则可以这样查询:
```sql
\dt
```
或者使用SQL语句:
```sql
SELECT table_name FROM information_schema.tables WHERE table_schema='public';
```
如果您是在特定的环境下遇到"MCP错误 (代码 -32602)",那么这个错误提示意味着您的请求参数存在问题,请检查您的请求是否符合API或接口文档的要求。如果需要更具体的帮助,请提供更多关于您正在使用的数据库类型以及尝试执行的具体操作等信息。
对于您提到的MCP错误,如果它与查询数据库表无关的话,我建议检查相关的API调用指南或联系技术支持以获得更准确的帮助。希望这些信息对您有所帮助!如果有其他问题,请随时告诉我。
”
mcp日志为:"
INFO: 127.0.0.1:54845 - "POST /mcp/ HTTP/1.1" 200 OK
2025-06-24 09:55:17,995 - root - WARNING - Failed to validate request: 25 validation errors for ClientRequest
PingRequest.method
Input should be 'ping' [type=literal_error, input_value='execute', input_type=str]
For further information visit https://errors.pydantic.dev/2.11/v/literal_error
InitializeRequest.method
Input should be 'initialize' [type=literal_error, input_value='execute', input_type=str]
For further information visit https://errors.pydantic.dev/2.11/v/literal_error
InitializeRequest.params.protocolVersion
Field required [type=missing, input_value={'query': 'SHOW TABLES;',...: 30, 'format': 'json'}}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.11/v/missing
InitializeRequest.params.capabilities
Field required [type=missing, input_value={'query': 'SHOW TABLES;',...: 30, 'format': 'json'}}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.11/v/missing
InitializeRequest.params.clientInfo
Field required [type=missing, input_value={'query': 'SHOW TABLES;',...: 30, 'format': 'json'}}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.11/v/missing
CompleteRequest.method
Input should be 'completion/complete' [type=literal_error, input_value='execute', input_type=str]
For further information visit https://errors.pydantic.dev/2.11/v/literal_error
CompleteRequest.params.ref
Field required [type=missing, input_value={'query': 'SHOW TABLES;',...: 30, 'format': 'json'}}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.11/v/missing
CompleteRequest.params.argument
Field required [type=missing, input_value={'query': 'SHOW TABLES;',...: 30, 'format': 'json'}}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.11/v/missing
SetLevelRequest.method
Input should be 'logging/setLevel' [type=literal_error, input_value='execute', input_type=str]
For further information visit https://errors.pydantic.dev/2.11/v/literal_error
SetLevelRequest.params.level
Field required [type=missing, input_value={'query': 'SHOW TABLES;',...: 30, 'format': 'json'}}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.11/v/missing
GetPromptRequest.method
Input should be 'prompts/get' [type=literal_error, input_value='execute', input_type=str]
For further information visit https://errors.pydantic.dev/2.11/v/literal_error
GetPromptRequest.params.name
Field required [type=missing, input_value={'query': 'SHOW TABLES;',...: 30, 'format': 'json'}}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.11/v/missing
GetPromptRequest.params.arguments.timeout
Input should be a valid string [type=string_type, input_value=30, input_type=int]
For further information visit https://errors.pydantic.dev/2.11/v/string_type
ListPromptsRequest.method
Input should be 'prompts/list' [type=literal_error, input_value='execute', input_type=str]
For further information visit https://errors.pydantic.dev/2.11/v/literal_error
ListResourcesRequest.method
Input should be 'resources/list' [type=literal_error, input_value='execute', input_type=str]
For further information visit https://errors.pydantic.dev/2.11/v/literal_error
ListResourceTemplatesRequest.method
Input should be 'resources/templates/list' [type=literal_error, input_value='execute', input_type=str]
For further information visit https://errors.pydantic.dev/2.11/v/literal_error
ReadResourceRequest.method
Input should be 'resources/read' [type=literal_error, input_value='execute', input_type=str]
For further information visit https://errors.pydantic.dev/2.11/v/literal_error
ReadResourceRequest.params.uri
Field required [type=missing, input_value={'query': 'SHOW TABLES;',...: 30, 'format': 'json'}}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.11/v/missing
SubscribeRequest.method
Input should be 'resources/subscribe' [type=literal_error, input_value='execute', input_type=str]
For further information visit https://errors.pydantic.dev/2.11/v/literal_error
SubscribeRequest.params.uri
Field required [type=missing, input_value={'query': 'SHOW TABLES;',...: 30, 'format': 'json'}}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.11/v/missing
UnsubscribeRequest.method
Input should be 'resources/unsubscribe' [type=literal_error, input_value='execute', input_type=str]
For further information visit https://errors.pydantic.dev/2.11/v/literal_error
UnsubscribeRequest.params.uri
Field required [type=missing, input_value={'query': 'SHOW TABLES;',...: 30, 'format': 'json'}}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.11/v/missing
CallToolRequest.method
Input should be 'tools/call' [type=literal_error, input_value='execute', input_type=str]
For further information visit https://errors.pydantic.dev/2.11/v/literal_error
CallToolRequest.params.name
Field required [type=missing, input_value={'query': 'SHOW TABLES;',...: 30, 'format': 'json'}}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.11/v/missing
ListToolsRequest.method
Input should be 'tools/list' [type=literal_error, input_value='execute', input_type=str]
For further information visit https://errors.pydantic.dev/2.11/v/literal_error
INFO: 127.0.0.1:54846 - "POST /mcp/ HTTP/1.1" 200 OK
"