Skip to content

Conversation

@dario-vega
Copy link
Member

Description

Original Issue:

The functions utilize the OCI SDK's list_compartments method without pagination, which by default returns only the first 100 results. In tenancies with thousands of compartments, the current implementation may return an error:

error: Compartment compartment_name not found

This occurs because the user’s compartment is not included in the initial 100 results retrieved (due to lack of pagination). Note: the list is sorted alphabetically by name.

Proposed Fix 1:

Implement pagination in the list_compartments call by incorporating the page and limit parameters and handling the next_page token to fetch all pages of results. This ensures all compartments are retrieved while preserving the current behavior of list_all_compartments. The existing get_compartment_by_name function remains in use, but now validates results only after retrieving all compartments. This maintains backward compatibility while ensuring accuracy.

Proposed Fix 2:

Introduce an alternative implementation for get_compartment_by_name (see get_compartment_by_name_v2). The existing function remains in use, but this new version provides a new approach for retrieving compartments by name.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

To reproduce this issue, ensure the tenancy contains more than 100 compartments. Alternatively, simulate the scenario using the limit parameter and setting only_one_page to restrict results to a single page.

I have tested using MCP Inspector

  • list_all_compartments
  • get_compartment_by_name_tool
  • list_autonomous_databases

For V2:
I updated the get_compartment_by_name_tool function in the test environment to use the new get_compartment_by_name_v2 .

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

The functions use the OCI SDK's list_compartments method without pagination, which by default returns only the first 100 results. get_compartment_by_name "fails" if the compartment name is not within the initial 100 results (e.g a tenancy with +300 compartments) which raise Compartment '{compartment_name}' not found
@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Sep 11, 2025
delete get_compartment_by_name_v2
@dario-vega
Copy link
Member Author

I deleted the code for get_compartment_by_name_v2

Copy link
Member

@nomisvai nomisvai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the pr!

@nomisvai nomisvai merged commit 064eb2f into oracle:main Sep 12, 2025
1 check passed
gebhardtr added a commit to shrug-labs/mcp that referenced this pull request Oct 9, 2025
Signed-off-by: Richard Gebhardt <richard.gebhardt@oracle.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants