The MCP Server for Creem.io is organized into modular components for maintainability and scalability.
mcp-server-creem/
├── src/
│ ├── index.ts # Main entry point (40 lines)
│ ├── server.ts # Server configuration (55 lines)
│ ├── client.ts # Creem API client (83 lines)
│ ├── types.ts # TypeScript definitions (183 lines)
│ └── tools/
│ ├── definitions.ts # Tool schemas (431 lines)
│ └── handlers.ts # Tool implementations (322 lines)
├── build/ # Compiled JavaScript (generated)
├── node_modules/ # Dependencies
└── [documentation files]
Purpose: Application initialization and startup
Responsibilities:
- Read environment variables
- Validate API key
- Initialize Creem client
- Start MCP server
Key Functions:
main()- Main entry point
Dependencies:
client.ts- For API clientserver.ts- For server creation
Purpose: MCP server setup and request handling
Responsibilities:
- Create MCP server instance
- Register request handlers
- Connect to transport layer
Key Functions:
createServer(creem)- Initialize server with handlersstartServer(server, testMode, baseURL)- Start and connect server
Dependencies:
@modelcontextprotocol/sdk- MCP frameworktools/definitions.ts- Tool schemastools/handlers.ts- Tool implementations
Purpose: HTTP communication with Creem API
Responsibilities:
- Manage API authentication
- Handle HTTP requests (GET, POST, DELETE)
- Error interception and formatting
- Base URL management (test/production)
Key Class:
class CreemClient {
constructor(config: CreemConfig)
get<T>(endpoint, params?): Promise<T>
post<T>(endpoint, data?): Promise<T>
delete<T>(endpoint): Promise<T>
getBaseURL(): string
isTestMode(): boolean
}Dependencies:
axios- HTTP clienttypes.ts- Type definitions
Purpose: TypeScript type safety
Key Types:
CreemConfig- Client configurationProduct- Product entityCustomer- Customer entitySubscription- Subscription entityCheckout- Checkout sessionLicense- License keyDiscount- Discount codeTransaction- Payment transaction- Request/Response types for API operations
No Dependencies
Purpose: MCP tool schemas and metadata
Structure:
export const tools: Tool[] = [
{
name: 'tool_name',
description: 'What the tool does',
inputSchema: {
type: 'object',
properties: { /* parameters */ },
required: [ /* required params */ ]
}
},
// ... more tools
];Contains:
- 20+ tool definitions
- Input schema for each tool
- Parameter descriptions
- Validation rules
Dependencies:
@modelcontextprotocol/sdk/types- Tool type definition
Purpose: Business logic for each tool
Key Function:
handleToolCall(name, args, creem): Promise<ToolResponse>Implementation Pattern:
async function handleXyz(args, creem) {
// 1. Extract and validate parameters
// 2. Make API call(s)
// 3. Format response
// 4. Return formatted data
}Handlers for:
- Product operations (3 handlers)
- Checkout operations (2 handlers)
- Customer operations (3 handlers)
- Subscription operations (4 handlers)
- License operations (3 handlers)
- Discount operations (3 handlers)
- Transaction operations (1 handler)
Dependencies:
client.ts- API communicationtypes.ts- Type definitions
User Request
↓
Claude/AI Assistant
↓
MCP Protocol
↓
server.ts (CallToolRequestSchema handler)
↓
tools/handlers.ts (handleToolCall)
↓
Specific handler function
↓
client.ts (HTTP request)
↓
Creem API (https://api.creem.io)
↓
Response back through chain
↓
User receives formatted result
// 1. User asks Claude to create a product
"Create a product called Pro Plan for $29/month"
// 2. Claude calls the tool
{
name: "create_product",
arguments: {
name: "Pro Plan",
price: 2900,
billing_type: "recurring",
billing_period: "every-month"
}
}
// 3. Server routes to handler
server.ts → handleToolCall("create_product", args, creem)
// 4. Handler executes
handlers.ts → handleCreateProduct(args, creem)
// 5. API call
client.ts → post("/v1/products", productData)
// 6. Response formatted and returned
{
content: [{
type: "text",
text: JSON.stringify(product, null, 2)
}]
}Error occurs
↓
Caught by handler or client
↓
formatError(error) in handlers.ts
↓
Returned with isError: true
↓
User sees error message
- Validation Errors - Invalid parameters
- API Errors - Creem API responses (401, 404, etc.)
- Network Errors - Connection failures
- Unknown Tool Errors - Tool not found
CREEM_API_KEY // Required - API authentication
CREEM_TEST_MODE // Optional - "true" for test mode// Test Mode
baseURL = "https://test-api.creem.io"
// Production Mode
baseURL = "https://api.creem.io"- Add schema to
tools/definitions.ts:
{
name: 'new_tool',
description: 'Tool description',
inputSchema: { /* schema */ }
}- Add handler to
tools/handlers.ts:
async function handleNewTool(args, creem) {
// Implementation
}- Add case in
handleToolCallswitch:
case 'new_tool':
return await handleNewTool(args, creem);Add to client.ts:
async patch<T>(endpoint: string, data?: any): Promise<T> {
const response = await this.client.patch<T>(endpoint, data);
return response.data;
}Add to types.ts:
export interface NewEntity {
id: string;
// ... fields
}- Set
CREEM_TEST_MODE=true - Use test API key
- Build:
npm run build - Configure Claude Desktop
- Test each tool
- Product creation and retrieval
- Checkout session generation
- Subscription management
- License activation/validation
- Error handling
- Typical API call: < 500ms
- Pagination for large lists
- Async operations throughout
- Minimal footprint
- No data caching
- Stateless operations
- Stored in environment variables
- Never logged or exposed
- HTTPS for all communications
- Input schemas validate parameters
- Type safety via TypeScript
- Error messages sanitized
- Caching Layer - Cache product/customer data
- Batch Operations - Multiple operations in one call
- Webhook Tools - Manage webhooks via tools
- Analytics - Usage tracking and reporting
- Rate Limiting - Client-side rate limit handling
- Unit tests for handlers
- Integration tests with Creem API
- Code coverage metrics
- Linting and formatting
{
"@modelcontextprotocol/sdk": "^1.0.4",
"axios": "^1.7.2",
"zod": "^3.23.8"
}{
"@types/node": "^22.10.2",
"typescript": "^5.7.2"
}npm run buildProcess:
- TypeScript compiler reads
tsconfig.json - Compiles
src/**/*.tstobuild/**/*.js - Generates
.d.tsdeclaration files - Creates source maps
build/
├── index.js # Entry point (executable)
├── index.d.ts # Type declarations
├── server.js
├── server.d.ts
├── client.js
├── client.d.ts
├── types.js
├── types.d.ts
└── tools/
├── definitions.js
├── definitions.d.ts
├── handlers.js
└── handlers.d.ts
- Separation of Concerns - Each module has one responsibility
- DRY (Don't Repeat Yourself) - Shared logic in helpers
- Type Safety - Full TypeScript coverage
- Modularity - Easy to add/modify tools
- Documentation - Inline comments and external docs
- Semantic versioning (MAJOR.MINOR.PATCH)
- CHANGELOG.md for release notes
- Git tags for releases
- Build Failures - Check TypeScript version
- API Errors - Verify API key and mode
- Tool Not Found - Check tool name matches definition
- Type Errors - Update type definitions
# Run with debugging
npm run dev
# Check server output
console.error messages show mode and URLLast Updated: November 10, 2025
Version: 1.0.0