@leanmcp/elicitation 0.1.3 → 0.1.4-alpha.3.0eaae8f
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 +80 -70
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,6 +27,10 @@
|
|
|
27
27
|
<a href="https://x.com/LeanMcp">
|
|
28
28
|
<img src="https://img.shields.io/badge/@LeanMCP-f5f5f5?logo=x&logoColor=000000" />
|
|
29
29
|
</a>
|
|
30
|
+
<a href="https://leanmcp.com/">
|
|
31
|
+
<img src="https://img.shields.io/badge/Website-leanmcp-0A66C2?" />
|
|
32
|
+
</a>
|
|
33
|
+
<a href="https://deepwiki.com/LeanMCP/leanmcp-sdk"><img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki"></a>
|
|
30
34
|
</p>
|
|
31
35
|
|
|
32
36
|
## Features
|
|
@@ -48,32 +52,32 @@ npm install @leanmcp/elicitation @leanmcp/core
|
|
|
48
52
|
### Simple Form Elicitation
|
|
49
53
|
|
|
50
54
|
```typescript
|
|
51
|
-
import { Tool } from
|
|
52
|
-
import { Elicitation } from
|
|
55
|
+
import { Tool } from '@leanmcp/core';
|
|
56
|
+
import { Elicitation } from '@leanmcp/elicitation';
|
|
53
57
|
|
|
54
58
|
class SlackService {
|
|
55
|
-
@Tool({ description:
|
|
59
|
+
@Tool({ description: 'Create a new Slack channel' })
|
|
56
60
|
@Elicitation({
|
|
57
|
-
title:
|
|
58
|
-
description:
|
|
61
|
+
title: 'Create Channel',
|
|
62
|
+
description: 'Please provide channel details',
|
|
59
63
|
fields: [
|
|
60
64
|
{
|
|
61
|
-
name:
|
|
62
|
-
label:
|
|
63
|
-
type:
|
|
65
|
+
name: 'channelName',
|
|
66
|
+
label: 'Channel Name',
|
|
67
|
+
type: 'text',
|
|
64
68
|
required: true,
|
|
65
69
|
validation: {
|
|
66
|
-
pattern:
|
|
67
|
-
errorMessage:
|
|
68
|
-
}
|
|
70
|
+
pattern: '^[a-z0-9-]+$',
|
|
71
|
+
errorMessage: 'Must be lowercase alphanumeric with hyphens',
|
|
72
|
+
},
|
|
69
73
|
},
|
|
70
74
|
{
|
|
71
|
-
name:
|
|
72
|
-
label:
|
|
73
|
-
type:
|
|
74
|
-
defaultValue: false
|
|
75
|
-
}
|
|
76
|
-
]
|
|
75
|
+
name: 'isPrivate',
|
|
76
|
+
label: 'Private Channel',
|
|
77
|
+
type: 'boolean',
|
|
78
|
+
defaultValue: false,
|
|
79
|
+
},
|
|
80
|
+
],
|
|
77
81
|
})
|
|
78
82
|
async createChannel(args: { channelName: string; isPrivate: boolean }) {
|
|
79
83
|
return { success: true, channelName: args.channelName };
|
|
@@ -97,29 +101,26 @@ class SlackService {
|
|
|
97
101
|
For more complex forms, use `ElicitationFormBuilder`:
|
|
98
102
|
|
|
99
103
|
```typescript
|
|
100
|
-
import { Tool } from
|
|
101
|
-
import { Elicitation, ElicitationFormBuilder, validation } from
|
|
104
|
+
import { Tool } from '@leanmcp/core';
|
|
105
|
+
import { Elicitation, ElicitationFormBuilder, validation } from '@leanmcp/elicitation';
|
|
102
106
|
|
|
103
107
|
class UserService {
|
|
104
|
-
@Tool({ description:
|
|
108
|
+
@Tool({ description: 'Create user account' })
|
|
105
109
|
@Elicitation({
|
|
106
|
-
builder: () =>
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
.minLength(3)
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
{ label: "User", value: "user" }
|
|
121
|
-
])
|
|
122
|
-
.build()
|
|
110
|
+
builder: () =>
|
|
111
|
+
new ElicitationFormBuilder()
|
|
112
|
+
.title('User Registration')
|
|
113
|
+
.description('Create a new user account')
|
|
114
|
+
.addEmailField('email', 'Email Address', { required: true })
|
|
115
|
+
.addTextField('username', 'Username', {
|
|
116
|
+
required: true,
|
|
117
|
+
validation: validation().minLength(3).maxLength(20).pattern('^[a-zA-Z0-9_]+$').build(),
|
|
118
|
+
})
|
|
119
|
+
.addSelectField('role', 'Role', [
|
|
120
|
+
{ label: 'Admin', value: 'admin' },
|
|
121
|
+
{ label: 'User', value: 'user' },
|
|
122
|
+
])
|
|
123
|
+
.build(),
|
|
123
124
|
})
|
|
124
125
|
async createUser(args: any) {
|
|
125
126
|
return { success: true, email: args.email };
|
|
@@ -129,22 +130,22 @@ class UserService {
|
|
|
129
130
|
|
|
130
131
|
### Builder Methods
|
|
131
132
|
|
|
132
|
-
| Method
|
|
133
|
-
|
|
134
|
-
| `title(string)`
|
|
135
|
-
| `description(string)`
|
|
136
|
-
| `condition(fn)`
|
|
137
|
-
| `addTextField(name, label, opts?)`
|
|
138
|
-
| `addTextAreaField(name, label, opts?)`
|
|
139
|
-
| `addNumberField(name, label, opts?)`
|
|
140
|
-
| `addBooleanField(name, label, opts?)`
|
|
141
|
-
| `addSelectField(name, label, options, opts?)`
|
|
142
|
-
| `addMultiSelectField(name, label, options, opts?)` | Add multi-select
|
|
143
|
-
| `addEmailField(name, label, opts?)`
|
|
144
|
-
| `addUrlField(name, label, opts?)`
|
|
145
|
-
| `addDateField(name, label, opts?)`
|
|
146
|
-
| `addCustomField(field)`
|
|
147
|
-
| `build()`
|
|
133
|
+
| Method | Description |
|
|
134
|
+
| -------------------------------------------------- | ----------------------------- |
|
|
135
|
+
| `title(string)` | Set form title |
|
|
136
|
+
| `description(string)` | Set form description |
|
|
137
|
+
| `condition(fn)` | Set condition for elicitation |
|
|
138
|
+
| `addTextField(name, label, opts?)` | Add text input |
|
|
139
|
+
| `addTextAreaField(name, label, opts?)` | Add textarea |
|
|
140
|
+
| `addNumberField(name, label, opts?)` | Add number input |
|
|
141
|
+
| `addBooleanField(name, label, opts?)` | Add checkbox |
|
|
142
|
+
| `addSelectField(name, label, options, opts?)` | Add dropdown |
|
|
143
|
+
| `addMultiSelectField(name, label, options, opts?)` | Add multi-select |
|
|
144
|
+
| `addEmailField(name, label, opts?)` | Add email input |
|
|
145
|
+
| `addUrlField(name, label, opts?)` | Add URL input |
|
|
146
|
+
| `addDateField(name, label, opts?)` | Add date picker |
|
|
147
|
+
| `addCustomField(field)` | Add custom field |
|
|
148
|
+
| `build()` | Build final config |
|
|
148
149
|
|
|
149
150
|
---
|
|
150
151
|
|
|
@@ -224,17 +225,17 @@ async deployApp(args: any) {
|
|
|
224
225
|
|
|
225
226
|
## Field Types
|
|
226
227
|
|
|
227
|
-
| Type
|
|
228
|
-
|
|
229
|
-
| `text`
|
|
230
|
-
| `textarea`
|
|
231
|
-
| `number`
|
|
232
|
-
| `boolean`
|
|
233
|
-
| `select`
|
|
234
|
-
| `multiselect` | Multi-select
|
|
235
|
-
| `email`
|
|
236
|
-
| `url`
|
|
237
|
-
| `date`
|
|
228
|
+
| Type | Description |
|
|
229
|
+
| ------------- | ------------------------ |
|
|
230
|
+
| `text` | Single-line text input |
|
|
231
|
+
| `textarea` | Multi-line text area |
|
|
232
|
+
| `number` | Numeric input |
|
|
233
|
+
| `boolean` | Checkbox |
|
|
234
|
+
| `select` | Dropdown (single choice) |
|
|
235
|
+
| `multiselect` | Multi-select |
|
|
236
|
+
| `email` | Email input |
|
|
237
|
+
| `url` | URL input |
|
|
238
|
+
| `date` | Date picker |
|
|
238
239
|
|
|
239
240
|
---
|
|
240
241
|
|
|
@@ -259,15 +260,15 @@ async deployApp(args: any) {
|
|
|
259
260
|
### Using ValidationBuilder
|
|
260
261
|
|
|
261
262
|
```typescript
|
|
262
|
-
import { validation } from
|
|
263
|
+
import { validation } from '@leanmcp/elicitation';
|
|
263
264
|
|
|
264
265
|
validation()
|
|
265
266
|
.minLength(8)
|
|
266
267
|
.maxLength(100)
|
|
267
|
-
.pattern(
|
|
268
|
-
.customValidator((value) => value !==
|
|
269
|
-
.errorMessage(
|
|
270
|
-
.build()
|
|
268
|
+
.pattern('^[a-zA-Z0-9]+$')
|
|
269
|
+
.customValidator((value) => value !== 'admin')
|
|
270
|
+
.errorMessage('Invalid input')
|
|
271
|
+
.build();
|
|
271
272
|
```
|
|
272
273
|
|
|
273
274
|
---
|
|
@@ -293,7 +294,16 @@ interface ElicitationConfig {
|
|
|
293
294
|
interface ElicitationField {
|
|
294
295
|
name: string;
|
|
295
296
|
label: string;
|
|
296
|
-
type:
|
|
297
|
+
type:
|
|
298
|
+
| 'text'
|
|
299
|
+
| 'number'
|
|
300
|
+
| 'boolean'
|
|
301
|
+
| 'select'
|
|
302
|
+
| 'multiselect'
|
|
303
|
+
| 'date'
|
|
304
|
+
| 'email'
|
|
305
|
+
| 'url'
|
|
306
|
+
| 'textarea';
|
|
297
307
|
description?: string;
|
|
298
308
|
required?: boolean;
|
|
299
309
|
defaultValue?: any;
|
package/package.json
CHANGED