Skip to main content

Overview

In this tutorial, you’ll build a simple command-line client that uses ATXP to search the web. Starting from an empty directory, you’ll learn how to set up a project, install dependencies, configure authentication, and make your first MCP server call. By the end of this tutorial, you’ll have a working CLI that can search the web using the Search MCP server.

Prerequisites

  • Node.js installed (version 18 or higher recommended)
  • An ATXP account with a connection string (learn how to create an account)
  • A terminal or command prompt

Step 1: Create your project

First, let’s create a new directory for your project and navigate into it:
mkdir my-atxp-cli
cd my-atxp-cli
Now initialize a new Node.js project:
npm init -y
This creates a package.json file with default values.

Step 2: Install dependencies

Install the ATXP client SDK and dotenv for managing environment variables:
npm install @atxp/client dotenv
The @atxp/client package provides everything you need to connect to MCP servers and make tool calls. The dotenv package helps you securely manage your connection string.

Step 3: Set up your environment variables

Create a .env file in your project directory to store your ATXP connection string:
touch .env
Open the .env file in your text editor and add your ATXP connection string:
.env
ATXP_CONNECTION=https://accounts.atxp.ai?connection_token=<your_token_here>
If you don’t have an ATXP connection string yet, follow the account creation guide to get one.
Never commit your .env file to version control. Add it to your .gitignore file:
echo .env >> .gitignore

Step 4: Write your CLI script

Create a new file called index.js:
touch index.js
Now let’s build the script step by step. Open index.js in your text editor.

Step 4a: Load dependencies and create an account

Add the imports and create an ATXP account from your connection string:
index.js
const { atxpClient, ATXPAccount } = require('@atxp/client');
require('dotenv/config');

const account = new ATXPAccount(process.env.ATXP_CONNECTION);

Step 4b: Connect to the Search MCP server

Create a client that connects to the Search MCP server:
index.js
const client = await atxpClient({
  mcpServer: 'https://search.mcp.atxp.ai',
  account: account,
});

Step 4c: Call the search tool and display results

Call the search tool and output the results:
index.js
const result = await client.callTool({
  name: 'search_search',
  arguments: { query: 'latest news on artificial intelligence' }
});

const searchResult = JSON.parse(result.content[0].text);
searchResult.results.forEach((item, index) => {
  console.log(`${index + 1}. ${item.title}`);
  console.log(`   ${item.url}\n`);
});

Complete code

Your full index.js file should look like this:
index.js
const { atxpClient, ATXPAccount } = require('@atxp/client');
require('dotenv/config');

async function main() {
  const account = new ATXPAccount(process.env.ATXP_CONNECTION);

  const client = await atxpClient({
    mcpServer: 'https://search.mcp.atxp.ai',
    account: account,
  });

  const result = await client.callTool({
    name: 'search_search',
    arguments: { query: 'latest news on artificial intelligence' }
  });

  const searchResult = JSON.parse(result.content[0].text);
  searchResult.results.forEach((item, index) => {
    console.log(`${index + 1}. ${item.title}`);
    console.log(`   ${item.url}\n`);
  });
}

main();

Step 5: Run your CLI

Now you’re ready to run your CLI! Execute the following command:
node index.js
You should see output similar to this:
Creating ATXP client...
Client created successfully!
Searching the web...

Found 10 results:

1. AI Breakthrough: New Language Model Achieves...
   URL: https://example.com/ai-news
   Recent developments in artificial intelligence have led to significant breakthroughs in natural language processing...
   Published: 2 days ago

2. Tech Giants Invest Billions in AI Research
   URL: https://example.com/tech-investment
   Major technology companies announced record investments in artificial intelligence research and development...
   Published: 3 days ago

...
Congratulations! You’ve successfully built a working ATXP client that can search the web using MCP servers.

Understanding the code

Let’s break down what your CLI does:
  1. Import dependencies: You import the ATXP client SDK and load environment variables
  2. Create account: You create an ATXPAccount instance using your connection string
  3. Create client: You use atxpClient() to create a client connected to the Search MCP server
  4. Call tool: You use client.callTool() to invoke the search_search tool with a query
  5. Parse results: You parse the JSON response and display the search results

Customizing your CLI

Now that you have a working CLI, try customizing it:

Change the search query

Modify the query argument in the callTool() call:
arguments: { query: 'your custom search query here' }

Accept command-line arguments

Make your CLI accept a search query as a command-line argument:
// Get query from command line or use default
const query = process.argv[2] || 'latest news on artificial intelligence';

const result = await client.callTool({
  name: 'search_search',
  arguments: { query: query }
});
Then run it with:
node index.js "your search query"

Try different MCP servers

Explore other MCP servers by changing the mcpServer URL. Check out the MCP Servers documentation to see what’s available.

Next steps