@jrmc/adonis-mcp 1.0.0-alpha.9 → 1.0.0-beta.2
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 +811 -26
- package/build/commands/commands.json +1 -1
- package/build/commands/inspector.d.ts +16 -0
- package/build/commands/inspector.d.ts.map +1 -0
- package/build/commands/inspector.js +54 -0
- package/build/commands/make/prompt.d.ts +16 -0
- package/build/commands/make/prompt.d.ts.map +1 -0
- package/build/commands/make/prompt.js +33 -0
- package/build/commands/make/resource.d.ts +16 -0
- package/build/commands/make/resource.d.ts.map +1 -0
- package/build/commands/make/resource.js +33 -0
- package/build/commands/make/tool.d.ts.map +1 -1
- package/build/commands/make/tool.js +0 -2
- package/build/configure.d.ts.map +1 -1
- package/build/configure.js +7 -0
- package/build/index.d.ts +2 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -0
- package/build/providers/mcp_provider.d.ts +3 -0
- package/build/providers/mcp_provider.d.ts.map +1 -1
- package/build/providers/mcp_provider.js +35 -12
- package/build/src/define_config.d.ts.map +1 -1
- package/build/src/define_config.js +0 -3
- package/build/src/enums/error.d.ts.map +1 -1
- package/build/src/enums/error.js +0 -1
- package/build/src/request.d.ts +1 -1
- package/build/src/response.d.ts +24 -23
- package/build/src/response.d.ts.map +1 -1
- package/build/src/response.js +49 -13
- package/build/src/server/annotations/annotations.d.ts +10 -0
- package/build/src/server/annotations/annotations.d.ts.map +1 -0
- package/build/src/server/annotations/annotations.js +9 -0
- package/build/src/server/annotations/audience.d.ts +22 -0
- package/build/src/server/annotations/audience.d.ts.map +1 -0
- package/build/src/server/annotations/audience.js +28 -0
- package/build/src/server/annotations/is_destructive.d.ts +17 -0
- package/build/src/server/annotations/is_destructive.d.ts.map +1 -0
- package/build/src/server/annotations/is_destructive.js +24 -0
- package/build/src/server/annotations/is_idempotent.d.ts +17 -0
- package/build/src/server/annotations/is_idempotent.d.ts.map +1 -0
- package/build/src/server/annotations/is_idempotent.js +24 -0
- package/build/src/server/annotations/is_open_world.d.ts +17 -0
- package/build/src/server/annotations/is_open_world.d.ts.map +1 -0
- package/build/src/server/annotations/is_open_world.js +24 -0
- package/build/src/server/annotations/is_read_only.d.ts +17 -0
- package/build/src/server/annotations/is_read_only.d.ts.map +1 -0
- package/build/src/server/annotations/is_read_only.js +24 -0
- package/build/src/server/annotations/last_modified.d.ts +21 -0
- package/build/src/server/annotations/last_modified.d.ts.map +1 -0
- package/build/src/server/annotations/last_modified.js +28 -0
- package/build/src/server/annotations/priority.d.ts +21 -0
- package/build/src/server/annotations/priority.d.ts.map +1 -0
- package/build/src/server/annotations/priority.js +31 -0
- package/build/src/server/annotations/tool_annotations.d.ts +11 -0
- package/build/src/server/annotations/tool_annotations.d.ts.map +1 -0
- package/build/src/server/annotations/tool_annotations.js +10 -0
- package/build/src/server/contents/audio.d.ts +24 -0
- package/build/src/server/contents/audio.d.ts.map +1 -0
- package/build/src/server/contents/audio.js +57 -0
- package/build/src/server/contents/blob.d.ts +20 -0
- package/build/src/server/contents/blob.d.ts.map +1 -0
- package/build/src/server/contents/blob.js +42 -0
- package/build/src/server/contents/embedded_resource.d.ts +25 -0
- package/build/src/server/contents/embedded_resource.d.ts.map +1 -0
- package/build/src/server/contents/embedded_resource.js +72 -0
- package/build/src/server/contents/error.d.ts +15 -0
- package/build/src/server/contents/error.d.ts.map +1 -0
- package/build/src/server/contents/error.js +16 -0
- package/build/src/server/contents/image.d.ts +24 -0
- package/build/src/server/contents/image.d.ts.map +1 -0
- package/build/src/server/contents/image.js +57 -0
- package/build/src/server/contents/resource_link.d.ts +22 -0
- package/build/src/server/contents/resource_link.d.ts.map +1 -0
- package/build/src/server/contents/resource_link.js +55 -0
- package/build/src/server/contents/structured.d.ts +20 -0
- package/build/src/server/contents/structured.d.ts.map +1 -0
- package/build/src/server/contents/structured.js +26 -0
- package/build/src/server/contents/text.d.ts +24 -0
- package/build/src/server/contents/text.d.ts.map +1 -0
- package/build/src/server/contents/text.js +61 -0
- package/build/src/server/context.d.ts +11 -6
- package/build/src/server/context.d.ts.map +1 -1
- package/build/src/server/context.js +30 -2
- package/build/src/server/contracts/content.d.ts +16 -0
- package/build/src/server/contracts/content.d.ts.map +1 -0
- package/build/src/server/contracts/content.js +8 -0
- package/build/src/server/contracts/context.d.ts +29 -0
- package/build/src/server/contracts/context.d.ts.map +1 -0
- package/build/src/server/contracts/response.d.ts +26 -0
- package/build/src/server/contracts/response.d.ts.map +1 -0
- package/build/src/{types → server/contracts}/transport.d.ts +2 -2
- package/build/src/server/contracts/transport.d.ts.map +1 -0
- package/build/src/server/contracts/transport.js +7 -0
- package/build/src/server/controllers/mcp_controller.d.ts.map +1 -1
- package/build/src/server/controllers/mcp_controller.js +0 -3
- package/build/src/server/exceptions/jsonrpc_exception.d.ts +6 -5
- package/build/src/server/exceptions/jsonrpc_exception.d.ts.map +1 -1
- package/build/src/server/exceptions/jsonrpc_exception.js +18 -9
- package/build/src/server/methods/call_tool.d.ts +2 -2
- package/build/src/server/methods/call_tool.d.ts.map +1 -1
- package/build/src/server/methods/call_tool.js +42 -17
- package/build/src/server/methods/completion.d.ts +12 -0
- package/build/src/server/methods/completion.d.ts.map +1 -0
- package/build/src/server/methods/completion.js +45 -0
- package/build/src/server/methods/get_prompt.d.ts +2 -2
- package/build/src/server/methods/get_prompt.d.ts.map +1 -1
- package/build/src/server/methods/get_prompt.js +55 -2
- package/build/src/server/methods/initialize.d.ts +2 -2
- package/build/src/server/methods/initialize.d.ts.map +1 -1
- package/build/src/server/methods/initialize.js +4 -1
- package/build/src/server/methods/list_prompts.d.ts +2 -2
- package/build/src/server/methods/list_prompts.d.ts.map +1 -1
- package/build/src/server/methods/list_prompts.js +24 -3
- package/build/src/server/methods/list_resource_templates.d.ts +12 -0
- package/build/src/server/methods/list_resource_templates.d.ts.map +1 -0
- package/build/src/server/methods/list_resource_templates.js +34 -0
- package/build/src/server/methods/list_resources.d.ts +2 -2
- package/build/src/server/methods/list_resources.d.ts.map +1 -1
- package/build/src/server/methods/list_resources.js +24 -3
- package/build/src/server/methods/list_tools.d.ts +2 -2
- package/build/src/server/methods/list_tools.d.ts.map +1 -1
- package/build/src/server/methods/list_tools.js +5 -17
- package/build/src/server/methods/ping.d.ts +2 -2
- package/build/src/server/methods/ping.d.ts.map +1 -1
- package/build/src/server/methods/ping.js +1 -1
- package/build/src/server/methods/read_resource.d.ts +2 -2
- package/build/src/server/methods/read_resource.d.ts.map +1 -1
- package/build/src/server/methods/read_resource.js +20 -2
- package/build/src/server/pagination/cursor_paginator.d.ts +2 -4
- package/build/src/server/pagination/cursor_paginator.d.ts.map +1 -1
- package/build/src/server/pagination/cursor_paginator.js +11 -11
- package/build/src/server/prompt.d.ts +27 -0
- package/build/src/server/prompt.d.ts.map +1 -0
- package/build/src/server/prompt.js +32 -0
- package/build/src/server/resource.d.ts +23 -0
- package/build/src/server/resource.d.ts.map +1 -0
- package/build/src/server/resource.js +40 -0
- package/build/src/server/tool.d.ts +19 -9
- package/build/src/server/tool.d.ts.map +1 -1
- package/build/src/server/tool.js +21 -0
- package/build/src/server/transports/fake_transport.d.ts +19 -1
- package/build/src/server/transports/fake_transport.d.ts.map +1 -1
- package/build/src/server/transports/fake_transport.js +28 -1
- package/build/src/server/transports/http_transport.d.ts +4 -3
- package/build/src/server/transports/http_transport.d.ts.map +1 -1
- package/build/src/server/transports/http_transport.js +14 -9
- package/build/src/server/transports/stdio_transport.d.ts +2 -2
- package/build/src/server/transports/stdio_transport.d.ts.map +1 -1
- package/build/src/server/transports/stdio_transport.js +0 -3
- package/build/src/server.d.ts +4 -3
- package/build/src/server.d.ts.map +1 -1
- package/build/src/server.js +15 -9
- package/build/src/types/config.d.ts +1 -0
- package/build/src/types/config.d.ts.map +1 -1
- package/build/src/types/content.d.ts +35 -0
- package/build/src/types/content.d.ts.map +1 -0
- package/build/src/types/content.js +7 -0
- package/build/src/types/context.d.ts +30 -18
- package/build/src/types/context.d.ts.map +1 -1
- package/build/src/types/jsonrpc.d.ts +406 -0
- package/build/src/types/jsonrpc.d.ts.map +1 -0
- package/build/src/types/jsonrpc.js +7 -0
- package/build/src/types/request.d.ts +3 -37
- package/build/src/types/request.d.ts.map +1 -1
- package/build/src/types/response.d.ts +10 -39
- package/build/src/types/response.d.ts.map +1 -1
- package/build/src/utils/find_resource_pattern.d.ts +19 -0
- package/build/src/utils/find_resource_pattern.d.ts.map +1 -0
- package/build/src/utils/find_resource_pattern.js +35 -0
- package/build/src/utils/stdio.d.ts +2 -3
- package/build/src/utils/stdio.d.ts.map +1 -1
- package/build/src/utils/stdio.js +7 -7
- package/build/src/utils/uri_template.d.ts +25 -0
- package/build/src/utils/uri_template.d.ts.map +1 -0
- package/build/src/utils/uri_template.js +241 -0
- package/build/stubs/config.ts.stub +0 -1
- package/build/stubs/make/mcp/prompts/main.ts.stub +32 -16
- package/build/stubs/make/mcp/resources/main.ts.stub +13 -19
- package/build/stubs/make/mcp/tools/main.ts.stub +11 -13
- package/build/stubs/make/middleware/mcp_middleware.ts.stub +48 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -4
- package/build/src/types/notification.d.ts +0 -14
- package/build/src/types/notification.d.ts.map +0 -1
- package/build/src/types/transport.d.ts.map +0 -1
- /package/build/src/{types/notification.js → server/contracts/context.js} +0 -0
- /package/build/src/{types/transport.js → server/contracts/response.js} +0 -0
package/README.md
CHANGED
|
@@ -5,14 +5,37 @@
|
|
|
5
5
|
|
|
6
6
|
AdonisJS MCP - Server MCP for your AdonisJS applications.
|
|
7
7
|
|
|
8
|
+
> **Note:** This documentation has been generated by AI and has not been fully verified yet. Please report any inaccuracies or issues you encounter.
|
|
9
|
+
|
|
10
|
+
## Links
|
|
11
|
+
|
|
12
|
+
[View documentation](https://adonis-mcp.jrmc.dev/)
|
|
13
|
+
|
|
8
14
|
## Roadmap
|
|
9
15
|
|
|
16
|
+
- [x] MCP tools support
|
|
17
|
+
- [x] MCP resources support
|
|
10
18
|
- [x] MCP prompts support
|
|
11
|
-
- [
|
|
12
|
-
- [
|
|
13
|
-
- [
|
|
19
|
+
- [x] HTTP transport
|
|
20
|
+
- [x] Stdio transport
|
|
21
|
+
- [x] Fake transport (for testing)
|
|
14
22
|
- [x] Advanced pagination support
|
|
15
|
-
- [
|
|
23
|
+
- [x] Meta support
|
|
24
|
+
- [x] Annotations
|
|
25
|
+
- [x] Completion
|
|
26
|
+
- [x] Inspector
|
|
27
|
+
- [x] Session
|
|
28
|
+
- [x] Documentation
|
|
29
|
+
- [ ] Output tool
|
|
30
|
+
- [ ] Vine integration
|
|
31
|
+
- [ ] Bounce integration (WIP)
|
|
32
|
+
- [ ] Auth helpers (WIP)
|
|
33
|
+
- [ ] Inject support
|
|
34
|
+
- [ ] Alternative transports (SSE)
|
|
35
|
+
- [ ] JSON Schema with Vine ???
|
|
36
|
+
- [ ] Login flow
|
|
37
|
+
- [ ] Starter kit
|
|
38
|
+
- [ ] Demo applications
|
|
16
39
|
|
|
17
40
|
## Installation & Configuration
|
|
18
41
|
|
|
@@ -28,10 +51,17 @@ import { defineConfig } from '@jrmc/adonis-mcp'
|
|
|
28
51
|
export default defineConfig({
|
|
29
52
|
name: 'adonis-mcp-server',
|
|
30
53
|
version: '1.0.0',
|
|
31
|
-
path: 'app/mcp', // Path where your tools will be stored
|
|
32
54
|
})
|
|
33
55
|
```
|
|
34
56
|
|
|
57
|
+
By default, your MCP tools, resources, and prompts will be stored in `app/mcp`. If you want to use a different path, you need to configure it in your `adonisrc.ts` file:
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
directories: {
|
|
61
|
+
mcp: 'app/custom/mcp', // Optional: custom path for MCP files (defaults to 'app/mcp')
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
35
65
|
## Usage
|
|
36
66
|
|
|
37
67
|
### Creating a Tool
|
|
@@ -45,8 +75,8 @@ node ace make:mcp-tool my_tool
|
|
|
45
75
|
This command will create a file in `app/mcp/tools/my_tool.ts` with a base template:
|
|
46
76
|
|
|
47
77
|
```typescript
|
|
48
|
-
import type {
|
|
49
|
-
import type { BaseSchema
|
|
78
|
+
import type { ToolContext } from '@jrmc/adonis-mcp/types/context'
|
|
79
|
+
import type { BaseSchema } from '@jrmc/adonis-mcp/types/method'
|
|
50
80
|
|
|
51
81
|
import { Tool } from '@jrmc/adonis-mcp'
|
|
52
82
|
|
|
@@ -54,15 +84,14 @@ type Schema = BaseSchema<{
|
|
|
54
84
|
text: { type: "string" }
|
|
55
85
|
}>
|
|
56
86
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
export default class MyToolTool implements Tool<Schema> {
|
|
87
|
+
export default class MyToolTool extends Tool<Schema> {
|
|
60
88
|
name = 'tool_name'
|
|
61
89
|
title = 'Tool title'
|
|
62
90
|
description = 'Tool description'
|
|
63
91
|
|
|
64
|
-
async handle({ args }:
|
|
92
|
+
async handle({ args, response }: ToolContext<Schema>) {
|
|
65
93
|
console.log(args.text)
|
|
94
|
+
return response.text('Hello, world!')
|
|
66
95
|
}
|
|
67
96
|
|
|
68
97
|
schema() {
|
|
@@ -126,7 +155,7 @@ schema() {
|
|
|
126
155
|
The `handle` method contains your tool's logic. It receives a typed context with validated arguments:
|
|
127
156
|
|
|
128
157
|
```typescript
|
|
129
|
-
async handle({ args, response, auth, bouncer }:
|
|
158
|
+
async handle({ args, response, auth, bouncer }: ToolContext<Schema>) {
|
|
130
159
|
// Your logic here
|
|
131
160
|
const result = await SomeModel.query().where('id', args.id)
|
|
132
161
|
|
|
@@ -136,7 +165,7 @@ async handle({ args, response, auth, bouncer }: Context) {
|
|
|
136
165
|
|
|
137
166
|
### Setting up Authentication and Bouncer
|
|
138
167
|
|
|
139
|
-
To use `auth` and `bouncer` in your MCP tools, add the following TypeScript declaration in your middleware (e.g., in your
|
|
168
|
+
To use `auth` and `bouncer` in your MCP tools, prompts, and resources, add the following TypeScript declaration in your middleware (e.g., in your MCP middleware):
|
|
140
169
|
|
|
141
170
|
```typescript
|
|
142
171
|
declare module '@jrmc/adonis-mcp/types/context' {
|
|
@@ -173,12 +202,29 @@ You can also specify a custom path:
|
|
|
173
202
|
router.mcp('/custom-mcp-path').use(middleware.auth())
|
|
174
203
|
```
|
|
175
204
|
|
|
205
|
+
> **⚠️ Important: CSRF Protection**
|
|
206
|
+
>
|
|
207
|
+
> If you have CSRF protection enabled in your application, you **must** exclude the MCP route from CSRF validation. MCP clients typically don't include CSRF tokens in their requests.
|
|
208
|
+
>
|
|
209
|
+
> In your `config/shield.ts` file, add the MCP route to the CSRF exceptions:
|
|
210
|
+
>
|
|
211
|
+
> ```typescript
|
|
212
|
+
> export const shieldConfig = defineConfig({
|
|
213
|
+
> csrf: {
|
|
214
|
+
> enabled: true,
|
|
215
|
+
> exceptRoutes: [
|
|
216
|
+
> '/mcp', // Or your custom MCP path
|
|
217
|
+
> ],
|
|
218
|
+
> },
|
|
219
|
+
> })
|
|
220
|
+
> ```
|
|
221
|
+
|
|
176
222
|
### Using Authentication
|
|
177
223
|
|
|
178
224
|
The MCP context automatically includes the `auth` instance from the `HttpContext` if available. You can use it to access the authenticated user:
|
|
179
225
|
|
|
180
226
|
```typescript
|
|
181
|
-
async handle({ args, auth }:
|
|
227
|
+
async handle({ args, auth, response }: ToolContext<Schema>) {
|
|
182
228
|
const user = auth?.user
|
|
183
229
|
|
|
184
230
|
if (!user) {
|
|
@@ -200,7 +246,7 @@ async handle({ args, auth }: Context) {
|
|
|
200
246
|
The MCP context automatically includes the `bouncer` instance from the `HttpContext` if available. You can use it to check permissions:
|
|
201
247
|
|
|
202
248
|
```typescript
|
|
203
|
-
async handle({ args, bouncer }:
|
|
249
|
+
async handle({ args, bouncer, response }: ToolContext<Schema>) {
|
|
204
250
|
// Check a permission
|
|
205
251
|
await bouncer.authorize('viewUsers')
|
|
206
252
|
|
|
@@ -214,13 +260,55 @@ async handle({ args, bouncer }: Context) {
|
|
|
214
260
|
|
|
215
261
|
### Response Return
|
|
216
262
|
|
|
217
|
-
The context includes a `response` instance to format your responses. The
|
|
263
|
+
The context includes a `response` instance to format your responses. The available methods depend on the context type:
|
|
264
|
+
|
|
265
|
+
#### Tool Responses
|
|
266
|
+
|
|
267
|
+
For tools, you can use:
|
|
268
|
+
|
|
269
|
+
- `response.text(text: string)`: Return plain text content
|
|
270
|
+
- `response.image(data: string, mimeType: string)`: Return image content (base64 encoded)
|
|
271
|
+
- `response.audio(data: string, mimeType: string)`: Return audio content (base64 encoded)
|
|
272
|
+
- `response.structured(object: Record<string, unknown>)`: Return structured JSON data
|
|
273
|
+
- `response.resourceLink(uri: string)`: Return a link to a resource
|
|
274
|
+
- `response.error(message: string)`: Return an error message
|
|
275
|
+
- `response.send(content: Content | Content[])`: Send custom content objects
|
|
218
276
|
|
|
219
277
|
```typescript
|
|
220
|
-
async handle({ args, response }:
|
|
221
|
-
|
|
278
|
+
async handle({ args, response }: ToolContext<Schema>) {
|
|
279
|
+
// Return text
|
|
280
|
+
return response.text(JSON.stringify({ success: true }))
|
|
281
|
+
|
|
282
|
+
// Return structured data
|
|
283
|
+
return response.structured({
|
|
284
|
+
temperature: 22.5,
|
|
285
|
+
conditions: 'Partly cloudy',
|
|
286
|
+
humidity: 65
|
|
287
|
+
})
|
|
222
288
|
|
|
223
|
-
|
|
289
|
+
// Return image
|
|
290
|
+
const imageData = await fs.readFile('path/to/image.png', 'base64')
|
|
291
|
+
return response.image(imageData, 'image/png')
|
|
292
|
+
|
|
293
|
+
// Return a resource link
|
|
294
|
+
return response.resourceLink('file:///path/to/resource.txt')
|
|
295
|
+
|
|
296
|
+
// Return error
|
|
297
|
+
return response.error('Something went wrong')
|
|
298
|
+
}
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
#### Resource Responses
|
|
302
|
+
|
|
303
|
+
For resources, you can use:
|
|
304
|
+
|
|
305
|
+
- `response.text(text: string)`: Return text content
|
|
306
|
+
- `response.blob(text: string)`: Return binary content (base64 encoded)
|
|
307
|
+
|
|
308
|
+
```typescript
|
|
309
|
+
async handle({ response }: ResourceContext) {
|
|
310
|
+
const content = await fs.readFile('path/to/file.txt', 'utf-8')
|
|
311
|
+
return response.text(content)
|
|
224
312
|
}
|
|
225
313
|
```
|
|
226
314
|
|
|
@@ -229,8 +317,8 @@ async handle({ args, response }: Context) {
|
|
|
229
317
|
Here is a complete example of a tool that creates a bookmark:
|
|
230
318
|
|
|
231
319
|
```typescript
|
|
232
|
-
import type {
|
|
233
|
-
import type { BaseSchema
|
|
320
|
+
import type { ToolContext } from '@jrmc/adonis-mcp/types/context'
|
|
321
|
+
import type { BaseSchema } from '@jrmc/adonis-mcp/types/method'
|
|
234
322
|
|
|
235
323
|
import { Tool } from '@jrmc/adonis-mcp'
|
|
236
324
|
import Bookmark from '#models/bookmark'
|
|
@@ -240,14 +328,12 @@ type Schema = BaseSchema<{
|
|
|
240
328
|
url: { type: "string" }
|
|
241
329
|
}>
|
|
242
330
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
export default class AddBookmarkTool implements Tool<Schema> {
|
|
331
|
+
export default class AddBookmarkTool extends Tool<Schema> {
|
|
246
332
|
name = 'create_bookmark'
|
|
247
333
|
title = 'Create Bookmark'
|
|
248
334
|
description = 'Create a new bookmark'
|
|
249
335
|
|
|
250
|
-
async handle({ args, response, auth }:
|
|
336
|
+
async handle({ args, response, auth }: ToolContext<Schema>) {
|
|
251
337
|
const bookmark = await Bookmark.create({
|
|
252
338
|
title: args.title,
|
|
253
339
|
text: args.url,
|
|
@@ -276,9 +362,708 @@ export default class AddBookmarkTool implements Tool<Schema> {
|
|
|
276
362
|
}
|
|
277
363
|
```
|
|
278
364
|
|
|
365
|
+
## Advanced Features
|
|
366
|
+
|
|
367
|
+
### Structured Output
|
|
368
|
+
|
|
369
|
+
The `response.structured()` method allows you to return JSON data in a structured format. This is particularly useful when you want to return data that can be easily parsed and used by the MCP client without additional processing:
|
|
370
|
+
|
|
371
|
+
```typescript
|
|
372
|
+
import type { ToolContext } from '@jrmc/adonis-mcp/types/context'
|
|
373
|
+
import { Tool } from '@jrmc/adonis-mcp'
|
|
374
|
+
|
|
375
|
+
export default class GetWeatherTool extends Tool {
|
|
376
|
+
name = 'get_weather'
|
|
377
|
+
title = 'Get Weather'
|
|
378
|
+
description = 'Get current weather data'
|
|
379
|
+
|
|
380
|
+
async handle({ args, response }: ToolContext) {
|
|
381
|
+
const weatherData = {
|
|
382
|
+
temperature: 22.5,
|
|
383
|
+
conditions: 'Partly cloudy',
|
|
384
|
+
humidity: 65,
|
|
385
|
+
windSpeed: 12,
|
|
386
|
+
location: args.location
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
return response.structured(weatherData)
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
**Note:** Structured content can only be used in tools, not in prompts or resources.
|
|
395
|
+
|
|
396
|
+
### Resource Links
|
|
397
|
+
|
|
398
|
+
Resource links allow you to reference other resources in your tool responses. This is useful when you want to point to additional information without embedding the entire resource content:
|
|
399
|
+
|
|
400
|
+
```typescript
|
|
401
|
+
import type { ToolContext } from '@jrmc/adonis-mcp/types/context'
|
|
402
|
+
import { Tool } from '@jrmc/adonis-mcp'
|
|
403
|
+
|
|
404
|
+
export default class GetDocumentationTool extends Tool {
|
|
405
|
+
name = 'get_documentation'
|
|
406
|
+
title = 'Get Documentation'
|
|
407
|
+
description = 'Get documentation for a specific topic'
|
|
408
|
+
|
|
409
|
+
async handle({ args, response }: ToolContext) {
|
|
410
|
+
return [
|
|
411
|
+
response.text('Here is the documentation for your topic:'),
|
|
412
|
+
response.resourceLink(`file:///docs/${args.topic}.md`)
|
|
413
|
+
]
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
The resource link will include metadata about the resource (name, mimeType, title, description, size) without fetching the actual content. The MCP client can then decide whether to fetch the resource content separately.
|
|
419
|
+
|
|
420
|
+
**Note:** Resource links can only be used in tools, not in prompts or resources.
|
|
421
|
+
|
|
422
|
+
### Metadata with `withMeta()`
|
|
423
|
+
|
|
424
|
+
The `withMeta()` method is available on all content types and allows you to attach custom metadata to your responses. This metadata can be used by MCP clients for various purposes such as logging, analytics, or custom processing:
|
|
425
|
+
|
|
426
|
+
```typescript
|
|
427
|
+
async handle({ args, response }: ToolContext<Schema>) {
|
|
428
|
+
const users = await User.all()
|
|
429
|
+
|
|
430
|
+
return response.text(JSON.stringify(users)).withMeta({
|
|
431
|
+
source: 'database',
|
|
432
|
+
queryTime: Date.now(),
|
|
433
|
+
count: users.length,
|
|
434
|
+
cacheHit: false
|
|
435
|
+
})
|
|
436
|
+
}
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
Metadata is particularly useful when:
|
|
440
|
+
- You want to provide debugging information
|
|
441
|
+
- You need to track the source of data
|
|
442
|
+
- You want to include performance metrics
|
|
443
|
+
- You need to pass additional context to the client
|
|
444
|
+
|
|
445
|
+
### Annotations
|
|
446
|
+
|
|
447
|
+
Annotations allow you to provide additional metadata about your tools and resources to help MCP clients better understand their behavior and characteristics.
|
|
448
|
+
|
|
449
|
+
#### Tool Annotations
|
|
450
|
+
|
|
451
|
+
Tools support the following annotations that describe their operational characteristics:
|
|
452
|
+
|
|
453
|
+
##### `@isReadOnly()`
|
|
454
|
+
|
|
455
|
+
Indicates that a tool only reads data and does not modify any state:
|
|
456
|
+
|
|
457
|
+
```typescript
|
|
458
|
+
import { Tool } from '@jrmc/adonis-mcp'
|
|
459
|
+
import { isReadOnly } from '@jrmc/adonis-mcp/tool_annotations'
|
|
460
|
+
|
|
461
|
+
@isReadOnly()
|
|
462
|
+
export default class GetUserTool extends Tool {
|
|
463
|
+
name = 'get_user'
|
|
464
|
+
|
|
465
|
+
async handle({ args, response }: ToolContext) {
|
|
466
|
+
const user = await User.find(args.id)
|
|
467
|
+
return response.text(JSON.stringify(user))
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
You can also explicitly set it to false:
|
|
473
|
+
|
|
474
|
+
```typescript
|
|
475
|
+
@isReadOnly(false)
|
|
476
|
+
export default class UpdateUserTool extends Tool {
|
|
477
|
+
// ...
|
|
478
|
+
}
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
##### `@isOpenWorld()`
|
|
482
|
+
|
|
483
|
+
Indicates that a tool can access information from the internet or external sources:
|
|
484
|
+
|
|
485
|
+
```typescript
|
|
486
|
+
import { isOpenWorld } from '@jrmc/adonis-mcp/tool_annotations'
|
|
487
|
+
|
|
488
|
+
@isOpenWorld()
|
|
489
|
+
export default class FetchWeatherTool extends Tool {
|
|
490
|
+
name = 'fetch_weather'
|
|
491
|
+
|
|
492
|
+
async handle({ args, response }: ToolContext) {
|
|
493
|
+
const weather = await externalApi.getWeather(args.city)
|
|
494
|
+
return response.text(JSON.stringify(weather))
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
##### `@isDestructive()`
|
|
500
|
+
|
|
501
|
+
Indicates that a tool performs destructive operations like deleting data:
|
|
502
|
+
|
|
503
|
+
```typescript
|
|
504
|
+
import { isDestructive } from '@jrmc/adonis-mcp/tool_annotations'
|
|
505
|
+
|
|
506
|
+
@isDestructive()
|
|
507
|
+
export default class DeleteUserTool extends Tool {
|
|
508
|
+
name = 'delete_user'
|
|
509
|
+
|
|
510
|
+
async handle({ args, response }: ToolContext) {
|
|
511
|
+
await User.query().where('id', args.id).delete()
|
|
512
|
+
return response.text('User deleted successfully')
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
##### `@isIdempotent()`
|
|
518
|
+
|
|
519
|
+
Indicates that a tool can be safely called multiple times with the same arguments without causing different effects:
|
|
520
|
+
|
|
521
|
+
```typescript
|
|
522
|
+
import { isIdempotent } from '@jrmc/adonis-mcp/tool_annotations'
|
|
523
|
+
|
|
524
|
+
@isIdempotent()
|
|
525
|
+
export default class SetUserStatusTool extends Tool {
|
|
526
|
+
name = 'set_user_status'
|
|
527
|
+
|
|
528
|
+
async handle({ args, response }: ToolContext) {
|
|
529
|
+
await User.query().where('id', args.id).update({ status: args.status })
|
|
530
|
+
return response.text('Status updated')
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
##### Combining Multiple Annotations
|
|
536
|
+
|
|
537
|
+
You can use multiple annotations on the same tool:
|
|
538
|
+
|
|
539
|
+
```typescript
|
|
540
|
+
import { isReadOnly, isOpenWorld, isIdempotent } from '@jrmc/adonis-mcp/tool_annotations'
|
|
541
|
+
|
|
542
|
+
@isReadOnly()
|
|
543
|
+
@isOpenWorld()
|
|
544
|
+
@isIdempotent()
|
|
545
|
+
export default class SearchOnlineTool extends Tool {
|
|
546
|
+
name = 'search_online'
|
|
547
|
+
|
|
548
|
+
async handle({ args, response }: ToolContext) {
|
|
549
|
+
const results = await searchEngine.search(args.query)
|
|
550
|
+
return response.text(JSON.stringify(results))
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
```
|
|
554
|
+
|
|
555
|
+
#### Resource Annotations
|
|
556
|
+
|
|
557
|
+
Resources support the following annotations to provide additional context:
|
|
558
|
+
|
|
559
|
+
##### `@priority()`
|
|
560
|
+
|
|
561
|
+
Specifies the importance of a resource as a number between 0.0 and 1.0:
|
|
562
|
+
|
|
563
|
+
```typescript
|
|
564
|
+
import { Resource } from '@jrmc/adonis-mcp'
|
|
565
|
+
import { priority } from '@jrmc/adonis-mcp/annotations'
|
|
566
|
+
|
|
567
|
+
@priority(0.9)
|
|
568
|
+
export default class ImportantDocResource extends Resource {
|
|
569
|
+
name = 'important_doc.txt'
|
|
570
|
+
uri = 'file:///important_doc.txt'
|
|
571
|
+
|
|
572
|
+
async handle({ response }: ResourceContext) {
|
|
573
|
+
return response.text('Critical documentation content')
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
##### `@audience()`
|
|
579
|
+
|
|
580
|
+
Specifies the intended audience for a resource (user, assistant, or both):
|
|
581
|
+
|
|
582
|
+
```typescript
|
|
583
|
+
import { Resource } from '@jrmc/adonis-mcp'
|
|
584
|
+
import { audience } from '@jrmc/adonis-mcp/annotations'
|
|
585
|
+
import Role from '@jrmc/adonis-mcp/enums/role'
|
|
586
|
+
|
|
587
|
+
@audience(Role.USER)
|
|
588
|
+
export default class UserManualResource extends Resource {
|
|
589
|
+
name = 'user_manual.txt'
|
|
590
|
+
uri = 'file:///user_manual.txt'
|
|
591
|
+
|
|
592
|
+
async handle({ response }: ResourceContext) {
|
|
593
|
+
return response.text('User manual content')
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
```
|
|
597
|
+
|
|
598
|
+
You can also specify multiple audiences:
|
|
599
|
+
|
|
600
|
+
```typescript
|
|
601
|
+
@audience([Role.USER, Role.ASSISTANT])
|
|
602
|
+
export default class SharedDocResource extends Resource {
|
|
603
|
+
// ...
|
|
604
|
+
}
|
|
605
|
+
```
|
|
606
|
+
|
|
607
|
+
##### `@lastModified()`
|
|
608
|
+
|
|
609
|
+
Indicates when a resource was last updated (ISO 8601 timestamp):
|
|
610
|
+
|
|
611
|
+
```typescript
|
|
612
|
+
import { Resource } from '@jrmc/adonis-mcp'
|
|
613
|
+
import { lastModified } from '@jrmc/adonis-mcp/annotations'
|
|
614
|
+
|
|
615
|
+
@lastModified('2024-12-12T10:00:00Z')
|
|
616
|
+
export default class DocumentResource extends Resource {
|
|
617
|
+
name = 'document.txt'
|
|
618
|
+
uri = 'file:///document.txt'
|
|
619
|
+
|
|
620
|
+
async handle({ response }: ResourceContext) {
|
|
621
|
+
return response.text('Document content')
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
```
|
|
625
|
+
|
|
626
|
+
##### Combining Resource Annotations
|
|
627
|
+
|
|
628
|
+
You can use multiple annotations on the same resource:
|
|
629
|
+
|
|
630
|
+
```typescript
|
|
631
|
+
import { Resource } from '@jrmc/adonis-mcp'
|
|
632
|
+
import { priority, audience, lastModified } from '@jrmc/adonis-mcp/annotations'
|
|
633
|
+
import Role from '@jrmc/adonis-mcp/enums/role'
|
|
634
|
+
|
|
635
|
+
@priority(0.8)
|
|
636
|
+
@audience([Role.USER, Role.ASSISTANT])
|
|
637
|
+
@lastModified('2024-12-12T10:00:00Z')
|
|
638
|
+
export default class ApiDocResource extends Resource {
|
|
639
|
+
name = 'api_docs.txt'
|
|
640
|
+
uri = 'file:///api_docs.txt'
|
|
641
|
+
|
|
642
|
+
async handle({ response }: ResourceContext) {
|
|
643
|
+
return response.text('API documentation content')
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
```
|
|
647
|
+
|
|
648
|
+
### Creating a Resource
|
|
649
|
+
|
|
650
|
+
To create a new resource, use the Ace command:
|
|
651
|
+
|
|
652
|
+
```bash
|
|
653
|
+
node ace make:mcp-resource my_resource
|
|
654
|
+
```
|
|
655
|
+
|
|
656
|
+
This command will create a file in `app/mcp/resources/my_resource.ts` with a base template:
|
|
657
|
+
|
|
658
|
+
```typescript
|
|
659
|
+
import type { ResourceContext } from '@jrmc/adonis-mcp/types/context'
|
|
660
|
+
|
|
661
|
+
import { Resource } from '@jrmc/adonis-mcp'
|
|
662
|
+
|
|
663
|
+
export default class MyResourceResource extends Resource {
|
|
664
|
+
name = 'example.txt'
|
|
665
|
+
uri = 'file:///example.txt'
|
|
666
|
+
mimeType = 'text/plain'
|
|
667
|
+
title = 'Resource title'
|
|
668
|
+
description = 'Resource description'
|
|
669
|
+
size = 0
|
|
670
|
+
|
|
671
|
+
async handle({ response }: ResourceContext) {
|
|
672
|
+
this.size = 1000
|
|
673
|
+
return response.text('Hello World')
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
```
|
|
677
|
+
|
|
678
|
+
### Resource Properties
|
|
679
|
+
|
|
680
|
+
Resources have the following properties:
|
|
681
|
+
|
|
682
|
+
- `name` (optional): The name of the resource
|
|
683
|
+
- `uri` (required): The unique identifier for the resource (must be unique)
|
|
684
|
+
- `mimeType` (optional): The MIME type of the resource
|
|
685
|
+
- `title` (optional): A human-readable title
|
|
686
|
+
- `description` (optional): A description of the resource
|
|
687
|
+
- `size` (optional): The size of the resource in bytes
|
|
688
|
+
|
|
689
|
+
### Resource Handler
|
|
690
|
+
|
|
691
|
+
The `handle` method returns the content of the resource. You can use `response.text()` for text content or `response.blob()` for binary content:
|
|
692
|
+
|
|
693
|
+
```typescript
|
|
694
|
+
async handle({ response }: ResourceContext) {
|
|
695
|
+
const content = await fs.readFile('path/to/file.txt', 'utf-8')
|
|
696
|
+
this.size = content.length
|
|
697
|
+
return response.text(content)
|
|
698
|
+
}
|
|
699
|
+
```
|
|
700
|
+
|
|
701
|
+
### URI Templates
|
|
702
|
+
|
|
703
|
+
Resources support URI templates (RFC 6570) to create dynamic resources. This allows you to define resources with variable parts in their URIs:
|
|
704
|
+
|
|
705
|
+
```typescript
|
|
706
|
+
import type { ResourceContext } from '@jrmc/adonis-mcp/types/context'
|
|
707
|
+
import { Resource } from '@jrmc/adonis-mcp'
|
|
708
|
+
|
|
709
|
+
type Args = {
|
|
710
|
+
name: string
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
export default class RobotsResource extends Resource<Args> {
|
|
714
|
+
name = 'robots.txt'
|
|
715
|
+
uri = 'file:///{name}.txt'
|
|
716
|
+
mimeType = 'text/plain'
|
|
717
|
+
title = 'Robots file'
|
|
718
|
+
description = 'Dynamic robots.txt file'
|
|
719
|
+
|
|
720
|
+
async handle({ args, response }: ResourceContext<Args>) {
|
|
721
|
+
this.size = 1000
|
|
722
|
+
return response.text(`Hello World ${args?.name}`)
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
```
|
|
726
|
+
|
|
727
|
+
When a client requests `file:///robots.txt`, the template `file:///{name}.txt` will match and extract `name: "robots"` as an argument, which will be available in the `handle` method via `args.name`.
|
|
728
|
+
|
|
729
|
+
URI templates support various operators:
|
|
730
|
+
- `{name}` - Simple variable substitution
|
|
731
|
+
- `{/name}` - Path segment
|
|
732
|
+
- `{?name}` - Query parameter
|
|
733
|
+
- `{&name}` - Additional query parameter
|
|
734
|
+
- `{#name}` - Fragment identifier
|
|
735
|
+
- `{+name}` - Reserved characters allowed
|
|
736
|
+
- `{.name}` - Dot-prefixed segment
|
|
737
|
+
|
|
738
|
+
For more information, see [RFC 6570](https://www.rfc-editor.org/rfc/rfc6570).
|
|
739
|
+
|
|
740
|
+
### Creating a Prompt
|
|
741
|
+
|
|
742
|
+
To create a new prompt, use the Ace command:
|
|
743
|
+
|
|
744
|
+
```bash
|
|
745
|
+
node ace make:mcp-prompt my_prompt
|
|
746
|
+
```
|
|
747
|
+
|
|
748
|
+
This command will create a file in `app/mcp/prompts/my_prompt.ts` with a base template:
|
|
749
|
+
|
|
750
|
+
```typescript
|
|
751
|
+
import type { PromptContext } from '@jrmc/adonis-mcp/types/context'
|
|
752
|
+
import type { BaseSchema } from '@jrmc/adonis-mcp/types/method'
|
|
753
|
+
|
|
754
|
+
import { Prompt } from '@jrmc/adonis-mcp'
|
|
755
|
+
|
|
756
|
+
type Schema = BaseSchema<{
|
|
757
|
+
text: { type: "string" }
|
|
758
|
+
}>
|
|
759
|
+
|
|
760
|
+
export default class MyPromptPrompt extends Prompt<Schema> {
|
|
761
|
+
name = 'my_prompt'
|
|
762
|
+
title = 'Prompt title'
|
|
763
|
+
description = 'Prompt description'
|
|
764
|
+
|
|
765
|
+
async handle({ args, response }: PromptContext<Schema>) {
|
|
766
|
+
return [
|
|
767
|
+
response.text('Hello, world!')
|
|
768
|
+
]
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
schema() {
|
|
772
|
+
return {
|
|
773
|
+
type: "object",
|
|
774
|
+
properties: {
|
|
775
|
+
text: {
|
|
776
|
+
type: "string",
|
|
777
|
+
description: "Description text argument"
|
|
778
|
+
},
|
|
779
|
+
},
|
|
780
|
+
required: ["text"]
|
|
781
|
+
} as Schema
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
```
|
|
785
|
+
|
|
786
|
+
### Prompt Schema
|
|
787
|
+
|
|
788
|
+
Prompts use the same schema definition system as tools, following the [JSON Schema](https://json-schema.org/) specification. You can also use Zod to define your schema:
|
|
789
|
+
|
|
790
|
+
```typescript
|
|
791
|
+
import * as z from 'zod'
|
|
792
|
+
|
|
793
|
+
const zodSchema = z.object({
|
|
794
|
+
code: z.string(),
|
|
795
|
+
language: z.string().optional()
|
|
796
|
+
})
|
|
797
|
+
|
|
798
|
+
schema() {
|
|
799
|
+
return z.toJSONSchema(
|
|
800
|
+
zodSchema,
|
|
801
|
+
{ io: "input" }
|
|
802
|
+
) as Schema
|
|
803
|
+
}
|
|
804
|
+
```
|
|
805
|
+
|
|
806
|
+
### Prompt Handler
|
|
807
|
+
|
|
808
|
+
The `handle` method for prompts returns an array of content objects. This allows you to return multiple pieces of content, including embedded resources:
|
|
809
|
+
|
|
810
|
+
```typescript
|
|
811
|
+
async handle({ args, response }: PromptContext<Schema>) {
|
|
812
|
+
return [
|
|
813
|
+
response.text(`Please review this code:\n\n${args.code}`),
|
|
814
|
+
response.embeddedResource('file:///example.txt')
|
|
815
|
+
]
|
|
816
|
+
}
|
|
817
|
+
```
|
|
818
|
+
|
|
819
|
+
### Prompt Response Methods
|
|
820
|
+
|
|
821
|
+
For prompts, you can use the same response methods as tools, but you must return an array:
|
|
822
|
+
|
|
823
|
+
- `response.text(text: string)`: Return plain text content
|
|
824
|
+
- `response.image(data: string, mimeType: string)`: Return image content (base64 encoded)
|
|
825
|
+
- `response.audio(data: string, mimeType: string)`: Return audio content (base64 encoded)
|
|
826
|
+
- `response.embeddedResource(uri: string)`: Embed another resource in the prompt response
|
|
827
|
+
|
|
828
|
+
All response methods also support the `withMeta()` method to add metadata:
|
|
829
|
+
|
|
830
|
+
```typescript
|
|
831
|
+
async handle({ args, response }: PromptContext<Schema>) {
|
|
832
|
+
return [
|
|
833
|
+
response.text('Here is the code to review:').withMeta({
|
|
834
|
+
language: args.language
|
|
835
|
+
}),
|
|
836
|
+
response.embeddedResource('file:///code.py'),
|
|
837
|
+
response.text('Please provide feedback.')
|
|
838
|
+
]
|
|
839
|
+
}
|
|
840
|
+
```
|
|
841
|
+
|
|
842
|
+
### Complete Prompt Example
|
|
843
|
+
|
|
844
|
+
Here is a complete example of a prompt for code review:
|
|
845
|
+
|
|
846
|
+
```typescript
|
|
847
|
+
import type { PromptContext } from '@jrmc/adonis-mcp/types/context'
|
|
848
|
+
import type { BaseSchema } from '@jrmc/adonis-mcp/types/method'
|
|
849
|
+
|
|
850
|
+
import { Prompt } from '@jrmc/adonis-mcp'
|
|
851
|
+
|
|
852
|
+
type Schema = BaseSchema<{
|
|
853
|
+
code: { type: "string" }
|
|
854
|
+
language: { type: "string" }
|
|
855
|
+
}>
|
|
856
|
+
|
|
857
|
+
export default class CodeReviewPrompt extends Prompt<Schema> {
|
|
858
|
+
name = 'code_review'
|
|
859
|
+
title = 'Code Review'
|
|
860
|
+
description = 'Review code and provide feedback'
|
|
861
|
+
|
|
862
|
+
async handle({ args, response }: PromptContext<Schema>) {
|
|
863
|
+
return [
|
|
864
|
+
response.text(`Please review this ${args.language} code:\n\n${args.code}`),
|
|
865
|
+
response.text('Provide feedback on code quality, potential bugs, and improvements.')
|
|
866
|
+
]
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
schema() {
|
|
870
|
+
return {
|
|
871
|
+
type: "object",
|
|
872
|
+
properties: {
|
|
873
|
+
code: {
|
|
874
|
+
type: "string",
|
|
875
|
+
description: "The code to review"
|
|
876
|
+
},
|
|
877
|
+
language: {
|
|
878
|
+
type: "string",
|
|
879
|
+
description: "Programming language"
|
|
880
|
+
}
|
|
881
|
+
},
|
|
882
|
+
required: ["code", "language"]
|
|
883
|
+
} as Schema
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
```
|
|
887
|
+
|
|
888
|
+
## Completions
|
|
889
|
+
|
|
890
|
+
Completions provide argument suggestions for prompts and resources, helping users fill in parameters interactively. This feature must be enabled in your configuration and can be implemented for both prompts and resources.
|
|
891
|
+
|
|
892
|
+
### Enabling Completions
|
|
893
|
+
|
|
894
|
+
First, enable completions in your `config/mcp.ts`:
|
|
895
|
+
|
|
896
|
+
```typescript
|
|
897
|
+
import { defineConfig } from '@jrmc/adonis-mcp'
|
|
898
|
+
|
|
899
|
+
export default defineConfig({
|
|
900
|
+
name: 'adonis-mcp-server',
|
|
901
|
+
version: '1.0.0',
|
|
902
|
+
completions: true, // Enable completions
|
|
903
|
+
})
|
|
904
|
+
```
|
|
905
|
+
|
|
906
|
+
### Implementing Completions in Prompts
|
|
907
|
+
|
|
908
|
+
Add a `complete()` method to your prompt to provide argument suggestions:
|
|
909
|
+
|
|
910
|
+
```typescript
|
|
911
|
+
import type { PromptContext, CompleteContext } from '@jrmc/adonis-mcp/types/context'
|
|
912
|
+
import type { BaseSchema } from '@jrmc/adonis-mcp/types/method'
|
|
913
|
+
|
|
914
|
+
import { Prompt } from '@jrmc/adonis-mcp'
|
|
915
|
+
|
|
916
|
+
type Schema = BaseSchema<{
|
|
917
|
+
language: { type: "string" }
|
|
918
|
+
code: { type: "string" }
|
|
919
|
+
}>
|
|
920
|
+
|
|
921
|
+
export default class CodeReviewPrompt extends Prompt<Schema> {
|
|
922
|
+
name = 'code_review'
|
|
923
|
+
title = 'Code Review'
|
|
924
|
+
description = 'Review code and provide feedback'
|
|
925
|
+
|
|
926
|
+
async handle({ args, response }: PromptContext<Schema>) {
|
|
927
|
+
return [
|
|
928
|
+
response.text(`Please review this ${args.language} code:\n\n${args.code}`)
|
|
929
|
+
]
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
async complete({ args, response }: CompleteContext<Schema>) {
|
|
933
|
+
// Provide language suggestions when the user types
|
|
934
|
+
if (args?.language !== undefined) {
|
|
935
|
+
return response.complete({
|
|
936
|
+
values: ['python', 'javascript', 'typescript', 'java', 'go', 'rust']
|
|
937
|
+
})
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
return response.complete({ values: [] })
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
schema() {
|
|
944
|
+
return {
|
|
945
|
+
type: "object",
|
|
946
|
+
properties: {
|
|
947
|
+
language: {
|
|
948
|
+
type: "string",
|
|
949
|
+
description: "Programming language"
|
|
950
|
+
},
|
|
951
|
+
code: {
|
|
952
|
+
type: "string",
|
|
953
|
+
description: "Code to review"
|
|
954
|
+
}
|
|
955
|
+
},
|
|
956
|
+
required: ["language", "code"]
|
|
957
|
+
} as Schema
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
```
|
|
961
|
+
|
|
962
|
+
### Implementing Completions in Resources
|
|
963
|
+
|
|
964
|
+
Resources with URI templates can also provide completions for their path parameters:
|
|
965
|
+
|
|
966
|
+
```typescript
|
|
967
|
+
import type { ResourceContext, CompleteContext } from '@jrmc/adonis-mcp/types/context'
|
|
968
|
+
import { Resource } from '@jrmc/adonis-mcp'
|
|
969
|
+
|
|
970
|
+
type Args = {
|
|
971
|
+
directory: string
|
|
972
|
+
name: string
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
export default class ConfigFileResource extends Resource<Args> {
|
|
976
|
+
name = 'config_file'
|
|
977
|
+
uri = 'file://{directory}/{name}.txt'
|
|
978
|
+
mimeType = 'text/plain'
|
|
979
|
+
title = 'Configuration File'
|
|
980
|
+
description = 'Access configuration files'
|
|
981
|
+
|
|
982
|
+
async handle({ args, response }: ResourceContext<Args>) {
|
|
983
|
+
const content = await readConfigFile(args.directory, args.name)
|
|
984
|
+
return response.text(content)
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
async complete({ args, response }: CompleteContext<Args>) {
|
|
988
|
+
// Provide suggestions based on available directories and files
|
|
989
|
+
if (args?.name !== undefined) {
|
|
990
|
+
return response.complete({
|
|
991
|
+
values: ['config', 'settings', 'environment', 'database']
|
|
992
|
+
})
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
if (args?.directory !== undefined) {
|
|
996
|
+
return response.complete({
|
|
997
|
+
values: ['production', 'staging', 'development']
|
|
998
|
+
})
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
return response.complete({ values: [] })
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
```
|
|
1005
|
+
|
|
1006
|
+
### Completion Context
|
|
1007
|
+
|
|
1008
|
+
The `complete()` method receives a `CompleteContext` that includes:
|
|
1009
|
+
|
|
1010
|
+
- `args`: The current argument values (partial or complete)
|
|
1011
|
+
- `response`: The response object with a `complete()` method
|
|
1012
|
+
|
|
1013
|
+
The response format includes:
|
|
1014
|
+
|
|
1015
|
+
```typescript
|
|
1016
|
+
response.complete({
|
|
1017
|
+
values: string[], // Array of suggested values
|
|
1018
|
+
hasMore?: boolean, // Optional: indicates if more values are available
|
|
1019
|
+
total?: number // Optional: total number of available values
|
|
1020
|
+
})
|
|
1021
|
+
```
|
|
1022
|
+
|
|
1023
|
+
### Transports
|
|
1024
|
+
|
|
1025
|
+
The package supports multiple transport mechanisms:
|
|
1026
|
+
|
|
1027
|
+
- **HTTP Transport**: Default transport for HTTP-based MCP servers (used when accessing via HTTP routes)
|
|
1028
|
+
- **Stdio Transport**: For command-line MCP servers that communicate via standard input/output
|
|
1029
|
+
- **Fake Transport**: For testing purposes, allows you to capture and inspect MCP messages
|
|
1030
|
+
|
|
279
1031
|
### Pagination
|
|
280
1032
|
|
|
281
|
-
The `tools/list`
|
|
1033
|
+
The `tools/list` and `resources/list` methods support cursor-based pagination to handle large numbers of tools and resources efficiently. This is particularly useful when you have many tools or resources registered in your application. [More information](https://modelcontextprotocol.io/specification/2025-06-18/server/utilities/pagination)
|
|
1034
|
+
|
|
1035
|
+
## Testing & Debugging
|
|
1036
|
+
|
|
1037
|
+
### MCP Inspector
|
|
1038
|
+
|
|
1039
|
+
The MCP Inspector is a powerful tool for debugging and testing your MCP server. It provides a graphical interface to interact with your tools, resources, and prompts.
|
|
1040
|
+
|
|
1041
|
+
To open the MCP Inspector, use the following command:
|
|
1042
|
+
|
|
1043
|
+
```bash
|
|
1044
|
+
node ace mcp:inspector
|
|
1045
|
+
```
|
|
1046
|
+
|
|
1047
|
+
By default, this command uses HTTP transport. You can specify a different transport type:
|
|
1048
|
+
|
|
1049
|
+
```bash
|
|
1050
|
+
# Use HTTP transport (default)
|
|
1051
|
+
node ace mcp:inspector http
|
|
1052
|
+
|
|
1053
|
+
# Use stdio transport
|
|
1054
|
+
node ace mcp:inspector stdio
|
|
1055
|
+
```
|
|
1056
|
+
|
|
1057
|
+
**Important notes:**
|
|
1058
|
+
|
|
1059
|
+
- The inspector can only be used in development environment (not in production)
|
|
1060
|
+
- For HTTP transport, make sure your server is running and the MCP route is configured
|
|
1061
|
+
- The inspector will automatically connect to your MCP server and allow you to:
|
|
1062
|
+
- List and test all available tools
|
|
1063
|
+
- Browse and read resources
|
|
1064
|
+
- Execute prompts with different arguments
|
|
1065
|
+
- Inspect request/response payloads
|
|
1066
|
+
- Debug any issues with your MCP implementation
|
|
282
1067
|
|
|
283
1068
|
## Support
|
|
284
1069
|
|