Skip to content

Commit 21d2278

Browse files
committed
Update the docs
1 parent 741174e commit 21d2278

11 files changed

Lines changed: 447 additions & 30 deletions

en/README.md

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ tinystruct is a simple yet powerful framework for Java development. It embraces
99

1010
## Key Features
1111

12-
- **Lightweight Architecture**: Minimal overhead with maximum flexibility
13-
- **Dual-Mode Support**: Build both web applications and CLI tools
14-
- **Simple Configuration**: Easy to set up and customize
15-
- **High Performance**: Optimized for efficient execution
16-
- **Database Integration**: Built-in support for multiple databases
17-
- **RESTful Support**: Easy API development
18-
- **Command Line Tools**: Powerful CLI capabilities
12+
- **Modern Architecture**: No `main()` method required, applications start directly via CLI
13+
- **Dual-Mode Support**: CLI and Web are treated as equal citizens
14+
- **Built-in Servers**: Native support for Netty, Tomcat, and Undertow
15+
- **AI-Ready**: Designed for AI integration and Model Context Protocol (MCP)
16+
- **SSE Support**: Native Server-Sent Events for real-time applications
17+
- **High Performance**: Optimized to handle 86,000+ requests per second
18+
- **Minimal Configuration**: Zero-boilerplate philosophy
19+
- **Annotation-Based Routing**: Clean and intuitive routing with `@Action`
1920

2021
## Quick Start
2122

@@ -27,7 +28,7 @@ Add the dependency to your pom.xml:
2728
<dependency>
2829
<groupId>org.tinystruct</groupId>
2930
<artifactId>tinystruct</artifactId>
30-
<version>1.7.19</version>
31+
<version>1.7.21</version>
3132
<classifier>jar-with-dependencies</classifier>
3233
</dependency>
3334
```
@@ -57,9 +58,24 @@ public class Example extends AbstractApplication {
5758
public String say(String words) {
5859
return words;
5960
}
61+
62+
@Action(value = "hello", mode = Mode.HTTP_GET)
63+
public String helloGet() {
64+
return "GET";
65+
}
6066
}
6167
```
6268

69+
## What makes tinystruct modern?
70+
71+
1. **No `main()` method required**: Applications can be started directly using CLI commands like `bin/dispatcher`, with no boilerplate code needed.
72+
2. **Unified design for CLI and Web**: Unlike many frameworks, tinystruct treats CLI and Web as equal citizens. This makes it perfect for AI tasks, script automation, and hybrid applications.
73+
3. **Built-in lightweight HTTP server**: Whether it’s Netty or Tomcat, tinystruct integrates the server lifecycle inside the framework.
74+
4. **Minimal configuration philosophy**: Configuration is minimized to the essentials. No need to wire up hundreds of beans or complex XML/YAML files.
75+
5. **Annotation-based routing**: Clean and intuitive routing using `@Action`, eliminating complex controller hierarchies.
76+
6. **Performance-first architecture**: Almost zero overhead. No reflection-based bean scanning or unnecessary interceptors.
77+
7. **AI & MCP Integration**: Built-in support for Model Context Protocol (MCP) and AI-driven workflows.
78+
6379
## Documentation Contents
6480

6581
- [Getting Started](getting-started.md)
@@ -70,6 +86,7 @@ public class Example extends AbstractApplication {
7086
- [Database Integration](database.md)
7187
- [Advanced Features](advanced-features.md)
7288
- [Best Practices](best-practices.md)
89+
- [AI & MCP Integration](mcp-integration.md)
7390
- [API Reference](api/README.md)
7491

7592
## Community and Support

en/cli-applications.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ This guide explains how to build command-line interface (CLI) applications using
66

77
tinystruct's CLI capabilities are powered by the same action mechanism used for web applications, making it easy to create both CLI tools and web interfaces with shared code.
88

9+
## Unified Design for CLI and Web
10+
11+
Unlike many other frameworks that treat CLI as an afterthought, tinystruct treats CLI and Web as equal citizens. This means:
12+
- You can use the same `@Action` annotations for both modes.
13+
- Business logic is naturally shared without extra layers.
14+
- You can test your web actions via CLI easily.
15+
- It's perfect for AI-driven tasks and automation.
16+
17+
## No main() Method Required
18+
19+
One of the modern features of tinystruct is that it doesn't require a `main()` method in your application classes. Applications are started directly using the `bin/dispatcher` tool. This reduces boilerplate and focuses your code on the logic itself.
20+
921
## Creating CLI Commands
1022

1123
### Basic Command

en/getting-started.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Add the tinystruct dependency to your project's `pom.xml` file:
2929
<dependency>
3030
<groupId>org.tinystruct</groupId>
3131
<artifactId>tinystruct</artifactId>
32-
<version>1.7.19</version>
32+
<version>1.7.21</version>
3333
<classifier>jar-with-dependencies</classifier>
3434
</dependency>
3535
```
@@ -84,6 +84,14 @@ public class HelloWorldApp extends AbstractApplication {
8484
public String greetPost() {
8585
return "POST: Hello!";
8686
}
87+
88+
@Action("say")
89+
public String say() throws ApplicationException {
90+
if (null != getContext().getAttribute("--words"))
91+
return getContext().getAttribute("--words").toString();
92+
93+
throw new ApplicationException("Could not find the parameter <i>words</i>.");
94+
}
8795
}
8896
```
8997

@@ -231,6 +239,7 @@ tinystruct is designed for high performance:
231239
- **Zero overhead** - no reflection-based scanning
232240
- **Direct method invocation** - no proxy layers
233241
- **Minimal memory footprint**
242+
- **AI & MCP Ready** - built-in support for AI workflows
234243

235244
## Next Steps
236245

@@ -241,6 +250,7 @@ tinystruct is designed for high performance:
241250
- Dive into [Database Integration](database.md)
242251
- Review [Advanced Features](advanced-features.md)
243252
- Follow [Best Practices](best-practices.md)
253+
- Learn about [AI & MCP Integration](mcp-integration.md)
244254

245255
## Examples and Resources
246256

en/mcp-integration.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# AI & MCP Integration with tinystruct
2+
3+
The Model Context Protocol (MCP) module for tinystruct provides comprehensive integration for AI model interactions, tool discovery, resource management, and prompt handling.
4+
5+
## Overview
6+
7+
The MCP module enables tinystruct applications to act as both MCP servers and clients. It supports the standard MCP specification including JSON-RPC communication, Server-Sent Events (SSE), and a unified resource model.
8+
9+
## Key Concepts
10+
11+
- **MCPApplication**: The base class for applications that want to handle MCP requests.
12+
- **MCPServer**: A complete server implementation that manages tools, resources, and prompts.
13+
- **MCPClient**: A client used to connect to and interact with MCP servers.
14+
- **MCPTool**: Executable functions that can be discovered and called by AI models.
15+
- **MCPResource**: Data sources that can be read by AI models.
16+
- **MCPPrompt**: Template-based text generation for AI prompts.
17+
18+
## Implementation
19+
20+
### Creating an MCP Server
21+
22+
To create an MCP server, extend the `MCPServer` class and register your tools, resources, or prompts in the `init()` method:
23+
24+
```java
25+
import org.tinystruct.mcp.MCPServer;
26+
import org.tinystruct.mcp.tools.CalculatorTool;
27+
28+
public class MyMCPServer extends MCPServer {
29+
30+
@Override
31+
public void init() {
32+
super.init();
33+
34+
// Register built-in tools
35+
CalculatorTool calculator = new CalculatorTool();
36+
this.registerTool(calculator);
37+
38+
// Register custom tools
39+
this.registerTool(new MyCustomTool());
40+
}
41+
}
42+
```
43+
44+
### Creating a Custom Tool
45+
46+
Custom tools can be created by extending `MCPTool` and using the `@Action` annotation to define executable methods:
47+
48+
```java
49+
import org.tinystruct.mcp.MCPTool;
50+
import org.tinystruct.system.annotation.Action;
51+
import org.tinystruct.system.annotation.Argument;
52+
53+
public class MyCustomTool extends MCPTool {
54+
55+
public MyCustomTool() {
56+
super("my-tool", "A custom tool for data processing", null, null, true);
57+
}
58+
59+
@Action(value = "my-tool/process",
60+
description = "Process input data",
61+
arguments = {
62+
@Argument(key = "input", description = "The data to process", type = "string")
63+
})
64+
public String processData(String input) {
65+
return "Processed: " + input.toUpperCase();
66+
}
67+
}
68+
```
69+
70+
### Using the MCP Client
71+
72+
You can connect to an MCP server programmatically using the `MCPClient`:
73+
74+
```java
75+
import org.tinystruct.mcp.MCPClient;
76+
import java.util.HashMap;
77+
import java.util.Map;
78+
79+
public class ClientExample {
80+
public static void main(String[] args) {
81+
MCPClient client = new MCPClient("http://localhost:8080", "your-auth-token");
82+
83+
try {
84+
client.connect();
85+
86+
// Execute a tool
87+
Map<String, Object> params = new HashMap<>();
88+
params.put("a", 10);
89+
params.put("b", 20);
90+
Object result = client.executeResource("calculator/add", params);
91+
92+
System.out.println("Result: " + result);
93+
} catch (Exception e) {
94+
e.printStackTrace();
95+
} finally {
96+
client.disconnect();
97+
}
98+
}
99+
}
100+
```
101+
102+
## Running the Server
103+
104+
Start your MCP server using the tinystruct dispatcher:
105+
106+
```bash
107+
bin/dispatcher start --import com.example.MyMCPServer
108+
```
109+
110+
## CLI Interaction
111+
112+
The tinystruct CLI also provides commands to interact with MCP servers:
113+
114+
```bash
115+
# Connect to a server
116+
bin/dispatcher mcp/connect --url http://localhost:8080
117+
118+
# List available tools
119+
bin/dispatcher mcp/list/tools
120+
121+
# Call a tool
122+
bin/dispatcher mcp/call --name calculator/add --arguments "a:10,b:20"
123+
124+
# Disconnect
125+
bin/dispatcher mcp/disconnect
126+
```
127+
128+
## Real-time Updates with SSE
129+
130+
The MCP module uses Server-Sent Events (SSE) for real-time notifications. When a tool or resource is updated on the server, connected clients receive immediate notifications via the `MCPPushManager`.

en/web-applications.md

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@ tinystruct supports multiple web servers:
1212
bin/dispatcher start --import org.tinystruct.system.NettyHttpServer
1313
```
1414

15-
### Tomcat Server
15+
### Undertow Server
1616

1717
```bash
18-
bin/dispatcher start --import org.tinystruct.system.TomcatServer
18+
bin/dispatcher start --import org.tinystruct.system.UndertowServer
19+
```
20+
21+
### Built-in HTTP Server (Minimal)
22+
23+
```bash
24+
bin/dispatcher start --import org.tinystruct.system.HttpServer
1925
```
2026

2127
## Request Handling
@@ -32,7 +38,7 @@ The framework automatically routes requests to the appropriate method based on t
3238

3339
### HTTP Method-Specific Actions
3440

35-
New in version 1.7.17, you can specify which HTTP methods an action responds to using the `mode` parameter:
41+
New in version 1.7.21, you can specify which HTTP methods an action responds to using the `mode` parameter:
3642

3743
```java
3844
import org.tinystruct.system.annotation.Action.Mode;
@@ -479,6 +485,42 @@ public Object adminUsers(Request request, Response response) {
479485
}
480486
```
481487

488+
## Server-Sent Events (SSE)
489+
490+
tinystruct provides native support for Server-Sent Events (SSE), which allows servers to push real-time updates to web pages over HTTP.
491+
492+
### Creating an SSE Endpoint
493+
494+
To create an SSE endpoint, you can use the `SSEPushManager`:
495+
496+
```java
497+
@Action("events")
498+
public void handleEvents(Request request, Response response) {
499+
String sessionId = request.getSession().getId();
500+
501+
// Register the client for SSE
502+
SSEPushManager.getInstance().register(sessionId, response);
503+
504+
// The connection will be kept open automatically
505+
}
506+
507+
@Action("notify")
508+
public String notifyClient(String message, Request request) {
509+
String sessionId = request.getSession().getId();
510+
511+
// Push data to a specific client
512+
SSEPushManager.getInstance().push(sessionId, message);
513+
514+
return "Notification sent";
515+
}
516+
```
517+
518+
## Model Context Protocol (MCP) & AI
519+
520+
tinystruct is now AI-ready with built-in support for the Model Context Protocol (MCP). This allows your application to act as an MCP server or client, enabling seamless integration with AI models.
521+
522+
For more details, see the [AI & MCP Integration](mcp-integration.md) guide.
523+
482524
## Best Practices
483525

484526
1. **Separation of Concerns**: Keep your action methods focused on handling the request/response cycle, and delegate business logic to service classes.

index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<meta name="keywords" content="java, framework, lightweight, command-line, web, applications, tinystruct">
1010
<meta name="author" content="James ZHOU">
1111
<link rel="icon" type="image/x-icon" href="favicon.ico">
12-
<title>tinystruct framework - v1.7.18</title>
12+
<title>tinystruct framework - v1.7.21</title>
1313

1414
<!-- Styles -->
1515
<link rel="stylesheet" href="assets/css/style.css">
@@ -82,7 +82,7 @@
8282
<button class="menu-toggle" onclick="toggleSidebar()">
8383
<ion-icon name="menu-outline"></ion-icon>
8484
</button>
85-
<div class="version-badge">v1.7.18</div>
85+
<div class="version-badge">v1.7.21</div>
8686
</div>
8787
<div class="header-actions">
8888
<button class="lang-switch" title="Switch Language" onclick="toggleLanguage()">
@@ -438,7 +438,7 @@ <h4>Zero Configuration</h4>
438438
const commands = [
439439
"$ bin/dispatcher --version",
440440
" _/ ' _ _/ _ _ _/",
441-
" / / /) (/ _) / / (/ ( / 1.7.19",
441+
" / / /) (/ _) / / (/ ( / 1.7.21",
442442
" /",
443443
" ",
444444
"$ bin/dispatcher --help",
@@ -472,7 +472,7 @@ <h4>Zero Configuration</h4>
472472
"# bin/dispatcher start --import org.tinystruct.system.NettyHttpServer --server-port 777",
473473
" ",
474474
" _/ ' _ _/ _ _ _/",
475-
" / / /) (/ _) / / (/ ( / 1.7.19",
475+
" / / /) (/ _) / / (/ ( / 1.7.21",
476476
" /",
477477
" ",
478478
`${new Date().toLocaleString()} org.tinystruct.system.NettyHttpServer start`,

0 commit comments

Comments
 (0)