-
Notifications
You must be signed in to change notification settings - Fork 536
feat: add read_github_data MCP tool for Supabase Postgres
#3771
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,22 @@ | ||
| use crate::env::{GitHubAppEnv, OpenRouterEnv}; | ||
| use crate::env::{GitHubAppEnv, OpenRouterEnv, SupabaseDbEnv}; | ||
|
|
||
| #[derive(Clone)] | ||
| pub struct SupportConfig { | ||
| pub github: GitHubAppEnv, | ||
| pub openrouter: OpenRouterEnv, | ||
| pub supabase_db: SupabaseDbEnv, | ||
| } | ||
|
|
||
| impl SupportConfig { | ||
| pub fn new(github: &GitHubAppEnv, openrouter: &OpenRouterEnv) -> Self { | ||
| pub fn new( | ||
| github: &GitHubAppEnv, | ||
| openrouter: &OpenRouterEnv, | ||
| supabase_db: &SupabaseDbEnv, | ||
| ) -> Self { | ||
| Self { | ||
| github: github.clone(), | ||
| openrouter: openrouter.clone(), | ||
| supabase_db: supabase_db.clone(), | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| mod bug_report; | ||
| mod feature_request; | ||
| mod read_github_data; | ||
|
|
||
| pub(crate) use bug_report::{SubmitBugReportParams, submit_bug_report}; | ||
| pub(crate) use feature_request::{SubmitFeatureRequestParams, submit_feature_request}; | ||
| pub(crate) use read_github_data::{ReadGitHubDataParams, read_github_data}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| use rmcp::{ | ||
| ErrorData as McpError, | ||
| model::*, | ||
| schemars::{self, JsonSchema}, | ||
| }; | ||
| use serde::Deserialize; | ||
|
|
||
| use crate::state::AppState; | ||
|
|
||
| #[derive(Debug, Clone, Deserialize, JsonSchema)] | ||
| #[serde(rename_all = "snake_case")] | ||
| pub(crate) enum GitHubTable { | ||
| #[schemars(description = "GitHub issues")] | ||
| Issues, | ||
| #[schemars(description = "GitHub pull requests")] | ||
| PullRequests, | ||
| #[schemars(description = "GitHub comments")] | ||
| Comments, | ||
| #[schemars(description = "GitHub tags")] | ||
| Tags, | ||
| } | ||
|
|
||
| impl GitHubTable { | ||
| fn as_str(&self) -> &'static str { | ||
| match self { | ||
| Self::Issues => "issues", | ||
| Self::PullRequests => "pull_requests", | ||
| Self::Comments => "comments", | ||
| Self::Tags => "tags", | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Deserialize, JsonSchema)] | ||
| pub(crate) struct ReadGitHubDataParams { | ||
| #[schemars(description = "The table to read from")] | ||
| pub table: GitHubTable, | ||
| #[schemars(description = "Maximum number of rows to return (default: 50, max: 500)")] | ||
| pub limit: Option<i64>, | ||
| #[schemars(description = "Number of rows to skip (default: 0)")] | ||
| pub offset: Option<i64>, | ||
| #[schemars( | ||
| description = "Filter by state (e.g. 'open', 'closed'). Applicable to issues and pull_requests." | ||
| )] | ||
| pub state: Option<String>, | ||
| } | ||
|
|
||
| pub(crate) async fn read_github_data( | ||
| state: &AppState, | ||
| params: ReadGitHubDataParams, | ||
| ) -> Result<CallToolResult, McpError> { | ||
| let table_name = params.table.as_str(); | ||
| let limit = params.limit.unwrap_or(50).max(0).min(500); | ||
| let offset = params.offset.unwrap_or(0).max(0); | ||
|
|
||
| if params.state.is_some() { | ||
| match params.table { | ||
| GitHubTable::Comments | GitHubTable::Tags => { | ||
| return Err(McpError::invalid_params( | ||
| "The 'state' filter is only applicable to 'issues' and 'pull_requests' tables", | ||
| None, | ||
| )); | ||
| } | ||
| _ => {} | ||
| } | ||
| } | ||
|
|
||
| let query = if let Some(ref state_filter) = params.state { | ||
| let q = format!( | ||
| "SELECT to_jsonb(t.*) AS row_data FROM hyprnote_github.{} t WHERE t.state = $1 ORDER BY t._airbyte_extracted_at DESC LIMIT $2 OFFSET $3", | ||
| table_name | ||
| ); | ||
| sqlx::query_scalar::<_, serde_json::Value>(&q) | ||
| .bind(state_filter) | ||
| .bind(limit) | ||
| .bind(offset) | ||
| .fetch_all(&state.db_pool) | ||
| .await | ||
| } else { | ||
| let q = format!( | ||
| "SELECT to_jsonb(t.*) AS row_data FROM hyprnote_github.{} t ORDER BY t._airbyte_extracted_at DESC LIMIT $1 OFFSET $2", | ||
| table_name | ||
| ); | ||
| sqlx::query_scalar::<_, serde_json::Value>(&q) | ||
| .bind(limit) | ||
| .bind(offset) | ||
| .fetch_all(&state.db_pool) | ||
| .await | ||
| }; | ||
|
|
||
| let rows = query.map_err(|e| McpError::internal_error(e.to_string(), None))?; | ||
|
|
||
| let total_count: i64 = if let Some(ref state_filter) = params.state { | ||
| let count_query = format!( | ||
| "SELECT COUNT(*) FROM hyprnote_github.{} t WHERE t.state = $1", | ||
| table_name | ||
| ); | ||
| sqlx::query_scalar(&count_query) | ||
| .bind(state_filter) | ||
| .fetch_one(&state.db_pool) | ||
| .await | ||
| .unwrap_or(0) | ||
| } else { | ||
| let count_query = format!("SELECT COUNT(*) FROM hyprnote_github.{}", table_name); | ||
| sqlx::query_scalar(&count_query) | ||
| .fetch_one(&state.db_pool) | ||
| .await | ||
| .unwrap_or(0) | ||
| }; | ||
|
|
||
| let result = serde_json::json!({ | ||
| "table": table_name, | ||
| "total_count": total_count, | ||
| "returned_count": rows.len(), | ||
| "limit": limit, | ||
| "offset": offset, | ||
| "rows": rows, | ||
| }); | ||
|
|
||
| Ok(CallToolResult::success(vec![Content::text( | ||
| result.to_string(), | ||
| )])) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.