# Datai FastMCP TypeScript Server - Build Prompt
## Context
We are building a high-performance FastMCP TypeScript server for Datai blockchain endpoints. We have completed the planning phase and identified the best 8 performing endpoints through testing. Now we need to implement the complete server following FastMCP standards.
**š Progress Tracking**: Use [`datai_fastmcp_checklist.md`](./datai_fastmcp_checklist.md) to track implementation progress through all phases.
## Project Location
Build everything in: `/Users/ilessio/dev-agents/PARTNERS/DATAI/datai-mcp/src/`
## FastMCP TypeScript Rules (Activate as needed)
- `@fastMCP_ts-cli.mdc` - CLI tools and development commands
- `@fastMCP_ts-content.mdc` - Content handling and response formatting
- `@fastMCP_ts-core.mdc` - Core FastMCP server implementation patterns
- `@fastMCP_ts-errors.mdc` - Error handling and user-friendly error messages
- `@fastMCP_ts-logging.mdc` - Comprehensive logging standards and practices
- `@fastMCP_ts-resources.mdc` - Resource management and templates
- `@fastMCP_ts-session.mdc` - Session management and client connections
- `@fastMCP_ts-testing.mdc` - Testing patterns and validation approaches
- `@fastMCP_ts-tools.mdc` - Tool implementation and parameter validation
## API Configuration
- **Base URL**: `https://api-v1.mymerlin.io`
- **API Key**: `dbNb54fQUGCuy2xO3RXPRw7bH9nbDSkS`
- **Timeout**: 180 seconds (3 minutes)
- **Auth Header**: `Authorization: {API_KEY}`
## Test Wallet Addresses (Verified Working)
- `WALLET1="0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"`
- `WALLET2="0x09CF915e195aF33FA7B932C253352Ae9FBdB0106"`
- `WALLET3="0xbdfa4f4492dd7b7cf211209c4791af8d52bf5c50"`
## 8 Endpoints to Implement (All Tested & Working)
### DeFi Position Tools (4 tools)
1. **get_all_user_defi_positions**
- Endpoint: `/api/merlin/public/userDeFiPositions/all/{wallet}`
- Test: `curl -H "Authorization: dbNb54fQUGCuy2xO3RXPRw7bH9nbDSkS" "https://api-v1.mymerlin.io/api/merlin/public/userDeFiPositions/all/0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"`
2. **get_user_defi_positions_by_chain**
- Endpoint: `/api/merlin/public/userDeFiPositions/{wallet}?chain={chain}`
- Test: `curl -H "Authorization: dbNb54fQUGCuy2xO3RXPRw7bH9nbDSkS" "https://api-v1.mymerlin.io/api/merlin/public/userDeFiPositions/0x09CF915e195aF33FA7B932C253352Ae9FBdB0106?chain=arb"`
3. **get_user_defi_positions_by_multiple_chains**
- Endpoint: `/api/merlin/public/userDeFiPositionsByChains/{wallet}?chains={chains}`
- Test: `curl -H "Authorization: dbNb54fQUGCuy2xO3RXPRw7bH9nbDSkS" "https://api-v1.mymerlin.io/api/merlin/public/userDeFiPositionsByChains/0xbdfa4f4492dd7b7cf211209c4791af8d52bf5c50?chains=avax,arb"`
4. **get_user_defi_positions_by_protocol**
- Endpoint: `/api/merlin/public/userDeFiPositions/{wallet}?protocol={protocol}`
- Test: `curl -H "Authorization: dbNb54fQUGCuy2xO3RXPRw7bH9nbDSkS" "https://api-v1.mymerlin.io/api/merlin/public/userDeFiPositions/0x09CF915e195aF33FA7B932C253352Ae9FBdB0106?protocol=uniswap"`
### Balance Tools (4 tools)
5. **get_user_defi_protocol_balances_by_chain**
- Endpoint: `/api/merlin/public/balances/defi/{wallet}?chain={chain}`
- Test: `curl -H "Authorization: dbNb54fQUGCuy2xO3RXPRw7bH9nbDSkS" "https://api-v1.mymerlin.io/api/merlin/public/balances/defi/0x09CF915e195aF33FA7B932C253352Ae9FBdB0106?chain=arb"`
6. **get_user_overall_balance_all_chains**
- Endpoint: `/api/merlin/public/balances/all/{wallet}`
- Test: `curl -H "Authorization: dbNb54fQUGCuy2xO3RXPRw7bH9nbDSkS" "https://api-v1.mymerlin.io/api/merlin/public/balances/all/0x09CF915e195aF33FA7B932C253352Ae9FBdB0106"`
7. **get_user_overall_balance_by_chain**
- Endpoint: `/api/merlin/public/balances/overall/{wallet}?chain={chain}`
- Test: `curl -H "Authorization: dbNb54fQUGCuy2xO3RXPRw7bH9nbDSkS" "https://api-v1.mymerlin.io/api/merlin/public/balances/overall/0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045?chain=eth"`
8. **get_wallet_balances_by_chain**
- Endpoint: `/api/merlin/public/balances/token/{wallet}?chain={chain}`
- Test: `curl -H "Authorization: dbNb54fQUGCuy2xO3RXPRw7bH9nbDSkS" "https://api-v1.mymerlin.io/api/merlin/public/balances/token/0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045?chain=base"`
## Implementation Requirements
### Phase 1: Project Setup (30 min)
1. Initialize TypeScript project with FastMCP dependencies
2. Create project structure in `/Users/ilessio/dev-agents/PARTNERS/DATAI/datai-mcp/src/`
3. Set up package.json, tsconfig.json
4. Install: `fastmcp`, `zod`, `axios`, `@types/node`
### Phase 2: Core Infrastructure (45 min)
1. Create API client with authentication and logging
2. Set up FastMCP logging system (follow `@fastMCP_ts-logging.mdc`)
3. Create validation schemas with Zod
4. Implement error handling (follow `@fastMCP_ts-errors.mdc`)
### Phase 3: Tool Implementation (60 min)
1. Implement 4 DeFi position tools (follow `@fastMCP_ts-tools.mdc`)
2. Implement 4 balance tools
3. Use proper parameter validation with Zod
4. Implement comprehensive logging for each tool
### Phase 4: Server Setup (30 min)
1. Create main FastMCP server (follow `@fastMCP_ts-core.mdc`)
2. Configure STDIO and SSE transports
3. Set up session management (follow `@fastMCP_ts-session.mdc`)
4. Add health checks and monitoring
### Phase 5: Testing (45 min)
1. Create unit tests (follow `@fastMCP_ts-testing.mdc`)
2. Test with real API endpoints using provided curl commands
3. Validate with FastMCP CLI tools
4. Test both STDIO and SSE transports
### Phase 6: Documentation (30 min)
1. Create comprehensive README.md
2. Document all 8 tools with examples
3. Add configuration and deployment guide
## Critical Requirements
1. **Follow FastMCP Standards**: Use the provided rules extensively
2. **Comprehensive Logging**: Log everything for debugging (use `@fastMCP_ts-logging.mdc`)
3. **Error Handling**: User-friendly errors (use `@fastMCP_ts-errors.mdc`)
4. **Type Safety**: Full TypeScript with strict types
5. **Validation**: Zod schemas for all parameters
6. **Transport Support**: Both STDIO and SSE
7. **Real Testing**: Use the provided curl commands to validate
## Success Criteria
- All 8 tools working with real API endpoints
- Both STDIO and SSE transports functional
- Comprehensive logging and error handling
- Full TypeScript type safety
- Ready for production deployment
- Complete documentation
## Build Command for Next Chat
```
Please build the complete Datai FastMCP TypeScript server following this plan. Start with Phase 1 (Project Setup) and work through all phases systematically. Use the FastMCP TypeScript rules as needed and ensure all 8 endpoints are properly implemented and tested with the provided curl commands.
š IMPORTANT: Use the checklist in datai_fastmcp_checklist.md to track your progress and mark items as completed.
Location: /Users/ilessio/dev-agents/PARTNERS/DATAI/datai-mcp/src/
API Key: dbNb54fQUGCuy2xO3RXPRw7bH9nbDSkS
Test Wallets: 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045, 0x09CF915e195aF33FA7B932C253352Ae9FBdB0106, 0xbdfa4f4492dd7b7cf211209c4791af8d52bf5c50
Activate FastMCP rules as needed:
@fastMCP_ts-core.mdc @fastMCP_ts-tools.mdc @fastMCP_ts-logging.mdc @fastMCP_ts-errors.mdc @fastMCP_ts-testing.mdc @fastMCP_ts-session.mdc @fastMCP_ts-content.mdc @fastMCP_ts-cli.mdc @fastMCP_ts-resources.mdc
Build this today - we need it production ready!
```