TRMX AI API Reference
This page provides an overview of the TRMX AI API and Model Context Protocol (MCP) interfaces. Use this reference to understand the available APIs, endpoints, and protocols for building MCP applications.
API Overview
TRMX AI provides several APIs for building context-aware AI applications:
- MCP Client API: For applications that need to connect to MCP servers
- MCP Server API: For building custom MCP servers
- TRMX AI REST API: For direct integration with TRMX AI services
MCP Client API
The MCP Client API enables applications to connect to MCP servers and use their capabilities.
Core Classes
MCPClient
: The main client class for connecting to MCP serversConversation
: Manages conversation context and interactionsToolCall
: Represents a call to an MCP tool
Basic Usage
// Create an MCP client
const client = new MCPClient({
serverUrl: 'http://localhost:3000'
});
// List available tools
const tools = await client.request({ method: 'tools/list' });
// Call a tool
const result = await client.request({
method: 'tools/call',
params: {
name: 'get_weather',
arguments: { location: 'New York' }
}
});
// Create a conversation
const conversation = client.createConversation({
contextId: 'user-123'
});
// Send a message in conversation context
const response = await conversation.sendMessage('Hello, world!');
Transport Options
The MCP Client API supports various transport mechanisms:
- HTTP/SSE: For web applications and remote servers
- WebSockets: For real-time bidirectional communication
- STDIO: For local process communication
// HTTP/SSE client
const httpClient = new MCPClient({
transport: 'http',
serverUrl: 'https://example.com/mcp'
});
// WebSocket client
const wsClient = new MCPClient({
transport: 'websocket',
serverUrl: 'wss://example.com/mcp'
});
// STDIO client (local process)
const stdioClient = new MCPClient({
transport: 'stdio',
command: 'node ./my-mcp-server.js'
});
MCP Server API
The MCP Server API enables developers to build custom MCP servers.
Core Classes
MCPServer
: The main server classTool
: Defines a tool that can be called by clientsResource
: Provides data and context to clientsPrompt
: Defines reusable prompt templates
Basic Usage
// Create and start an MCP server
const server = new MCPServer({
tools: [weatherTool, calculatorTool],
resources: [documentsResource],
prompts: [greetingPrompt],
port: 3000
});
await server.start();
Tool Definition
// Define a tool
const calculatorTool = {
name: 'calculator',
description: 'Perform basic calculations',
parameters: {
type: 'object',
properties: {
operation: {
type: 'string',
enum: ['add', 'subtract', 'multiply', 'divide'],
description: 'The operation to perform'
},
a: { type: 'number', description: 'First operand' },
b: { type: 'number', description: 'Second operand' }
},
required: ['operation', 'a', 'b']
},
execute: async (params) => {
const { operation, a, b } = params;
switch (operation) {
case 'add': return { result: a + b };
case 'subtract': return { result: a - b };
case 'multiply': return { result: a * b };
case 'divide': return { result: a / b };
default: throw new Error(`Unknown operation: ${operation}`);
}
}
};
Resource Definition
// Define a resource
const documentsResource = {
name: 'documents',
description: 'Access to document repository',
fetch: async (query) => {
// Fetch documents based on the query
// ...
return [
{ id: 'doc-1', title: 'Getting Started', content: '...' },
{ id: 'doc-2', title: 'Advanced Usage', content: '...' }
];
}
};
Prompt Definition
// Define a prompt template
const greetingPrompt = {
name: 'greeting',
description: 'Generate a greeting for the user',
template: `
You are a helpful assistant.
User's name: {{user_name}}
Time of day: {{time_of_day}}
Generate a friendly greeting for the user.
`,
parameters: {
type: 'object',
properties: {
user_name: {
type: 'string',
description: 'The name of the user'
},
time_of_day: {
type: 'string',
description: 'The time of day (morning, afternoon, evening)'
}
},
required: ['user_name']
}
};
TRMX AI REST API
The TRMX AI REST API provides direct access to TRMX AI services.
Authentication
// Authenticate with API key
const trmx = new TrmxClient({
apiKey: 'your-api-key'
});
Key Endpoints
/api/v1/conversations
: Manage conversations/api/v1/complete
: Generate completions/api/v1/servers
: Manage MCP servers/api/v1/tools
: Access and manage tools
Protocol Reference
MCP Protocol Methods
Method | Description | Parameters |
---|---|---|
tools/list | List available tools | None |
tools/call | Call a tool with arguments | name , arguments |
resources/list | List available resources | None |
resources/fetch | Fetch data from a resource | name , query |
prompts/list | List available prompt templates | None |
prompts/render | Render a prompt template | name , parameters |
auth/token | Get or refresh an authentication token | grant_type , client_id , etc. |
JSON-RPC Request Format
{
"jsonrpc": "2.0",
"id": "request-123",
"method": "tools/call",
"params": {
"name": "get_weather",
"arguments": {
"location": "New York"
}
}
}
JSON-RPC Response Format
{
"jsonrpc": "2.0",
"id": "request-123",
"result": {
"temperature": 72,
"conditions": "partly cloudy",
"location": "New York"
}
}
Client Libraries
TRMX AI provides client libraries for various programming languages:
- JavaScript/TypeScript:
@trmx/client
- Python:
trmx-client
- Java:
trmx-java-client
- C#:
Trmx.Client
- Go:
github.com/trmx/client-go
Next Steps
For more detailed API documentation, check out the following resources: