@andrewcaires/api 5.6.0 → 5.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -73,86 +73,13 @@ const main = async () => {
73
73
  ]
74
74
  );
75
75
 
76
- await app.run();
76
+ await app.listen();
77
77
 
78
78
  };
79
79
 
80
80
  main().catch(console.log);
81
81
  ```
82
82
 
83
- ## Workers
84
-
85
- Use `@Worker` em um metodo de controller carregado pela aplicação e inicie o processo com `app.run()`. Sem `--worker`, `app.run()` inicia a API normalmente; com `--worker`, ele prepara banco, migrations e `sync()` dos controllers, executa o worker e nao abre a porta HTTP.
86
-
87
- ```ts
88
- import { BaseController, Worker } from "@andrewcaires/api";
89
-
90
- class ReportsController extends BaseController {
91
-
92
- @Worker("reports.daily")
93
- protected async daily() {
94
-
95
- return { ok: true };
96
- }
97
- }
98
- ```
99
-
100
- ```sh
101
- node dist/index.js --worker reports.daily
102
- ```
103
-
104
- ## MCP Streamable HTTP
105
-
106
- `McpController` exposes `/mcp` for MCP Streamable HTTP using protocol `2025-11-25` by default. Clients must call `initialize`, send `notifications/initialized`, and then include `MCP-Session-Id` and `MCP-Protocol-Version` on subsequent requests. The server also keeps compatibility with `2025-06-18` when that version is requested during initialization.
107
-
108
- The Streamable HTTP transport supports `POST` for JSON-RPC calls, `DELETE` to close a session, and `OPTIONS` for preflight. `GET` and `HEAD` return `405 Method Not Allowed`; the older HTTP+SSE transport is not implemented. Invalid JSON bodies return a JSON-RPC parse error (`-32700`) with `id: null`.
109
-
110
- Implemented MCP capabilities:
111
-
112
- - Tools via `@McpTool`, `tools/list`, and `tools/call`.
113
- - Tool input and output schemas generated from `@andrewcaires/utils.js` validations.
114
- - Tool input validation failures return a `tools/call` result with `isError: true`; protocol errors such as invalid sessions or missing tool names still return JSON-RPC errors.
115
-
116
- Not implemented by this package: resources, prompts, elicitation, sampling, OAuth authorization endpoints, tasks, and SSE streaming.
117
-
118
- Configuration:
119
-
120
- ```env
121
- MCP_ALLOWED_ORIGINS=https://app.example.com
122
- MCP_RATE_LIMIT_MAX=120
123
- MCP_RATE_LIMIT_WINDOW=1m
124
- MCP_SESSION_TTL=30m
125
- ```
126
-
127
- Tools can be declared from any loaded controller:
128
-
129
- ```ts
130
- import { Validation } from "@andrewcaires/utils.js";
131
- import { McpTool } from "@andrewcaires/api";
132
-
133
- class UsersController {
134
-
135
- @McpTool({
136
- name: "users.search",
137
- title: "Search users",
138
- description: "Searches users by text.",
139
- input: {
140
- q: Validation.string().required().description("Search text."),
141
- active: Validation.boolean().parse().empty(false).description("Filter only active users."),
142
- },
143
- output: {
144
- total: Validation.number().required().description("Total matched users."),
145
- },
146
- })
147
- protected async searchUsers(args, context) {
148
-
149
- return {
150
- total: 0,
151
- };
152
- }
153
- }
154
- ```
155
-
156
83
  ### Links
157
84
 
158
85
  * [Docs](https://www.npmjs.com/package/@andrewcaires/api)