Skip to content

DBA-725 Fixed the issue with running explain plan on cursor #29

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

Merged
merged 5 commits into from
Apr 4, 2025

Conversation

mdashti
Copy link
Contributor

@mdashti mdashti commented Apr 4, 2025

No description provided.

@mdashti mdashti requested review from jssmith and greglearns April 4, 2025 22:34
@mdashti mdashti self-assigned this Apr 4, 2025
@mdashti mdashti requested a review from rahulcap April 4, 2025 22:35
Copy link
Contributor

@jssmith jssmith left a comment

Choose a reason for hiding this comment

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

See comments.

default=None,
]
If there is no hypothetical index, you can pass an empty list.""",
default=[],
Copy link
Contributor

Choose a reason for hiding this comment

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

If we have a default value why instruct the LLM to pass in an empty list?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to make sure that it doesn't HAVE TO send a list of hypothetical indexes.

hypothetical_indexes: list[dict[str, Any]] | None = Field(
description="""Optional list of hypothetical indexes to simulate. Each index must be a dictionary with these keys:
hypothetical_indexes: list[dict[str, Any]] = Field(
description="""A list of hypothetical indexes to simulate. Each index must be a dictionary with these keys:
Copy link
Contributor

Choose a reason for hiding this comment

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

See comment below, I think I could keep it optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was the main fix to not have it as optional.

@@ -363,7 +364,7 @@ async def explain_query(
result: ExplainPlanArtifact | ErrorResult | None = None

# If hypothetical indexes are specified, check for HypoPG extension
if hypothetical_indexes:
if len(hypothetical_indexes) > 0:
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not certain whether it is still possible to pass in None. The type annotation does not apply at runtime, and I'm not certain how the Field handles None inputs.

Suggest `if hypothetical_indexes and len(hypothetical_indexes) > 0:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was the main problem: with having None in the parameter, the MCP server had a hard time figuring out the required type and as failing in Cursor. Added this check.

@jssmith
Copy link
Contributor

jssmith commented Apr 4, 2025

In general, we should probably be thinking in terms of Postel's Law for tools. It's not always the right approach but for calls from LLMs it probably is: "be conservative in what you send, and liberal in what you accept"

@mdashti mdashti requested a review from jssmith April 4, 2025 23:05
Copy link
Contributor

@rahulcap rahulcap left a comment

Choose a reason for hiding this comment

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

this code works for me on cursor. I did get an error once of Error: Error converting explain plan: 'Node Type' but all the other times it worked

@mdashti mdashti merged commit d5d6ae4 into main Apr 4, 2025
1 check passed
@mdashti mdashti deleted the mdashti/DBA-725-explain-plan-cursor branch April 4, 2025 23:23
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

Successfully merging this pull request may close these issues.

3 participants