Skip to content

Feat/add database knowledge base resource#14

Open
gmorales96 wants to merge 4 commits intomainfrom
feat/add-database-knowledge-base-resource
Open

Feat/add database knowledge base resource#14
gmorales96 wants to merge 4 commits intomainfrom
feat/add-database-knowledge-base-resource

Conversation

@gmorales96
Copy link
Copy Markdown
Collaborator

@gmorales96 gmorales96 commented Jun 3, 2025

Summary by CodeRabbit

  • New Features
    • Introduced a new resource providing documentation about the database schema, tables, fields, and relationships.
    • Added a template knowledge base file to guide users in documenting their own database structure and business logic.
  • Documentation
    • Updated the README to reflect the new "Tools" section and added instructions for customizing the database knowledge base.
    • Added a "Resources" section in the README highlighting the new knowledge base.
  • Tests
    • Added tests to verify the new resource returns the correct database knowledge base content.
  • Chores
    • Updated dependencies to include support for asynchronous file operations.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jun 3, 2025

Walkthrough

This update introduces a new documentation template file, database_knowledge_base.md, which provides guidelines and an example schema for integrating Metabase with a Redshift database. The README is updated to reference this new resource and instruct users to customize it for their own database and business logic. A new asynchronous MCP resource, database_knowledge_base, is added to serve the content of this documentation. The pyproject.toml file is updated to include aiofiles and its type stubs as dependencies. Additionally, a corresponding asynchronous test is added to verify the new resource's output. No changes were made to exported code entities apart from the new resource.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (5)
metabase_mcp_server/app.py (1)

217-231: Add a docstring for better documentation.

The resource implementation is correct and follows MCP patterns well. The async file reading with proper path resolution is appropriate.

Consider adding a docstring to the function for better documentation:

 @mcp.resource(
     uri="resource://database_knowledge_base",
     name="database_knowledge_base",
     description="""
         Provides documentation about database schema, tables,
         fields and their relationships.
     """,
 )
 async def database_knowledge_base() -> str:
+    """Read and return the contents of the database knowledge base markdown file."""
     path = (
         Path(__file__).parent.parent / "database_knowledge_base.md"
     ).resolve()
     async with aiofiles.open(path) as file:
         content = await file.read()
     return content
🧰 Tools
🪛 Pylint (3.3.7)

[convention] 225-225: Missing function or method docstring

(C0116)

tests/test_app.py (1)

178-186: Excellent test coverage for the new resource.

The test properly validates the database knowledge base resource by comparing the returned content with the actual file content. The path construction matches the implementation, ensuring consistency.

Consider adding a docstring for consistency with other test functions:

 async def test_database_knowledge_base(client: Client) -> None:
+    """Test that the database knowledge base resource returns the correct markdown content."""
     response = await client.read_resource("resource://database_knowledge_base")
🧰 Tools
🪛 Pylint (3.3.7)

[convention] 178-178: Missing function or method docstring

(C0116)

database_knowledge_base.md (3)

12-14: Suggest clarifying example database details.

Remind users to update both database_id and engine name to match their own Redshift (or alternative) environment. You could parameterize these values or link to your deployment manifest for consistency.


15-22: Recommend marking key relationships in example tables.

Listing tables and columns is helpful; consider annotating primary keys, foreign keys, and index recommendations in real‐world templates to guide schema design and query performance.


24-24: Refine phrasing for countable nouns.

LanguageTool flags “amount of bookings” since bookings are countable. Consider:

- For customer activity profiles: calculate the average total_amount of bookings in the customer's first month.
+ For customer activity profiles: calculate the average booking amount in the customer's first month.
🧰 Tools
🪛 LanguageTool

[uncategorized] ~24-~24: ‘Amount of’ should usually only be used with uncountable or mass nouns. Consider using “number” if this is not the case.
Context: ...y profiles: calculate the average total_amount of bookings in the customer's first mon...

(AMOUNTOF_TO_NUMBEROF)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fa6be94 and 4099a5c.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • README.md (2 hunks)
  • database_knowledge_base.md (1 hunks)
  • metabase_mcp_server/app.py (2 hunks)
  • pyproject.toml (2 hunks)
  • tests/test_app.py (2 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
`**/*.py`: Enforce Relative Imports for Internal Modules

Ensure that any imports referencing internal modules use relative paths. However, if modules reside in the main module dir...

**/*.py: Enforce Relative Imports for Internal Modules

Ensure that any imports referencing internal modules use relative paths. However, if modules reside in the main module directories (for example /src or /library_or_app_name) —and relative imports are not feasible—absolute imports are acceptable. Additionally, if a module is located outside the main module structure (for example, in /tests or /scripts at a similar level), absolute imports are also valid.

Examples and Guidelines:

  1. If a module is in the same folder or a subfolder of the current file, use relative imports. For instance: from .some_module import SomeClass
  2. If the module is located under /src or /library_or_app_name and cannot be imported relatively, absolute imports are allowed (e.g., from library_or_app_name.utilities import helper_method).
  3. If a module is outside the main module directories (for example, in /tests, /scripts, or any similarly placed directory), absolute imports are valid.
  4. External (third-party) libraries should be imported absolutely (e.g., import requests).
  • metabase_mcp_server/app.py
  • tests/test_app.py
`**/*.py`: Rule: Enforce Snake Case in Python Backend
  1. New or Modified Code: Use snake_case for all variables, functions, methods, and class attributes.
  2. Exceptions (Pydantic...

**/*.py:
Rule: Enforce Snake Case in Python Backend

  1. New or Modified Code: Use snake_case for all variables, functions, methods, and class attributes.
  2. Exceptions (Pydantic models for API responses):
    • Primary fields must be snake_case.
    • If older clients expect camelCase, create a computed or alias field that references the snake_case field.
    • Mark any camelCase fields as deprecated or transitional.

Examples

Invalid:

class CardConfiguration(BaseModel):
    title: str
    subTitle: str  # ❌ Modified or new field in camelCase

Valid:

class CardConfiguration(BaseModel):
    title: str
    subtitle: str  # ✅ snake_case for new/modified field

    @computed_field
    def subTitle(self) -> str:  # camelCase allowed only for compatibility
        return self.subtitle

Any direct use of camelCase in new or updated code outside of these exceptions should be flagged.

  • metabase_mcp_server/app.py
  • tests/test_app.py
`**/*.py`: Use try/except for concise error handling when accessing nested dictionary keys:
try:
    can_ignore_error = data['error']['code'] in ignore_error_codes
excep...</summary>

> `**/*.py`: Use try/except for concise error handling when accessing nested dictionary keys:
> 
> ```python
> try:
>     can_ignore_error = data['error']['code'] in ignore_error_codes
> except KeyError:
>     can_ignore_error = False
> ```
> 
>Avoid Verbose Chained Conditionals:
> ```python
> can_ignore_error = (
>     'code' in data['error']
>     and data['error']['code'] in ignore_error_codes
> )
> ```
> 
> Explanation:
> The try/except approach:
> 
> Reduces code complexity and nesting
> Improves readability by focusing on the "happy path" logic
> Follows Python's "easier to ask forgiveness than permission" (EAFP) idiom
> 
> Severity: Important (Not a Nitpick)
> This pattern significantly improves code maintainability and readability, especially as dictionary access patterns become more complex.

- `metabase_mcp_server/app.py`
- `tests/test_app.py`

</details>
<details>
<summary>`**/*.py`: Context
Agave is our internal Python library for processing SQS messages. The @task decorator can automatically convert JSON to Pydantic models.

Rule
Always annotate @t...</summary>

> `**/*.py`: Context
> Agave is our internal Python library for processing SQS messages. The @task decorator can automatically convert JSON to Pydantic models.
> 
> Rule
> Always annotate @task parameters with Pydantic models instead of manually converting dictionaries.
> 
> Correct Pattern
> ```python
> from pydantic import BaseModel
> from agave.tasks.sqs_tasks import task
> 
> class User(BaseModel):
>     name: str
>     age: int
>     
> @task(queue_url=QUEUE_URL, region_name='us-east-1')
> async def task_validator(message: User) -> None:
>     # The message is already a User instance - no conversion needed
>     print(message.name)  # Direct attribute access
> ```
> 
> Incorrect Pattern
> ```python
> from pydantic import BaseModel
> from agave.tasks.sqs_tasks import task
> 
> class User(BaseModel):
>     name: str
>     age: int
>     
> @task(queue_url=QUEUE_URL, region_name='us-east-1')
> async def task_validator(message_data: dict) -> None:  # or unannotated parameter
>     # Unnecessary conversion
>     message = User(**message_data)
>     print(message.name)
> ```
> 
> Explanation
> The Agave @task decorator automatically:
> 
> - Reads JSON messages from SQS queues
> - Converts them to Pydantic model instances when the handler parameter is annotated
> - Performs validation based on the Pydantic model

- `metabase_mcp_server/app.py`
- `tests/test_app.py`

</details>
<details>
<summary>`**/*.py`: ## MANDATORY: Use built-in Pydantic validators

### Description
Avoid creating custom validators that duplicate functionality already provided by Pydantic's built-in val...</summary>

> `**/*.py`: ## MANDATORY: Use built-in Pydantic validators
> 
> ### Description
> Avoid creating custom validators that duplicate functionality already provided by Pydantic's built-in validators, pydantic_extra_types package, or third-party Pydantic validator libraries. This improves code maintainability and reduces unnecessary unit tests.
> 
> ### Bad Practice
> ```python
> from pydantic import BaseModel, field_validator
> 
> class MyValidator(BaseModel):
>     location: str
>     
>     @field_validator('location')
>     def validate_location(cls, value: str) -> str:
>         values = value.split(',')
>         if len(values) != 3:
>             raise ValueError('Must provide exactly 3 values for location')
>         # Custom validation logic that duplicates functionality
>         return value
> ```
> 
> ### Good Practice
> ```python
> from pydantic import BaseModel
> from pydantic_extra_types.coordinate import Coordinate
> 
> class MyValidator(BaseModel):
>     location: Coordinate
> ```
> 
> ### Unit Test Guidelines
> Do not write unit tests specifically for validating the behavior of Pydantic's built-in validators. These are already well-tested by the Pydantic library itself.
> 
> #### Tests to Remove
> ```python
> def test_invalid_location():
>     pytest.raises(ValidationError):
>         MyValidator(location='foo,bar')
> ```
> 
> ### Rule Enforcement
> This is a mandatory rule, not a refactoring suggestion. Changes must be implemented when:
> 1. A custom validator replicates functionality already available in Pydantic's ecosystem
> 2. There is a suitable built-in, pydantic_extra_types, or third-party Pydantic validator available
> 
> Actions required:
> 1. Replace custom validators with appropriate existing validators
> 2. Remove unnecessary unit tests that only validate built-in Pydantic validation behavior
> 3. Block PRs that introduce new custom validators when alternatives exist

- `metabase_mcp_server/app.py`
- `tests/test_app.py`

</details>

</details><details>
<summary>🧬 Code Graph Analysis (1)</summary>

<details>
<summary>tests/test_app.py (1)</summary><blockquote>

<details>
<summary>tests/conftest.py (1)</summary>

* `client` (16-18)

</details>

</blockquote></details>

</details><details>
<summary>🪛 LanguageTool</summary>

<details>
<summary>database_knowledge_base.md</summary>

[uncategorized] ~24-~24: ‘Amount ofshould usually only be used with uncountable or mass nouns. Consider usingnumberif this is not the case.
Context: ...y profiles: calculate the average total_amount of bookings in the customer's first mon...

(AMOUNTOF_TO_NUMBEROF)

</details>

</details>
<details>
<summary>🪛 Pylint (3.3.7)</summary>

<details>
<summary>metabase_mcp_server/app.py</summary>

[error] 11-11: Unable to import 'aiofiles'

(E0401)

---

[convention] 225-225: Missing function or method docstring

(C0116)

</details>
<details>
<summary>tests/test_app.py</summary>

[error] 4-4: Unable to import 'aiofiles'

(E0401)

---

[error] 6-6: Unable to import 'fastmcp'

(E0401)

---

[error] 7-7: Unable to import 'mcp.types'

(E0401)

---

[convention] 178-178: Missing function or method docstring

(C0116)

</details>

</details>

</details>

<details>
<summary>🔇 Additional comments (8)</summary><blockquote>

<details>
<summary>pyproject.toml (1)</summary>

`8-8`: **LGTM! Proper dependency management for async file operations.**

The addition of `aiofiles` and its type stubs appropriately supports the new asynchronous file reading functionality in the database knowledge base resource.




Also applies to: 20-20

</details>
<details>
<summary>README.md (1)</summary>

`5-5`: **Excellent documentation updates.**

The section reorganization and new Resources documentation clearly communicate the available functionality. The customization note is particularly helpful for users to understand they need to modify the knowledge base file for their specific use case.




Also applies to: 14-19

</details>
<details>
<summary>metabase_mcp_server/app.py (1)</summary>

`7-7`: **LGTM! Proper imports for the new functionality.**

The Path and aiofiles imports are correctly added to support the asynchronous file reading in the new resource.




Also applies to: 11-11

</details>
<details>
<summary>tests/test_app.py (1)</summary>

`2-2`: **LGTM! Proper test imports added.**

The new imports support testing the database knowledge base resource functionality correctly.




Also applies to: 4-4, 7-7

</details>
<details>
<summary>database_knowledge_base.md (4)</summary>

`1-4`: **Approve header and admonition clarity.**

The top-level heading and blockquote clearly identify this as a template and strongly emphasize the need for customization before production use.

---

`5-11`: **Approve guidelines section.**

The bullet points provide concise, actionable steps for using Metabase effectivelychecking existing questions, verifying schemas, normalizing dates, and testing queries.

---

`23-26`: **Approve Additional Notes examples.**

The business logic snippets (first-month averages, excluding cancellations) are insightful. Ensure you extend them with edge cases like refunds or partial charges when adapting to your domain.

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 LanguageTool</summary>

[uncategorized] ~24-~24: ‘Amount ofshould usually only be used with uncountable or mass nouns. Consider usingnumberif this is not the case.
Context: ...y profiles: calculate the average total_amount of bookings in the customer's first mon...

(AMOUNTOF_TO_NUMBEROF)

</details>

</details>

---

`27-28`: **Approve call-to-action.**

The final reminder to replace all example names and rules is clear and prominently placed, ensuring users wont overlook customization.

</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

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.

1 participant