Overview

Use the Code MCP server from your ATXP-powered agent to run code in a variety of languages in a sandboxed environment.

Example prompts

  • “Run the following python code: print(‘Hello, world!’)”
  • “What is the result of this javascript code: console.log(‘Hello, world!’);”
  • “What is the result of this Scheme code: (display ‘Hello, world!)”

Tools

Usage

1

Define the Code 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 Code tools in a consistent manner.
const codeService = {
    mcpServer: 'https://code.mcp.atxp.ai/',
    executeCodeToolName: 'code_execute_code',
    description: 'ATXP Code MCP server',
    getArguments: (code: string, language: string) => ({ code, language }),
    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: codeService.mcpServer,
  account: new ATXPAccount(atxpConnectionString),
});
3

Use the Code service in your agent

Call the Code tool by passing your natural‑language instruction as the argument the getArguments method.Read the response using the getResult method.
const code = "print('Hello, world!')";
const language = "python";

try {
  const result = await client.callTool({
      name: codeService.executeCodeToolName,
      arguments: codeService.getArguments(code, language),
  });
  const result = codeService.getResult(result);
  console.log('Status:', result.status);
  console.log('Output:', result.output);
  console.log('Exit code:', result.exitCode);
} catch (error) {
  console.error(`Error with ${codeService.description}:`, error);
  process.exit(1);
}
You should see the result of the code printed in your console.