2026年4月3日金曜日

リモートMCPサーバーのツール実行をリソース・マネージャーで制御する

記事「MCPを話すOracle Databaseを作成する - Autonomous AI Database編」にそって作成した環境で、リモートMCPサーバーのツール実行をリソース・マネージャで制御します。

リソース・マネージャについては、Autonomous AI Databaseでできることとオンプレミス環境でできることは異なります。リポジトリmcp-appのリモートMCPサーバーでは、ツールを実行する際にリソース・コンシューマー・グループを設定できるように実装しています。

Autonomous AI Databaseでのリソース・マネージャを以下の記事にそって設定し、リモートMCPサーバーのツールを呼び出して動作確認します。

Autonomous DatabaseのCS_RESOURCE_MANAGERによるSQLの中断を確認する

データベースSALESADBに管理者ユーザーADMINで接続します。

sql -cloudconfig Wallet_SALESADB.zip admin@salesadb_low

mcp-salesadb % sql -cloudconfig Wallet_SALESADB.zip admin@salesadb_low


SQLcl: 金 4月 03 22:18:03 2026のリリース25.4 Production


Copyright (c) 1982, 2026, Oracle.  All rights reserved.


パスワード (**********?) ****************

Last Successful login time: 金 4月  03 2026 22:18:11 +09:00


接続先:

Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

Version 19.31.0.1.0


SQL> 


現状のコンシューマ・グループの設定値を一覧します。

select * from cs_resource_manager.list_current_rules();

SQL> select * from cs_resource_manager.list_current_rules();


CONSUMER_GROUP       ELAPSED_TIME_LIMIT    IO_MEGABYTES_LIMIT    SHARES    CONCURRENCY_LIMIT    DEGREE_OF_PARALLELISM 

_________________ _____________________ _____________________ _________ ____________________ ________________________ 

HIGH                                                                  4                    3                        2 

MEDIUM                                                                2                    2                        2 

LOW                                                                   1                   30                        1 

TP                                                                    8                   30                        1 

TPURGENT                                                             12                   30                          


SQL> 


ツールrun_sqlはコンシューマ・グループTPURGENTに切り替えて実行することにします。コンシューマ・グループTPURGENTの経過時間の上限を5秒に設定します。

CS_RESOURCE_MANAGER.UPDATE_PLAN_DIRECTIVEを呼び出し、コンシューマ・グループTPURGENTelapesed_time_limit5を設定します。
begin
    cs_resource_manager.update_plan_directive(
        consumer_group => 'TPURGENT',
        elapsed_time_limit => 5
    );
end;
/

SQL> begin

  2      cs_resource_manager.update_plan_directive(

  3          consumer_group => 'TPURGENT',

  4          elapsed_time_limit => 5

  5      );

  6  end;

  7* /


PL/SQLプロシージャが正常に完了しました。


SQL> 


SELECT文を再度実行し変更を確認します。コンシューマ・グループTPURGENTELAPSED_TIME_LIMITになっています。

SQL> select * from cs_resource_manager.list_current_rules();


CONSUMER_GROUP       ELAPSED_TIME_LIMIT    IO_MEGABYTES_LIMIT    SHARES    CONCURRENCY_LIMIT    DEGREE_OF_PARALLELISM 

_________________ _____________________ _____________________ _________ ____________________ ________________________ 

HIGH                                                                  4                    3                        2 

MEDIUM                                                                2                    2                        2 

LOW                                                                   1                   30                        1 

TP                                                                    8                   30                        1 

TPURGENT                              5                              12                   30                          


SQL> 


MCP App HelperのAPEXアプリケーションを実行し、ナビゲーション・メニューのToolsを開きます。

一覧にあるrun_sqlを編集します。


Resource Consumer GroupTPURGENTを設定し、変更の適用をクリックします。


以上でツールrun_sqlの実行時にコンシューマ・グループがTPURGENTに切り替わり、SELECT文の経過時間が5秒に達すると切断されるように設定されました。

MCP Inspectorを起動します。

npx @modelcontextprotocol/inspector

リモートMCPサーバーsampleserverに接続し、ツールrun_sqlを呼び出します。


sqlとして以下を記述し、Run Toolを実行します。

select count(*) from all_objects, all_objects

コンシューマ・グループTPURGENTが割当たっているため、経過時間が5秒を超えたところで以下のエラーが発生します。

