Package com.tnsai.mcp.database
Class PostgresMcpClient
java.lang.Object
com.tnsai.mcp.database.PostgresMcpClient
Client for PostgreSQL MCP server.
Provides convenience methods for common PostgreSQL operations by wrapping
MCP tool calls to a PostgreSQL MCP server. All operations are performed
through the underlying McpClient.
Example usage:
McpClient mcpClient = McpClient.create(transport);
mcpClient.connect();
mcpClient.initialize();
PostgresMcpClient postgres = new PostgresMcpClient(mcpClient);
JsonNode tables = postgres.listTables();
JsonNode result = postgres.executeQuery("SELECT * FROM users LIMIT 10");
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionPostgresMcpClient(McpClient mcpClient) Creates a new PostgresMcpClient wrapping the given MCP client. -
Method Summary
Modifier and TypeMethodDescriptioncom.fasterxml.jackson.databind.JsonNodedescribeTable(String table) Describes the schema of a table.com.fasterxml.jackson.databind.JsonNodeexecuteQuery(String sql) Executes a SQL query.Returns the underlying MCP client.booleanChecks if the PostgreSQL MCP server is available.com.fasterxml.jackson.databind.JsonNodeLists all tables in the database.
-
Constructor Details
-
PostgresMcpClient
Creates a new PostgresMcpClient wrapping the given MCP client.- Parameters:
mcpClient- the MCP client connected to a PostgreSQL MCP server- Throws:
IllegalArgumentException- if mcpClient is null
-
-
Method Details
-
executeQuery
Executes a SQL query.- Parameters:
sql- the SQL query to execute- Returns:
- the query results as JSON
- Throws:
IOException- if the MCP call fails
-
listTables
Lists all tables in the database.- Returns:
- the list of tables as JSON
- Throws:
IOException- if the MCP call fails
-
describeTable
Describes the schema of a table.- Parameters:
table- the table name- Returns:
- the table description as JSON
- Throws:
IOException- if the MCP call fails
-
getMcpClient
Returns the underlying MCP client.- Returns:
- the MCP client
-
isAvailable
public boolean isAvailable()Checks if the PostgreSQL MCP server is available.- Returns:
- true if the MCP client is connected and initialized
-