Skip to main content

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

Creates a new PostgreSQL database. An example would be if you are creating a new application that needs to connect to a database.

Arguments

Accepts no arguments.

Returns

Returns a JSON object with the following fields:
status
string
required
The status of the database creation operation. Returns “success” when the database is created successfully.
result
string
required
The PostgreSQL connection string for the newly created database. Use this string to connect your application to the database.
Executes a SQL query against a PostgreSQL database. Examples would be if you want to get a list of tables in the database or if you want to insert a new row into a table.

Arguments

Accepts a JSON object with the following fields:
url
string
required
The URL of the database to execute the SQL against.
sql
string
required
The SQL to execute.

Returns

Returns a JSON object with the following fields:
status
string
The status of the SQL execution operation. Returns “success” when the SQL is executed successfully.
result
string
The result of the SQL execution.

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

  • Using an ATXP account
  • Using a Base account
  • Using a Solana account
  • Using a Worldchain account
  • Using a Polygon account
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.
I