You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+71-39Lines changed: 71 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,9 @@
28
28
This extension provides a plug-and-play integration between LoopBack4 applications and the Model Context Protocol (MCP) specification.
29
29
30
30
Its purpose is to enable LoopBack APIs, services, and business logic to be exposed as MCP Tools, allowing external MCP clients (such as LLMs, agents, or MCP-compatible apps) to discover and execute server-defined operations.
31
+
31
32
### Key Features
33
+
32
34
- Automatic MCP Tool Discovery :-
33
35
The extension scans your application at boot time and automatically registers all methods decorated with the custom @mcpTool() decorator.
34
36
@@ -38,16 +40,35 @@ Its purpose is to enable LoopBack APIs, services, and business logic to be expos
38
40
A dedicated `McpToolRegistry` service maintains all discovered tool metadata,their handlers and execution context.
39
41
40
42
A `McpToolRegistryBootObserver` ensures that registration happens only after the application has fully booted.
43
+
41
44
## Installation
45
+
42
46
```sh
43
47
npm install loopback4-mcp
44
48
```
45
-
Then register the component inside your `application.ts`.
49
+
50
+
## Basic Usage
51
+
52
+
Configure and load `McpComponent` in the application constructor
53
+
as shown below.
54
+
46
55
```ts
47
-
this.component(McpComponent);
56
+
import {McpComponent} from'loopback4-mcp';
57
+
58
+
exportclassMyApplicationextendsBootMixin(
59
+
ServiceMixin(RepositoryMixin(RestApplication)),
60
+
) {
61
+
constructor(options:ApplicationConfig= {}) {
62
+
super();
63
+
this.component(McpComponent);
64
+
}
65
+
}
48
66
```
49
-
## Usage
67
+
50
68
Add the `@mcpTool()` decorator to any controller in your application.
69
+
70
+
All MCP tool methods must use LoopBack `@param` decorators to define their input parameters.If `@param` decorators are missing, the MCP tool will fail.
71
+
51
72
```ts
52
73
@mcpTool({
53
74
name: 'create-user',
@@ -57,47 +78,58 @@ Add the `@mcpTool()` decorator to any controller in your application.
This decorator accepts a total of five fields, out of which `name` and `description` are mandatory and `schema`,`preHook` and `postHook` are optional enhancements.
66
90
67
91
The schema field allows defining a Zod-based validation schema for tool input parameters, while preHook and postHook enable execution of custom logic before and after the tool handler runs.
68
92
69
-
### Mcp Hook Usage Details
70
-
To use hooks with MCP tools, follow the provider-based approach:
0 commit comments