-
Notifications
You must be signed in to change notification settings - Fork 307
Return useful error message for AIs if we fail to deserialize custom datatypes #1024
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
5 commits
Select commit
Hold shift + click to select a range
41c6dff
Return useful error message for AIs if we fail to deserialize custom …
707454e
Added unit tests for ExecuteQueryAsync
ba0507e
Merge branch 'main' into users/jumacabo/postgres_custom_datatypes
27a85b5
Merge branch 'main' into users/jumacabo/postgres_custom_datatypes
d205ed0
sorted usings
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
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
23 changes: 23 additions & 0 deletions
23
tools/Azure.Mcp.Tools.Postgres/src/Providers/DbProvider.cs
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,23 @@ | ||
| using System.Data.Common; | ||
| using Npgsql; | ||
|
|
||
| namespace Azure.Mcp.Tools.Postgres.Providers | ||
| { | ||
| internal class DbProvider : IDbProvider | ||
| { | ||
| public async Task<IPostgresResource> GetPostgresResource(string connectionString) | ||
| { | ||
| return await PostgresResource.CreateAsync(connectionString); | ||
| } | ||
|
|
||
| public NpgsqlCommand GetCommand(string query, IPostgresResource postgresResource) | ||
| { | ||
| return new NpgsqlCommand(query, postgresResource.Connection); | ||
| } | ||
|
|
||
| public async Task<DbDataReader> ExecuteReaderAsync(NpgsqlCommand command) | ||
| { | ||
| return await command.ExecuteReaderAsync(); | ||
| } | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
tools/Azure.Mcp.Tools.Postgres/src/Providers/EntraTokenProvider.cs
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,15 @@ | ||
| using Azure.Core; | ||
|
|
||
| namespace Azure.Mcp.Tools.Postgres.Auth | ||
| { | ||
| internal class EntraTokenProvider : IEntraTokenProvider | ||
| { | ||
| public async Task<AccessToken> GetEntraToken(TokenCredential tokenCredential, CancellationToken cancellationToken) | ||
| { | ||
| var tokenRequestContext = new TokenRequestContext(["https://ossrdbms-aad.database.windows.net/.default"]); | ||
| var accessToken = await tokenCredential | ||
| .GetTokenAsync(tokenRequestContext, cancellationToken); | ||
| return accessToken; | ||
| } | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
tools/Azure.Mcp.Tools.Postgres/src/Providers/IDbProvider.cs
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,13 @@ | ||
| | ||
| using System.Data.Common; | ||
| using Npgsql; | ||
|
|
||
| namespace Azure.Mcp.Tools.Postgres.Providers | ||
| { | ||
| public interface IDbProvider | ||
| { | ||
| Task<IPostgresResource> GetPostgresResource(string connectionString); | ||
| NpgsqlCommand GetCommand(string query, IPostgresResource postgresResource); | ||
| Task<DbDataReader> ExecuteReaderAsync(NpgsqlCommand command); | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
tools/Azure.Mcp.Tools.Postgres/src/Providers/IEntraTokenProvider.cs
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,9 @@ | ||
| using Azure.Core; | ||
|
|
||
| namespace Azure.Mcp.Tools.Postgres.Auth | ||
| { | ||
| public interface IEntraTokenProvider | ||
| { | ||
| Task<AccessToken> GetEntraToken(TokenCredential tokenCredential, CancellationToken cancellationToken); | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
tools/Azure.Mcp.Tools.Postgres/src/Providers/IPostgresResource.cs
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,9 @@ | ||
| using Npgsql; | ||
|
|
||
| namespace Azure.Mcp.Tools.Postgres.Providers | ||
| { | ||
| public interface IPostgresResource : IAsyncDisposable | ||
| { | ||
| NpgsqlConnection Connection { get; } | ||
| } | ||
| } |
31 changes: 31 additions & 0 deletions
31
tools/Azure.Mcp.Tools.Postgres/src/Providers/PostgresResource.cs
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,31 @@ | ||
| using Npgsql; | ||
|
|
||
| namespace Azure.Mcp.Tools.Postgres.Providers | ||
| { | ||
| internal class PostgresResource : IPostgresResource | ||
| { | ||
| public NpgsqlConnection Connection { get; } | ||
| private readonly NpgsqlDataSource _dataSource; | ||
|
|
||
| public static async Task<PostgresResource> CreateAsync(string connectionString) | ||
| { | ||
| var dataSource = new NpgsqlSlimDataSourceBuilder(connectionString) | ||
| .EnableTransportSecurity() | ||
| .Build(); | ||
| var connection = await dataSource.OpenConnectionAsync(); | ||
| return new PostgresResource(dataSource, connection); | ||
| } | ||
|
|
||
| public async ValueTask DisposeAsync() | ||
| { | ||
| await Connection.DisposeAsync(); | ||
| await _dataSource.DisposeAsync(); | ||
| } | ||
|
|
||
| private PostgresResource(NpgsqlDataSource dataSource, NpgsqlConnection connection) | ||
| { | ||
| _dataSource = dataSource; | ||
| Connection = connection; | ||
| } | ||
| } | ||
| } |
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.