Project Structure
This guide explains the structure of a TRMX AI MCP project, helping you understand how all the components fit together.
Overview
Every MCP project follows a standardized structure that makes it easy to organize your code and collaborate with others.
Key Components
Entry Point
The src/index.js
(or src/index.ts
for TypeScript) file is the main entry point of your MCP server. It initializes and starts your server:
import { MCPServer } from '@trmx/server';
import { config } from './config';
import { tools } from './tools';
import { resources } from './resources';
import { prompts } from './prompts';
async function main() {
// Create an MCP server
const server = new MCPServer({
port: config.port,
tools,
resources,
prompts,
});
// Start the server
await server.start();
console.log(`MCP server running on port ${config.port}`);
}
main().catch(console.error);
Configuration
The src/config
directory contains settings for your MCP server. This typically includes:
File | Purpose |
---|---|
index.js | Exports all config settings |
auth.js | Authentication configuration |
database.js | Database connection settings |
logging.js | Logging settings |
A typical configuration setup:
// src/config/index.js
import dotenv from 'dotenv';
// Load environment variables
dotenv.config();
export const config = {
port: process.env.PORT || 3000,
environment: process.env.NODE_ENV || 'development',
logLevel: process.env.LOG_LEVEL || 'info',
apiKeys: {
trmx: process.env.TRMX_API_KEY,
openai: process.env.OPENAI_API_KEY,
},
};
Tools
Tools are functions that can be called by AI models to perform actions. They live in the src/tools
directory:
What is a Tool? In the MCP ecosystem, a tool is a function that allows an AI model to perform actions such as calculations, data retrieval, or API calls.
Each tool follows this structure:
// src/tools/calculator.js
export const calculatorTool = {
name: 'calculator',
description: 'Performs basic arithmetic operations',
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 ({ operation, a, b }) => {
switch (operation) {
case 'add': return { result: a + b };
case 'subtract': return { result: a - b };
case 'multiply': return { result: a * b };
case 'divide':
if (b === 0) throw new Error('Division by zero');
return { result: a / b };
default:
throw new Error(`Unknown operation: ${operation}`);
}
},
};
Tools are then exported from an index file:
// src/tools/index.js
import { weatherTool } from './weather';
import { calculatorTool } from './calculator';
export const tools = [
weatherTool,
calculatorTool,
];
Resources
Resources connect your MCP server to external data sources. They are defined in the src/resources
directory:
What is a Resource? Resources provide AI models with access to external data sources such as databases, APIs, or file systems.
A typical resource implementation:
// src/resources/documents.js
import { documentDB } from '../services/document-db';
export const documentsResource = {
name: 'documents',
description: 'Access to company documents and knowledge base',
fetch: async (query) => {
// Query the document database
const results = await documentDB.search(query);
return results.map(doc => ({
id: doc.id,
title: doc.title,
content: doc.content,
url: doc.url,
}));
},
};
Resources are then exported from an index file:
// src/resources/index.js
import { documentsResource } from './documents';
import { userDataResource } from './user-data';
export const resources = [
documentsResource,
userDataResource,
];
Prompts
Prompts help generate consistent AI responses. They are defined in the src/prompts
directory:
What is a Prompt? Prompts are templates that guide AI models to generate responses in a specific format or style.
A typical prompt implementation:
// src/prompts/greeting.js
export const greetingPrompt = {
name: 'greeting',
description: 'Generates a personalized greeting for users',
template: `
You are a helpful assistant for {{company_name}}.
User's name: {{user_name}}
User's role: {{user_role}}
Provide a warm, personalized greeting to the user. Be professional but friendly.
Mention their role and offer help related to their responsibilities.
`,
parameters: {
company_name: {
type: 'string',
description: 'The name of the company',
},
user_name: {
type: 'string',
description: 'The name of the user',
},
user_role: {
type: 'string',
description: 'The role of the user within the company',
},
},
};
Prompts are then exported from an index file:
// src/prompts/index.js
import { greetingPrompt } from './greeting';
import { supportPrompt } from './support';
export const prompts = [
greetingPrompt,
supportPrompt,
];
Supporting Files
Beyond the core components, MCP projects typically include these supporting files:
.env
Environment variables for development
package.json
Dependencies and scripts
tsconfig.json
TypeScript configuration
README.md
Project documentation
Directory Structure for Advanced Projects
As your MCP project grows, you might add these additional directories:
Directory | Purpose |
---|---|
src/middleware/ | Custom middleware functions |
src/services/ | Shared service modules |
src/types/ | TypeScript type definitions |
src/utils/ | Utility functions |
Next Steps
Now that you understand the project structure, you're ready to: