- SQLclからローカルのOracle AI Database 26ai Freeに接続する
- Database Tools MCP ServerからOracle Autonomous Database 19cに接続する(作成手順については、こちらの記事)
SQLclのツールsql_runでの非同期実行
SQLcl: リリース26.1.2.0 Production ビルド: 26.1.2.132.1334
{
"name": "sql_run",
"description": "Executes a SQL statement or PL/SQL block against the connected Oracle database. Returns CSV-formatted...",
"inputSchema": {
"type": "object",
"properties": {
"sql": {
"type": "string",
"description": "The SQL query to execute"
},
"model": {
"type": "string",
"description": "The name (and version) of the language model being used by the MCP client to process requests",
"default": "UNKNOWN-LLM"
},
"execution_type": {
"type": "string",
"enum": [
"SYNCHRONOUS",
"ASYNCHRONOUS"
],
"description": "The execution type of the sql query",
"default": "SYNCHRONOUS"
}
},
"required": [
"sql"
]
}
}
Use this tool for standard queries, DML, DDL, and PL/SQL that complete in a few seconds.
Set `execution_type=ASYNCHRONOUS` for queries that scan large tables or may take
longer than a few seconds. If the command keeps running in the background,
the response includes structured content containing `tool_request_id`.
""COUNT(*)"
1849
"
select count(*) from all_objects, all_tables
以下のレスポンスが得られました。tool_request_idが返されています。
{
"tool_request_id": "2"
}
""COUNT(*)"
17097924
"
select count(*) from all_objects, all_objects
select sql_id, sql_text from v$sql where sql_text like '%UNKNOWN-LLM%all_objects, all_objects%'
SQL> select sql_id, sql_text from v$sql where sql_text like '%UNKNOWN-LLM%all_objects, all_objects%';
SQL_ID SQL_TEXT
________________ __________________________________________________________________________________________________
1aa9f3gqhtbby select sql_id, sql_text from v$sql where sql_text like '%UNKNOWN-LLM%all_objects, all_objects%'
ag0h1g4t92axp select /* LLM in use is UNKNOWN-LLM */ count(*) from all_objects, all_objects
SQL>
SQL_IDはag0h1g4t92axpでした。
select 'alter system cancel sql ' || chr(39) || sid || ',' || serial# || chr(39) from v$session where username = 'APEXDEV' and status = 'ACTIVE' and sql_id = 'ag0h1g4t92axp';
SQL> select 'alter system cancel sql ' || chr(39) || sid || ',' || serial# || chr(39) from v$session where username = 'APEXDEV' and status = 'ACTIVE' and sql_id = 'ag0h1g4t92axp';
'ALTERSYSTEMCANCELSQL'||CHR(39)||SID||','||SERIAL#||CHR(39)
______________________________________________________________
alter system cancel sql '196,56849'
SQL> alter system cancel sql '196,56849';
Systemが変更されました。
SQL>
{
"content": [
{
"type": "text",
"text": "\n次のコマンド行の開始中にエラーが発生しました : 1 -\nselect /* LLM in use is UNKNOWN-LLM */ count(*) from all_objects, all_objects\nコマンド行 : 1 列 : 1 でのエラー\nエラー・レポート -\nSQLエラー: ORA-01013: ユーザーによって現行の操作の取消しがリクエストされました。\n\nhttps://docs.oracle.com/error-help/db/ora-01013/01013. 00000 - \"User requested cancel of current operation.\"\n*Cause: The user interrupted an Oracle operation by entering CTRL-C,\n Control-C, or another canceling operation.\n*Action: No action needed.\n\nMore Details :\nhttps://docs.oracle.com/error-help/db/ora-01013/\n"
}
],
"isError": false
}
Possible outcomes:
- RUNNING: The request is still in progress; no final result is available yet. Retry after a short delay.
- FAILED: The request completed with an error; the response contains error details.
- FINISHED: The request completed successfully; the response contains the final result payload produced by the original tool.
Database Tools SQL Serverのsql_runでの非同期実行
When set to `SYNCHRONOUS`:
The tool blocks and waits until the tool call completes, then returns the final result. If execution does not complete within the configured timeout, the tool returns an error (timeout).
When set to `ASYNCHRONOUS`:
The tool attempts to return a result quickly:
1) If execution completes within ~55 seconds, the tool returns the final result in this response.
2) If execution takes longer than ~55 seconds, the tool returns a toolRequestId instead of the final result. Use that toolRequestId with request_status to poll until the final result is available.
Prefer SYNCHRONOUS for short queries where you need immediate results. Prefer ASYNCHRONOUS for long-running scripts (e.g., large queries, bulk DML, DDL, or PL/SQL) and be prepared to poll using request_status.
select count(*) from all_tables, all_tables
Database Tools MCP Serverでは、かなりの時間(55秒)待ってから、toolRequestIdとして、以下が以下が返されました。
select count(*) from all_objects, all_objects
toolRequestIdが返されます。
oci raw-request \
--http-method DELETE \
--target-uri https://dbtools.<リージョン>.oci.oraclecloud.com/20230222/workRequests/<キャンセルするランタイム作業リクエストのOCID>
~ % oci raw-request \
--http-method DELETE \
--target-uri https://dbtools.ca-toronto-1.oci.oraclecloud.com/20230222/workRequests/ocid1.databasetoolsrtworkrequest.oc1.ca-toronto-1.aaaaaaaaelifb474vvkwzxorjrfyrrntl2zlcyuxbv2hxhlnyjv3u2ioog6a
/opt/homebrew/Cellar/oci-cli/3.84.0/libexec/lib/python3.14/site-packages/urllib3/poolmanager.py:329: FutureWarning: The 'strict' parameter is no longer needed on Python 3+. This will raise an error in urllib3 v3.0.
warnings.warn(
{
"data": "",
"headers": {
"Content-Type": "application/octet-stream",
"Date": "Tue, 02 Jun 2026 04:57:56 GMT",
"Strict-Transport-Security": "max-age=63072000; includeSubDomains",
"Transfer-Encoding": "chunked",
"Vary": "Origin",
"X-Content-Type-Options": "nosniff, nosniff",
"opc-request-id": "E47D86BC52A649778BF9A566F66514CC/7BB81289697F3EE0D4621E6A59595AD0/0EC494DAE6979A7E61F1C804405C3234"
},
"status": "202 Accepted"
}
~ %

















