"ORA-56735: elapsed time limit exceeded - call aborted"


SELECT文実行時に割り当てられているリソース・コンシューマー・グループを、以下のSELECT文を実行して確認します。

select resource_consumer_group from v$session where audsid = sys_context('USERENV','SESSIONID')

Tool Resultから、ツールrun_sqlの実行時にコンシューマ・グループとしてTPURGENTが割り当たっていることが確認できます。


以上のように、リモートMCPサーバーのツール実行時にリソース・コンシューマ・グループを切り替えられることが確認できました。

今回の記事は以上になります。

Entra IDで認証したリモートMCPサーバーにReal Application Securityを適用する

以下の記事で作成したリモートMCPサーバーを実行する環境に、Real Application Securityによる保護を実装します。

以下の記事は、Autonomous AI Lakehouse 19cのデータベースとしてSALESADB、OpenRestyによるリバース・プロキシを実行するコンピュート・インスタンスを作成します。APEXワークスペースとしてapexdev、スキーマとしてWKSP_APEXDEVが作成済みとします。

MCPを話すOracle Databaseを作成する - Autonomous AI Database編

続けて、上記で作成したサンプルのリモートMCPサーバーsampleserverを、Microsoft Entra IDをIdPとしてOpen ID Connect認証できるようにします。Entra IDのアプリとしてORDS MCPおよびORDS MCP Clientを作成します。

この環境に、Oracle Databaseのサンプル・スキーマhuman_resourcesをインストールし、Entra IDで認証されたユーザーを使ってReal Application Securityによるデータ保護を実装します。

Real Application Securityは以下の記事と同じ構成にします。以下の2つのACLを構成します。
  • ACL: emp_acl: サインインしたユーザーと同じ部門にアクセスを限定する
  • ACL: mgr_acl: サインインしたユーザーがマネージャーである従業員の列SALARYとCOMMISSION_PCTにアクセスを限定する
Entra IDで認証したMCPサーバーにReal Application Securityを適用する

以下よりReal Application Securityの構成作業を紹介します。

サンプルを実行するための手順のみです。リモートMCPサーバーを実装しているコードの説明は含みません。実際のところ、クローンしたリポジトリmcp-appをClaude Codeに読ませて解説してもらう方が分かりやすいので、処理に興味があるかたはClaude Code(またはそれに類するAI)などを活用することをお勧めします。


サンプル・データセットのhuman resourcesのインストール



サンプル・データセットのhuman_resourcesをインストールします。2026年4月3日時点での最新であるv23.3.zipをダウンロードします。

curl -OL https://github.com/oracle-samples/db-sample-schemas/archive/refs/tags/v23.3.zip
unzip -q v23.3.zip
ls db-sample-schemas-23.3

mcp-salesadb % curl -OL https://github.com/oracle-samples/db-sample-schemas/archive/refs/tags/v23.3.zip

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

100 11.6M    0 11.6M    0     0  4364k      0 --:--:--  0:00:02 --:--:-- 5446k

mcp-salesadb % unzip -q v23.3.zip

mcp-salesadb % ls db-sample-schemas-23.3

customer_orders LICENSE.txt product_media README.txt SECURITY.md

human_resources order_entry README.md sales_history

mcp-salesadb % 


human resourcesのディレクトリへ移動します。

cd db-sample-schemas-23.3/human_resources

mcp-salesadb % cd db-sample-schemas-23.3/human_resources

human_resources % 


管理者ユーザーADMINでデータベースSALESADBに接続し、インストール・スクリプトhr_install.sqlを実行します。データベースSALESADBのクラウド・ウォレットWallet_SALESADB.zipを使用します。

sql -cloudconfig ../../Wallet_SALESADB.zip admin@salesadb_low
@hr_install

human_resources % sql -cloudconfig ../../Wallet_SALESADB.zip admin@salesadb_low



SQLcl: 金 4月 03 13:06:37 2026のリリース25.4 Production


Copyright (c) 1982, 2026, Oracle.  All rights reserved.


パスワード (**********?) ****************

Last Successful login time: 金 4月  03 2026 13:06:44 +09:00


接続先:

Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

Version 19.31.0.1.0


SQL> @hr_install


Thank you for installing the Oracle Human Resources Sample Schema.

This installation script will automatically exit your database session

at the end of the installation or if any error is encountered.

The entire installation will be logged into the 'hr_install.log' log file.


Enter a password for the user HR: ****************


DATA              

Enter a tablespace for HR [DATA]: 

Do you want to overwrite the schema, if it already exists? [YES|no]: 

******  Creating REGIONS table ....


Table REGIONSは作成されました。



INDEX REG_ID_PKは作成されました。



Table REGIONSが変更されました。


[中略]


Procedure ADD_JOB_HISTORYがコンパイルされました



Trigger UPDATE_JOB_HISTORYがコンパイルされました



コミットが完了しました。



Installation verification    

____________________________ 

Verification:                


Table             provided    actual 

______________ ___________ _________ 

regions                  5         5 

countries               25        25 

departments             27        27 

locations               23        23 

employees              107       107 

jobs                    19        19 

job_history             10        10 


Thank you!                                                  

___________________________________________________________ 

The installation of the sample schema is now finished.      

Please check the installation verification output above.    

You will now be disconnected from the database.             

Thank you for using Oracle Database!                        

Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

Version 19.31.0.1.0から切断されました

human_resources % 


サンプル・データセットのインストールが完了したら、最初の作業ディレクトリに戻ります。

cd ../..

human_resources % cd ../..

mcp-salesadb % 



管理ユーザーRASADMINの作成と各種権限の付与



Real Application Securityを構成するためのデータベース・ユーザーとしてRASADMINを作成します。

データベースSALESADBに管理者ユーザーADMINで接続し、作業を進めます。

sql -cloudconfig Wallet_SALESADB.zip admin@salesadb_low

mcp-salesadb % sql -cloudconfig Wallet_SALESADB.zip admin@salesadb_low



SQLcl: 金 4月 03 13:13:34 2026のリリース25.4 Production


Copyright (c) 1982, 2026, Oracle.  All rights reserved.


パスワード (**********?) ****************

Last Successful login time: 金 4月  03 2026 13:13:45 +09:00


接続先:

Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

Version 19.31.0.1.0


SQL> 


データベース・ユーザーRASADMINを作成し、最低限必要な権限を与えます。

create user rasadmin identified by <パスワード>;
grant create session to rasadmin;

SQL> create user rasadmin identified by ************;


User RASADMINは作成されました。


SQL> grant create session to rasadmin;


Grantが正常に実行されました。


SQL> 


RASADMINに、Real Application Securityを構成するために必要な権限を与えます。
begin
    sys.xs_admin_cloud_util.grant_system_privilege('PROVISION','RASADMIN');
    sys.xs_admin_cloud_util.grant_system_privilege('ADMIN_ANY_SEC_POLICY','RASADMIN');
end;
/

SQL> begin

  2      sys.xs_admin_cloud_util.grant_system_privilege('PROVISION','RASADMIN');

  3      sys.xs_admin_cloud_util.grant_system_privilege('ADMIN_ANY_SEC_POLICY','RASADMIN');

  4  end;

  5* /


PL/SQLプロシージャが正常に完了しました。


SQL> 


ロールHR_ROLEを作成し、ユーザーRASADMINに割り当てます。ロールHR_ROLEは後ほどユーザーRASADMINで作成するアプリケーション・ロールEMPLOYEEに割り当てます。
create role hr_role;
grant select on hr.departments to hr_role;
grant select on hr.employees to hr_role;
grant select on hr.jobs to hr_role;
grant select on hr.job_history to hr_role;
grant select on hr.locations to hr_role;
grant select on hr.regions to hr_role;
grant select on hr.countries to hr_role;
grant select on hr.emp_details_view to hr_role;
grant hr_role to rasadmin with admin option;

SQL> create role hr_role;


Role HR_ROLEは作成されました。


SQL> grant select on hr.departments to hr_role;


Grantが正常に実行されました。


SQL> grant select on hr.employees to hr_role;


Grantが正常に実行されました。


SQL> grant select on hr.jobs to hr_role;


Grantが正常に実行されました。


SQL> grant select on hr.job_history to hr_role;


Grantが正常に実行されました。


SQL> grant select on hr.locations to hr_role;


Grantが正常に実行されました。


SQL> grant select on hr.regions to hr_role;


Grantが正常に実行されました。


SQL> grant select on hr.countries to hr_role;


Grantが正常に実行されました。


SQL> grant select on hr.emp_details_view to hr_role;


Grantが正常に実行されました。


SQL> grant hr_role to rasadmin with admin option;


Grantが正常に実行されました。


SQL> 


リモートMCPサーバーはAPEXワークスペースapexdevに紐づくスキーマWKSP_APEXDEVに作成しています。

このデータベース・ユーザーWKSP_APEXDEVに、RASセッションを操作する権限ADMINISTER_SESSIONを与えます。
begin
    sys.xs_admin_cloud_util.grant_system_privilege('ADMINISTER_SESSION','WKSP_APEXDEV');
end;
/

SQL> begin

  2      sys.xs_admin_cloud_util.grant_system_privilege('ADMINISTER_SESSION','WKSP_APEXDEV');

  3  end;

  4* /


PL/SQLプロシージャが正常に完了しました。


SQL> 


以上で、管理ユーザーRASADMINの作成と各種権限の付与が完了しました。


スキーマWKSP_APEXDEVの構成



RASのポリシー作成を補助するための設定を行います。

元記事「Entra IDで認証したMCPサーバーにReal Application Securityを適用する」では、Entra IDで認証したユーザーのユーザーID(Bearerトークンのサブジェクト)と表HR.EMPLOYEESに保存されている従業員を紐づける表AUTH_USERSと、ネームスペース・テンプレートHREMPを準備するパッケージEMP_DEPT_CTX_PKGを作成しています。

この表AUTH_USERSとネームスペース・テンプレートHREMPを準備するパッケージ(OJ_MCP_RAS_CONFIG)は、リモートMCPサーバー・フレームワークmcp-appに含まれるサンプルMCPサーバーsampleserverをインストールする際に作成されています。

そのため、それらのオブジェクトの作成は省略します。

表AUTH_USERSにEntra IDで認証されたユーザーがEMPLOYEE_ID=105, DEPARTMENT_ID=60のDavid Williamsとして認識されるように、1行挿入します。

Entra IDで認証されたユーザーIDは、MCP InspectorよりToolsget_authenticated_identityを実行して取得します。


データベースSALESADBに管理者ユーザーADMINで接続して作業を行います。

sql -cloudconfig Wallet_SALESADB.zip admin@salesadb_low

mcp-salesadb % sql -cloudconfig Wallet_SALESADB.zip admin@salesadb_low



SQLcl: 金 4月 03 13:41:35 2026のリリース25.4 Production


Copyright (c) 1982, 2026, Oracle.  All rights reserved.


パスワード (**********?) ****************

Last Successful login time: 金 4月  03 2026 13:41:42 +09:00


接続先:

Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

Version 19.31.0.1.0


SQL> 


insert into wksp_apexdev.auth_users(employee_id, department_id, email, authenticated_identity) values(105,60,'DWILLIAMS','Entra IDのユーザーのID - upnとして渡される値');
commit;

SQL> insert into wksp_apexdev.auth_users(employee_id, department_id, email, authenticated_identity) values(105,60,'DWILLIAMS','*****************************');


1行挿入しました。


SQL> commit;


コミットが完了しました。


SQL> 


これらのRAS関連の作業に使用するオブジェクトへのアクセス権限を、ロールMCP_ROLEにまとめます。ユーザー・データへのアクセス権限(HR_ROLE)とは異なるロールとします。

ロールmcp_roleにはMCPサーバーのツールとして呼び出されるプロシージャについても、実行権限を割り当てます。
create role mcp_role;
grant select on wksp_apexdev.auth_users to mcp_role;
grant execute on wksp_apexdev.oj_mcp_ras_config to mcp_role;
grant select on wksp_apexdev.uc_ai_tools to mcp_role;
grant execute on wksp_apexdev.run_sql to mcp_role;
grant execute on wksp_apexdev.get_current_user to mcp_role;
grant execute on wksp_apexdev.get_schema to mcp_role;
grant mcp_role to rasadmin with admin option;

SQL> create role mcp_role;


Role MCP_ROLEは作成されました。


SQL> grant select on wksp_apexdev.auth_users to mcp_role;


Grantが正常に実行されました。


SQL> grant execute on wksp_apexdev.oj_mcp_ras_config to mcp_role;


Grantが正常に実行されました。


SQL> grant select on wksp_apexdev.uc_ai_tools to mcp_role;


Grantが正常に実行されました。


