ttoss Examples
This directory contains practical examples demonstrating how to use ttoss packages in real-world scenarios.
Available Examples
http-server-mcp-calculator
Demonstrates how to create a single HTTP server with both REST and MCP endpoints sharing the same business logic. Perfect for understanding how to build APIs that serve both traditional clients and AI assistants.
Key Concepts:
- Code reuse across different protocols
- Setting up REST endpoints with
@ttoss/http-server - Setting up MCP endpoints with
@ttoss/http-server-mcp - Single server instance for multiple protocols
Running Examples
Each example is a standalone package that can be run independently:
# From the example directory
cd examples/EXAMPLE_NAME
pnpm install
pnpm dev
# Or from monorepo root
pnpm --filter EXAMPLE_NAME dev
Contributing Examples
When adding new examples:
- Create a new directory under
examples/ - Include a comprehensive
README.mdexplaining:- What the example demonstrates
- How to run it
- Key concepts and architecture
- Testing instructions
- Keep the code simple and focused on the core concept
- Add comments explaining non-obvious code
- Use TypeScript for better documentation through types
- Set
"private": trueinpackage.json(examples aren't published) - Optionally, create a
buildscript withtsc --noEmitto validate ttoss/packages compatibility.
Example Template Structure
examples/
your-example/
README.md # Comprehensive documentation
package.json # With "private": true
tsconfig.json # TypeScript configuration
src/
index.ts # Main entry point