Overview

Use the Database MCP server from your ATXP-powered agent to store and retrieve data in a PostgreSQL database. The Database MCP server can be used to:
  • create tables
  • insert data into tables
  • retrieve data from tables

Example prompts

  • “Create a table called users with the columns id, name, and email.”
  • “Insert the following data into the users table: 1, John Doe, john.doe@example.com.”
  • “Retrieve all the data from the users table.”

Tools

Usage

1

Define the Database service

Create a reusable service configuration that points to the MCP server and standardizes how you pass arguments and read results. This lets your agent easily interact with the Database tools in a consistent manner.
const databaseService = {
    mcpServer: 'https://database.mcp.atxp.ai/',
    createDatabaseToolName: 'database_create_database',
    executeSqlToolName: 'database_execute_sql',
    description: 'ATXP Database MCP server',
    getArguments: (url: string, query: string) => ({ url, query }),
    getResult: (result: any) => {
      const jsonResult = result.content[0].text
      return JSON.parse(jsonResult);
    }
  };
2

Create an ATXP client

Create a client using an ATXP account by importing the ATXP client SDK and other dependencies.
// Import the ATXP client SDK
import { atxpClient, ATXPAccount } from '@atxp/client';

// Read the ATXP account details from environment variables
const atxpConnectionString = process.env.ATXP_CONNECTION;

// Create a client using the `atxpClient` function
const client = await atxpClient({
  mcpServer: databaseService.mcpServer,
  account: new ATXPAccount(atxpConnectionString),
});
3

Use the Database service in your agent

Call the Database tool by passing your natural‑language instruction as the argument the getArguments method.Read the response using the getResult method.
const createTableQuery = "CREATE TABLE users (id INT, name VARCHAR(255), email VARCHAR(255))";

try {
  const createResult = await client.callTool({
      name: databaseService.createDatabaseToolName,
      arguments: databaseService.getArguments(),
  });
  const createDBResult = databaseService.getResult(createResult);
  const dbUrl = createDBResult.result;

  console.log('Status:', createDBResult.status);
  console.log('Result:', createDBResult.result);

  const executeResult = await client.callTool({
      name: databaseService.executeSqlToolName,
      arguments: databaseService.getArguments(dbUrl, createTableQuery),
  });
  const result = databaseService.getResult(executeResult);
  console.log('Status:', result.status);
  console.log('Result:', result.result);
} catch (error) {
  console.error(`Error with ${crawlService.description}:`, error);
  process.exit(1);
}
You should see the result of the database query printed in your console.