SQL> grant execute on wksp_apexdev.run_sql to mcp_role;


Grantが正常に実行されました。


SQL> grant execute on wksp_apexdev.get_current_user to mcp_role;


Grantが正常に実行されました。


SQL> grant execute on wksp_apexdev.get_schema to mcp_role;


Grantが正常に実行されました。


SQL> grant mcp_role to rasadmin with admin option;


Grantが正常に実行されました。


SQL> 


ユーザーADMINでの作業は以上で完了です。

続いて、ユーザーRASADMINにて、Real Application Securityによる保護を構成します。


Real Application Securityの構成




一連の作業を行なうスクリプトをクローンしたリポジトリmcp-appに、mcp-app/ras-setup/create-ras-prot.sqlとして作成しています。

ユーザーRASADMINでデータベースSALESADBに接続し、create-ras-prot.sqlを実行します。

sql -cloudconfig Wallet_SALESADB.zip rasadmin@salesadb_low

mcp-salesadb % sql -cloudconfig Wallet_SALESADB.zip rasadmin@salesadb_low



SQLcl: 金 4月 03 14:58:10 2026のリリース25.4 Production


Copyright (c) 1982, 2026, Oracle.  All rights reserved.


パスワード (**********?) ************

接続先:

Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

Version 19.31.0.1.0


SQL> 


create-ras-prot.sqlを実行します。

@mcp-app/ras-setup/create-ras-prot.sql

SQL> @mcp-app/ras-setup/create-ras-prot.sql 

SQL> set serveroutput on

SQL> set echo on

SQL> 

SQL> -- dynamic role EMPLOYEE to access schema HR.

SQL> begin

  2      sys.xs_principal.create_dynamic_role(

  3          name => 'EMPLOYEE',

  4          scope => XS_PRINCIPAL.SESSION_SCOPE

  5      );

  6  end;

  7  /


PL/SQLプロシージャが正常に完了しました。


SQL> grant hr_role to employee;


Grantが正常に実行されました。


SQL> 

SQL> -- dynamic role MCPRUNTIME to access MCP server framework.

SQL> begin

  2      sys.xs_principal.create_dynamic_role(

  3          name => 'MCPRUNTIME',

  4          scope => XS_PRINCIPAL.SESSION_SCOPE

  5      );

  6  end;

  7  /


PL/SQLプロシージャが正常に完了しました。


SQL> grant mcp_role to mcpruntime;


Grantが正常に実行されました。


SQL> 

SQL> -- namespace template HREMP which refered by ACL

SQL> declare

  2      attrlist XS$NS_ATTRIBUTE_LIST;

  3  begin

  4      attrlist := XS$NS_ATTRIBUTE_LIST();

  5      attrlist.extend(2);

  6      attrlist(1) := XS$NS_ATTRIBUTE('employee_id','0');

  7      attrlist(2) := XS$NS_ATTRIBUTE('department_id','0');

  8      sys.xs_namespace.create_template(

  9          name => 'HREMP',

 10          attr_list => attrlist,

 11          acl => 'SYS.NS_UNRESTRICTED_ACL'

 12      );

 13  end;

 14  /


PL/SQLプロシージャが正常に完了しました。


SQL> 

SQL> -- security class emp_priv

SQL> begin

  2      sys.xs_security_class.create_security_class(

  3          name => 'emp_priv',

  4          parent_list => xs$name_list('sys.dml'),

  5          priv_list => xs$privilege_list(xs$privilege('view_sal'))

  6      );

  7  end;

  8  /


PL/SQLプロシージャが正常に完了しました。


SQL> 

SQL> -- ACL: emp_acl - Restrict access to the same department as the signed-in user.

SQL> declare

  2      aces xs$ace_list := xs$ace_list();

  3  begin

  4      aces.extend(1);

  5      aces(1) := xs$ace_type(

  6          privilege_list => xs$name_list('select','insert','update','delete'),

  7          principal_name => 'employee' -- application role

  8      );

  9      sys.xs_acl.create_acl(

 10          name => 'emp_acl',

 11          ace_list => aces,

 12          sec_class => 'emp_priv' -- security class

 13      );

 14  end;

 15  /


PL/SQLプロシージャが正常に完了しました。


SQL> 

SQL> -- ACL: mgr_acl - Restrict access to the SALARY and COMMISSION_PCT columns

SQL> --                for employees whose manager is the signed-in user.

