# Source Code (src/)
This is the main source code directory for the GearTrade MCP Server. All TypeScript source files are organized here and compiled to the `dist/` directory.
## š Directory Structure
```
src/
āāā formatters/ Output formatting utilities (17 files)
āāā memory/ AI memory storage and management
āāā prompts/ AI prompt templates (31 prompts)
āāā resources/ Educational resources (4 resources)
āāā server/ HTTP/SSE infrastructure
āāā signal-generation/ Core analysis engine
ā āāā analysis/ Market analysis modules
ā āāā data-fetchers/ API integrations
ā āāā exit-conditions/ Exit strategy calculations
ā āāā position-management/ Position tracking
ā āāā risk-management/ Risk and leverage calculations
ā āāā technical-indicators/ Indicator implementations
ā āāā types/ TypeScript type definitions
ā āāā utils/ Utility functions
āāā tools/ 69 MCP tools (5 categories)
ā āāā account/ 10 account management tools
ā āāā analysis/ 15 market analysis tools
ā āāā data/ 3 price & position tools
ā āāā indicators/ 35 technical indicator tools
ā āāā trading/ 6 trading execution tools
āāā index.ts Main entry point
```
## š Main Components
### 1. Entry Point (`index.ts`)
The main entry point that:
- Initializes the MCP server
- Registers all 69 tools
- Registers 31 prompts
- Registers 4 resources
- Sets up stdio or HTTP/SSE transport
- Handles errors and logging
### 2. Formatters
Utilities for formatting tool outputs:
- Technical indicators
- Volume analysis
- Market structure
- Order book depth
- Position data
- Risk calculations
See [formatters/README.md](formatters/README.md) for details.
### 3. Memory
AI memory storage using Mem0:
- Trade journaling
- Pattern learning
- Preference storage
- Performance tracking
See [memory/README.md](memory/README.md) for details.
### 4. Prompts
31 AI prompt templates for:
- Day trading workflows
- Swing trading strategies
- Position trading analysis
See [prompts/README.md](prompts/README.md) for details.
### 5. Resources
4 educational resources:
- Trading strategy guide
- Technical analysis reference
- Risk management guide
- Tool usage patterns
See [resources/README.md](resources/README.md) for details.
### 6. Server
HTTP/SSE infrastructure:
- CORS middleware
- JSON-RPC 2.0 handler
- Request/response processing
See [server/README.md](server/README.md) for details.
### 7. Signal Generation
Core analysis engine with:
- Market analysis algorithms
- Data fetchers (Hyperliquid, HyperScreener, etc.)
- Technical indicator calculations
- Risk management calculations
- Position management logic
See [signal-generation/README.md](signal-generation/README.md) for details.
### 8. Tools
69 MCP tools organized into 5 categories:
- **Account** (10 tools) - See [tools/account/README.md](tools/account/README.md)
- **Analysis** (15 tools) - See [tools/analysis/README.md](tools/analysis/README.md)
- **Data** (3 tools) - See [tools/data/README.md](tools/data/README.md)
- **Indicators** (35 tools) - See [tools/indicators/README.md](tools/indicators/README.md)
- **Trading** (6 tools) - See [tools/trading/README.md](tools/trading/README.md)
## š§ Architecture
### Component Flow
```
index.ts (Entry Point)
ā
MCP Server Initialization
ā
Register Components:
āāā Tools (69)
ā āāā Use signal-generation for calculations
ā āāā Use formatters for output
ā āāā Use data-fetchers for external data
āāā Prompts (31)
ā āāā Reference tools and resources
āāā Resources (4)
āāā Provide educational content
ā
Transport Setup (stdio or HTTP)
ā
Ready to Accept Requests
```
### Data Flow
```
AI Assistant Request
ā
Tool Invocation
ā
Data Fetching (signal-generation/data-fetchers)
ā
Analysis/Calculation (signal-generation/analysis)
ā
Formatting (formatters)
ā
Response to AI Assistant
```
## šÆ Key Features
### Modular Design
- Each directory has a specific purpose
- Clear separation of concerns
- Easy to maintain and extend
### Type Safety
- Full TypeScript coverage
- Zod schema validation
- Type definitions in `signal-generation/types/`
### Extensibility
- Easy to add new tools
- Simple to add new indicators
- Straightforward to add new data sources
### Performance
- Parallel tool execution support
- Efficient data fetching
- Minimal dependencies
## š Code Statistics
```
Total Files: ~150+
Total Lines: ~30,000+
TypeScript: 100%
Components: 104 (69 tools + 31 prompts + 4 resources)
Categories: 5 (account, analysis, data, indicators, trading)
```
## š Development
### Adding a New Tool
1. **Choose Category**: Determine which category (account, analysis, data, indicators, trading)
2. **Create Tool File**: Add to appropriate subdirectory
```typescript
// tools/analysis/new-tool.ts
import { z } from 'zod'
export function registerNewTool(server: any) {
server.registerTool(
'new_tool',
{
title: 'New Tool',
description: 'Tool description',
inputSchema: z.object({
param: z.string()
}),
outputSchema: z.object({
result: z.string()
})
},
async ({ param }) => {
// Implementation
return {
content: [{ type: 'text', text: 'result' }],
structuredContent: { result: 'data' }
}
}
)
}
```
3. **Export from Category**: Add to category `index.ts`
```typescript
export { registerNewTool } from './new-tool'
```
4. **Register in Main**: Already handled by category registration
### Adding a New Indicator
1. **Implement Calculation**: Add to `signal-generation/technical-indicators/`
```typescript
export function calculateNewIndicator(data: number[], period: number) {
// Calculation logic
return {
value: result,
signal: 'BUY' | 'SELL' | 'NEUTRAL'
}
}
```
2. **Create Tool**: Add to `tools/indicators/`
3. **Add Formatter**: If needed, add to `formatters/`
### Adding a New Data Source
1. **Create Fetcher**: Add to `signal-generation/data-fetchers/`
```typescript
export async function fetchNewData(symbol: string) {
// API call
return data
}
```
2. **Create Tool**: If exposing as tool, add to `tools/data/`
## š ļø Build Process
### TypeScript Compilation
```bash
# Compile TypeScript to JavaScript
npm run build
# Output directory: dist/
# Source maps: dist/**/*.js.map
# Type declarations: dist/**/*.d.ts
```
### Build Configuration
- **Target**: ES2020
- **Module**: CommonJS
- **Strict Mode**: Enabled
- **Source Maps**: Generated
- **Declaration Files**: Generated
## š Code Style
### Naming Conventions
- **Files**: kebab-case (e.g., `market-sentiment.ts`)
- **Functions**: camelCase (e.g., `calculateRSI`)
- **Classes**: PascalCase (e.g., `TechnicalAnalyzer`)
- **Constants**: UPPER_SNAKE_CASE (e.g., `MAX_RETRIES`)
### Import Order
1. External dependencies
2. Internal modules (signal-generation)
3. Formatters
4. Types
5. Utilities
### Documentation
- JSDoc comments for public functions
- Inline comments for complex logic
- README files in each directory
## š Security
- Environment variables for sensitive data
- No hardcoded secrets
- Input validation with Zod
- Safe wallet operations
- Testnet available for testing
## š Future Enhancements
- [ ] GraphQL API support
- [ ] WebSocket real-time streaming
- [ ] Plugin system for custom tools
- [ ] Hot reload for development
- [ ] Advanced caching layer
- [ ] Performance monitoring
- [ ] Unit test coverage
- [ ] Integration tests
## š Related Documentation
- [Formatters](formatters/README.md)
- [Memory](memory/README.md)
- [Prompts](prompts/README.md)
- [Resources](resources/README.md)
- [Server](server/README.md)
- [Signal Generation](signal-generation/README.md)
- [Tools](tools/README.md)
- [Account Tools](tools/account/README.md)
- [Analysis Tools](tools/analysis/README.md)
- [Data Tools](tools/data/README.md)
- [Indicator Tools](tools/indicators/README.md)
- [Trading Tools](tools/trading/README.md)
---
**Note**: This directory contains all source code. The compiled JavaScript is in `dist/` directory.