@@ -19,6 +19,7 @@ export abstract class BaseTool<TParams = Record<string, unknown>, TResult = unkn
1919```
2020
2121** Benefits:**
22+
2223- ✅ Full TypeScript IntelliSense
2324- ✅ Automatic parameter validation
2425- ✅ Type-safe result formatting
@@ -36,14 +37,15 @@ Advanced decorators with automatic categorization and metadata:
3637 description: ' Retrieve entity data' ,
3738 paramsSchema: entitySchema ,
3839 cacheable: true ,
39- tags: [' entity' , ' read' ]
40+ tags: [' entity' , ' read' ],
4041})
4142export class GetEntityTool extends BaseTool <EntityParams , Entity > {
4243 // Fully type-safe implementation
4344}
4445```
4546
4647** Decorator Types:**
48+
4749- ` @ReadTool ` - GET operations with caching
4850- ` @WriteTool ` - POST/PUT with confirmation
4951- ` @AuthenticatedTool ` - Requires authentication
@@ -57,19 +59,15 @@ Different execution strategies for various scenarios:
5759
5860``` typescript
5961// Standard execution
60- const standardTool = ToolFactory .create ()
61- .withStrategy (new StandardExecutionStrategy ())
62- .build ();
62+ const standardTool = ToolFactory .create ().withStrategy (new StandardExecutionStrategy ()).build ();
6363
6464// Cached execution
6565const cachedTool = ToolFactory .create ()
6666 .withStrategy (new CachedExecutionStrategy (5 * 60 * 1000 )) // 5 min TTL
6767 .build ();
6868
6969// Batched execution
70- const batchTool = ToolFactory .create ()
71- .withStrategy (new BatchedExecutionStrategy ())
72- .build ();
70+ const batchTool = ToolFactory .create ().withStrategy (new BatchedExecutionStrategy ()).build ();
7371```
7472
7573### 4. Middleware Pipeline Pattern
@@ -79,15 +77,15 @@ const batchTool = ToolFactory.create()
7977Extensible middleware system for cross-cutting concerns:
8078
8179``` typescript
82- export const AuthenticatedTool = ToolFactory
83- .create ()
80+ export const AuthenticatedTool = ToolFactory .create ()
8481 .use (new AuthenticationMiddleware ())
8582 .use (new ValidationMiddleware ())
8683 .use (new LoggingMiddleware ())
8784 .build ();
8885```
8986
9087** Built-in Middleware:**
88+
9189- ` AuthenticationMiddleware ` - Handles auth requirements
9290- ` ValidationMiddleware ` - Input validation
9391- ` CachingMiddleware ` - Response caching
@@ -99,8 +97,7 @@ export const AuthenticatedTool = ToolFactory
9997Fluent API for tool creation and configuration:
10098
10199``` typescript
102- export const MyTool = ToolFactory
103- .createReadTool ()
100+ export const MyTool = ToolFactory .createReadTool ()
104101 .name (' my-tool' )
105102 .description (' A powerful tool' )
106103 .schema (mySchema )
@@ -171,8 +168,7 @@ export class GetEntityTool extends BaseTool<z.infer<typeof paramsSchema>, Entity
171168### Advanced Tool with Middleware and Strategy
172169
173170``` typescript
174- export const AdvancedTool = ToolFactory
175- .createWriteTool ()
171+ export const AdvancedTool = ToolFactory .createWriteTool ()
176172 .name (' advanced-tool' )
177173 .description (' Advanced tool with full feature set' )
178174 .schema (advancedSchema )
@@ -195,25 +191,21 @@ export class MetricsPlugin implements IMcpPlugin {
195191
196192 async initialize(context : IToolRegistrationContext ): Promise <void > {
197193 // Add metrics middleware to all tools
198- context .toolRegistrar .register (
199- ToolFactory .create ()
200- .use (new MetricsMiddleware ())
201- .build ()
202- );
194+ context .toolRegistrar .register (ToolFactory .create ().use (new MetricsMiddleware ()).build ());
203195 }
204196}
205197```
206198
207199## 📊 Benefits Achieved
208200
209- | Pattern | Benefit | Implementation |
210- | ---------| ---------| ----------------|
211- | ** Generics** | Type safety, IntelliSense | ` BaseTool<TParams, TResult> ` |
212- | ** Decorators** | Metadata, categorization | ` @ReadTool ` , ` @WriteTool ` |
213- | ** Strategy** | Execution flexibility | ` CachedExecutionStrategy ` |
214- | ** Middleware** | Cross-cutting concerns | Pipeline architecture |
215- | ** Builder** | Fluent configuration | ` ToolFactory.create() ` |
216- | ** Plugin** | Extensibility | ` PluginManager ` |
201+ | Pattern | Benefit | Implementation |
202+ | -------------- | ------------------------- | ---------------------------- |
203+ | ** Generics** | Type safety, IntelliSense | ` BaseTool<TParams, TResult> ` |
204+ | ** Decorators** | Metadata, categorization | ` @ReadTool ` , ` @WriteTool ` |
205+ | ** Strategy** | Execution flexibility | ` CachedExecutionStrategy ` |
206+ | ** Middleware** | Cross-cutting concerns | Pipeline architecture |
207+ | ** Builder** | Fluent configuration | ` ToolFactory.create() ` |
208+ | ** Plugin** | Extensibility | ` PluginManager ` |
217209
218210## 🔄 Migration Guide
219211
@@ -244,11 +236,10 @@ export class ModernTool extends BaseTool<LegacyParams, LegacyResult> {
244236``` typescript
245237import { ToolMigrationHelper } from ' ./utils/tools/migration-helper.js' ;
246238
247- const modernTool = ToolMigrationHelper .migrateLegacyTool (
248- LegacyTool ,
249- legacyMetadata ,
250- { addCaching: true , addValidation: true }
251- );
239+ const modernTool = ToolMigrationHelper .migrateLegacyTool (LegacyTool , legacyMetadata , {
240+ addCaching: true ,
241+ addValidation: true ,
242+ });
252243```
253244
254245## 🎯 Best Practices
@@ -290,9 +281,7 @@ pluginManager.register(new MetricsPlugin());
290281pluginManager .register (new SecurityPlugin ());
291282
292283// Use advanced tool factory
293- const advancedTool = ToolFactory .createReadTool ()
294- .withStrategy (new CachedExecutionStrategy ())
295- .build ();
284+ const advancedTool = ToolFactory .createReadTool ().withStrategy (new CachedExecutionStrategy ()).build ();
296285```
297286
298- This implementation provides a solid foundation for scalable, maintainable, and extensible MCP server development with modern TypeScript patterns.
287+ This implementation provides a solid foundation for scalable, maintainable, and extensible MCP server development with modern TypeScript patterns.
0 commit comments