SQL> declare

  2      aces xs$ace_list := xs$ace_list();

  3  begin

  4      aces.extend(1);

  5      aces(1) := xs$ace_type(

  6          privilege_list => xs$name_list('select','insert','update','delete','view_sal'),

  7          principal_name => 'employee' -- application role

  8      );

  9      sys.xs_acl.create_acl(

 10          name => 'mgr_acl',

 11          ace_list => aces,

 12          sec_class => 'emp_priv'

 13      );

 14  end;

 15  /


PL/SQLプロシージャが正常に完了しました。


SQL> 

SQL> -- data security policy employees_ds that includes ACL emp_acl and mgr_acl

SQL> declare

  2      realms xs$realm_constraint_list := xs$realm_constraint_list();

  3      cols xs$column_constraint_list := xs$column_constraint_list();

  4  begin

  5      realms.extend(2);

  6      realms(1) := xs$realm_constraint_type(

  7          realm => q'~department_id = xs_sys_context('HREMP','department_id')~',

  8          acl_list => xs$name_list('emp_acl')

  9      );

 10      realms(2) := xs$realm_constraint_type(

 11          realm => q'~manager_id = xs_sys_context('HREMP','employee_id')~',

 12          acl_list => xs$name_list('mgr_acl')

 13      );

 14      cols.extend(1);

 15      cols(1) := xs$column_constraint_type(

 16          column_list => xs$list('SALARY','COMMISSION_PCT'),

 17          privilege => 'view_sal'

 18      );

 19      sys.xs_data_security.create_policy(

 20          name => 'employee_ds',

 21          realm_constraint_list => realms,

 22          column_constraint_list => cols

 23      );

 24  end;

 25  /


PL/SQLプロシージャが正常に完了しました。


SQL> 

SQL> -- apply data security policy employees_ds to hr.employees

SQL> begin

  2      sys.xs_data_security.apply_object_policy(

  3          policy => 'employee_ds',

  4          schema => 'hr',

  5          object => 'employees'

  6      );

  7  end;

  8  /


PL/SQLプロシージャが正常に完了しました。


SQL> 

SQL> -- verify configuration

SQL> begin

  2      if (sys.xs_diag.validate_workspace()) then

  3          dbms_output.put_line('All Configurations are correct.');

  4      else

  5          dbms_output.put_line('Some configurations are incorrect.');

  6      end if;

  7  end;

  8  /

All Configurations are correct.



PL/SQLプロシージャが正常に完了しました。


SQL> 


最後に実行されるsys.xs_diag.validate_workspace()の結果として、All Configurations are correct.が表示されていれば、Real Application Securityの構成は完了です。

create-ras-prot.sqlで作成したRASの設定を削除するスクリプトdelete-ras-prot.sqlを、リポジトリに含めています。


MCPサーバーsampleserverの更新



リモートMCPサーバーへの接続時にReal Application Securityのセッションを作成し、ツール呼び出し時に作成したセッションをアタッチするように、ORDSのハンドラを変更します。

スキーマWKSP_APEXDEVに接続し、RESTモジュールsampleserverのPOSTおよびDELETEハンドラを更新します。

sql -cloudconfig Wallet_SALESADB.zip wksp_apexdev@salesadb_low

mcp-salesadb % sql -cloudconfig Wallet_SALESADB.zip wksp_apexdev@salesadb_low


SQLcl: 金 4月 03 16:21:04 2026のリリース25.4 Production


Copyright (c) 1982, 2026, Oracle.  All rights reserved.


パスワード (**********?) ****************

接続先:

Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

Version 19.31.0.1.0


SQL> 


以下のコードを実行し、ORDS RESTモジュールのハンドラがプロシージャoj_mcp_ras_post_handlerまたはoj_mcp_ras_delete_handlerを呼び出すように変更します。RASを有効にしない場合はoj_mcp_post_handlerまたはoj_mcp_delete_handlerを呼び出します。
begin
    ords.define_handler(
        p_module_name    => 'sampleserver',
        p_pattern        => 'mcp',
        p_method         => 'POST',
        p_source_type    => 'plsql/block',
        p_source         => 'begin oj_mcp_ras_post_handler(:body,:current_user,:status_code); end;'
    );
    ords.define_handler(
        p_module_name    => 'sampleserver',
        p_pattern        => 'mcp',
        p_method         => 'DELETE',
        p_source_type    => 'plsql/block',
        p_source         => 'begin oj_mcp_ras_delete_handler(:current_user,:status_code); end;'
    );
end;
/

SQL> begin

  2      ords.define_handler(

  3          p_module_name    => 'sampleserver',

  4          p_pattern        => 'mcp',

  5          p_method         => 'POST',

  6          p_source_type    => 'plsql/block',

  7          p_source         => 'begin oj_mcp_ras_post_handler(:body,:current_user,:status_code); end;'

  8      );

  9      ords.define_handler(

 10          p_module_name    => 'sampleserver',

 11          p_pattern        => 'mcp',

 12          p_method         => 'DELETE',

 13          p_source_type    => 'plsql/block',

 14          p_source         => 'begin oj_mcp_ras_delete_handler(:current_user,:status_code); end;'

 15      );

 16  end;

 17* /


PL/SQLプロシージャが正常に完了しました。


SQL> 


給与と手当の情報が検索できるように、ユーザーの割り当てをAJAMESに変更します。

update auth_users set employee_id = 103, email = 'AJAMES';
commit;

SQL> update auth_users set employee_id = 103, email = 'AJAMES';


1行更新しました。


SQL> commit;


コミットが完了しました。


SQL> 


以上でリモートMCPサーバーのツール呼び出し時のセッションに、Real Application Securityの動的ロールEMPLOYEEとMCPRUNTIMEが割り当たるようになります。


動作確認



Claude Coworkを使って動作確認をしてみます。

Coworkプロジェクトを開いて、新規プロジェクトを作成します。


新規プロジェクトの手順に「My Oracle Appに繋いでスキーマHRに含まれる情報を検索する」と記述します。この後に、リモートMCPサーバーsampleserverをカスタムコネクタMy Oracle Appとして作成します。


プロジェクトが作成されます。作業を始める前にカスタムコネクタを作成します。

コネクタを管理を開きます。


カスタムコネクタを追加を実行します。


リモートMCPサーバーsampleserverを、Claude Desktopにカスタムコネクタとして追加します。コネクタの名前はMy Oracle Appとします。

Microsoft Entra IDによる認証の場合、アプリケーションIDとシークレットの指定が必要です。

追加します。


コネクタが追加されます。追加直後は未接続です。

一覧からMy Oracle Appを選択し、連携/連携させるをクリックします。


ブラウザが開き、Entra IDへのサインインが要求されます。


サインインが完了すると、コネクタで呼び出すことができるツールが一覧されます。インタラクティブ・ツールは、UIリソースが割り当てられているツールです。


プロジェクトのコンテキストとして、コネクタMy Oracle Appが追加されました。

あとはCoworkでの作業を行います。


補足として、MCPサーバーのツールにはVisibilityという属性があり、そのツールをLLMから直接呼び出せるか、または、MCP Apps経由での呼び出しに限定するか決めることができます。サンプルのMCPサーバーsampleserverでは、ツールにUIリソースを紐づけて、かつ、LLMからの直接呼び出しも可としているため、ツール呼び出し時にUIも表示されています。

ツールの性格を考慮してUIリソースに紐付けてLLMからは見えないようにするなど、Visibilityなどを適切に設定する必要があります。


今回の記事は以上になります。


 追記

リポジトリmcp-app全体をClaude Codeに読ませて、以下の質問をしました。

「RASの構成を、HRを対象とするのではなく、別の保護を適用したいのだが、コードのどの部分を変更すれば良いのか調べて。」


コードを色々解析して、以下の結論が返されています。正解で、そのようにコーディングしています。

まとめ: 設計のポイント

RAS の汎用部分(oj_mcp_ras_ctxoj_mcp_app_serveroj_mcp_app_methods)はプラグイン方式で設計されており、oj_mcp_ras_config パッケージが以下の2つの関数を実装していれば動作します:

function get_dynamic_roles return sys.xs$name_list;
function prepare_namespace(p_username in varchar2) return sys.dbms_xs_nsattrlist;

つまり、新しい保護対象用に 別の config パッケージ(例: oj_mcp_ras_config_sales)を作成し、oj_mcp_ras_post_handler.pls の C_RAS_CONFIG_PKG 定数をそのパッケージ名に変えるだけで、コアロジックの変更なしに切り替え可能です。