@modelcontextprotocol/sdk 1.25.3 → 1.26.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/dist/cjs/client/auth-extensions.d.ts +12 -0
- package/dist/cjs/client/auth-extensions.d.ts.map +1 -1
- package/dist/cjs/client/auth-extensions.js +6 -3
- package/dist/cjs/client/auth-extensions.js.map +1 -1
- package/dist/cjs/examples/server/elicitationFormExample.js +250 -244
- package/dist/cjs/examples/server/elicitationFormExample.js.map +1 -1
- package/dist/cjs/examples/server/honoWebStandardStreamableHttp.js +31 -27
- package/dist/cjs/examples/server/honoWebStandardStreamableHttp.js.map +1 -1
- package/dist/cjs/examples/server/ssePollingExample.js +58 -53
- package/dist/cjs/examples/server/ssePollingExample.js.map +1 -1
- package/dist/cjs/examples/server/standaloneSseWithGetStreamableHttp.js +33 -21
- package/dist/cjs/examples/server/standaloneSseWithGetStreamableHttp.js.map +1 -1
- package/dist/cjs/server/webStandardStreamableHttp.d.ts +1 -0
- package/dist/cjs/server/webStandardStreamableHttp.d.ts.map +1 -1
- package/dist/cjs/server/webStandardStreamableHttp.js +7 -0
- package/dist/cjs/server/webStandardStreamableHttp.js.map +1 -1
- package/dist/cjs/shared/protocol.d.ts.map +1 -1
- package/dist/cjs/shared/protocol.js +13 -0
- package/dist/cjs/shared/protocol.js.map +1 -1
- package/dist/esm/client/auth-extensions.d.ts +12 -0
- package/dist/esm/client/auth-extensions.d.ts.map +1 -1
- package/dist/esm/client/auth-extensions.js +6 -3
- package/dist/esm/client/auth-extensions.js.map +1 -1
- package/dist/esm/examples/server/elicitationFormExample.js +250 -244
- package/dist/esm/examples/server/elicitationFormExample.js.map +1 -1
- package/dist/esm/examples/server/honoWebStandardStreamableHttp.js +31 -27
- package/dist/esm/examples/server/honoWebStandardStreamableHttp.js.map +1 -1
- package/dist/esm/examples/server/ssePollingExample.js +58 -53
- package/dist/esm/examples/server/ssePollingExample.js.map +1 -1
- package/dist/esm/examples/server/standaloneSseWithGetStreamableHttp.js +33 -21
- package/dist/esm/examples/server/standaloneSseWithGetStreamableHttp.js.map +1 -1
- package/dist/esm/server/webStandardStreamableHttp.d.ts +1 -0
- package/dist/esm/server/webStandardStreamableHttp.d.ts.map +1 -1
- package/dist/esm/server/webStandardStreamableHttp.js +7 -0
- package/dist/esm/server/webStandardStreamableHttp.js.map +1 -1
- package/dist/esm/shared/protocol.d.ts.map +1 -1
- package/dist/esm/shared/protocol.js +13 -0
- package/dist/esm/shared/protocol.js.map +1 -1
- package/package.json +9 -5
|
@@ -38,6 +38,10 @@ export interface ClientCredentialsProviderOptions {
|
|
|
38
38
|
* Optional client name for metadata.
|
|
39
39
|
*/
|
|
40
40
|
clientName?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Space-separated scopes values requested by the client.
|
|
43
|
+
*/
|
|
44
|
+
scope?: string;
|
|
41
45
|
}
|
|
42
46
|
/**
|
|
43
47
|
* OAuth provider for client_credentials grant with client_secret_basic authentication.
|
|
@@ -96,6 +100,10 @@ export interface PrivateKeyJwtProviderOptions {
|
|
|
96
100
|
* Optional JWT lifetime in seconds (default: 300).
|
|
97
101
|
*/
|
|
98
102
|
jwtLifetimeSeconds?: number;
|
|
103
|
+
/**
|
|
104
|
+
* Space-separated scopes values requested by the client.
|
|
105
|
+
*/
|
|
106
|
+
scope?: string;
|
|
99
107
|
}
|
|
100
108
|
/**
|
|
101
109
|
* OAuth provider for client_credentials grant with private_key_jwt authentication.
|
|
@@ -150,6 +158,10 @@ export interface StaticPrivateKeyJwtProviderOptions {
|
|
|
150
158
|
* Optional client name for metadata.
|
|
151
159
|
*/
|
|
152
160
|
clientName?: string;
|
|
161
|
+
/**
|
|
162
|
+
* Space-separated scopes values requested by the client.
|
|
163
|
+
*/
|
|
164
|
+
scope?: string;
|
|
153
165
|
}
|
|
154
166
|
/**
|
|
155
167
|
* OAuth provider for client_credentials grant with a static private_key_jwt assertion.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-extensions.d.ts","sourceRoot":"","sources":["../../../src/client/auth-extensions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC7F,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEzE;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1D,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC,GAAG,uBAAuB,CAgE1B;AAED;;GAEG;AACH,MAAM,WAAW,gCAAgC;IAC7C;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"auth-extensions.d.ts","sourceRoot":"","sources":["../../../src/client/auth-extensions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC7F,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAEzE;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,GAAG,UA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7C,uBAAuB,EAAE,uBAAuB,CAAC;gBAErC,OAAO,EAAE,kCAAkC;IAmBvD,IAAI,WAAW,IAAI,SAAS,CAE3B;IAED,IAAI,cAAc,IAAI,mBAAmB,CAExC;IAED,iBAAiB,IAAI,sBAAsB;IAI3C,qBAAqB,CAAC,IAAI,EAAE,sBAAsB,GAAG,IAAI;IAIzD,MAAM,IAAI,WAAW,GAAG,SAAS;IAIjC,UAAU,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI;IAIrC,uBAAuB,IAAI,IAAI;IAI/B,gBAAgB,IAAI,IAAI;IAIxB,YAAY,IAAI,MAAM;IAItB,mBAAmB,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,eAAe;CAKvD"}
|
|
@@ -125,7 +125,8 @@ class ClientCredentialsProvider {
|
|
|
125
125
|
client_name: options.clientName ?? 'client-credentials-client',
|
|
126
126
|
redirect_uris: [],
|
|
127
127
|
grant_types: ['client_credentials'],
|
|
128
|
-
token_endpoint_auth_method: 'client_secret_basic'
|
|
128
|
+
token_endpoint_auth_method: 'client_secret_basic',
|
|
129
|
+
scope: options.scope
|
|
129
130
|
};
|
|
130
131
|
}
|
|
131
132
|
get redirectUrl() {
|
|
@@ -189,7 +190,8 @@ class PrivateKeyJwtProvider {
|
|
|
189
190
|
client_name: options.clientName ?? 'private-key-jwt-client',
|
|
190
191
|
redirect_uris: [],
|
|
191
192
|
grant_types: ['client_credentials'],
|
|
192
|
-
token_endpoint_auth_method: 'private_key_jwt'
|
|
193
|
+
token_endpoint_auth_method: 'private_key_jwt',
|
|
194
|
+
scope: options.scope
|
|
193
195
|
};
|
|
194
196
|
this.addClientAuthentication = createPrivateKeyJwtAuth({
|
|
195
197
|
issuer: options.clientId,
|
|
@@ -250,7 +252,8 @@ class StaticPrivateKeyJwtProvider {
|
|
|
250
252
|
client_name: options.clientName ?? 'static-private-key-jwt-client',
|
|
251
253
|
redirect_uris: [],
|
|
252
254
|
grant_types: ['client_credentials'],
|
|
253
|
-
token_endpoint_auth_method: 'private_key_jwt'
|
|
255
|
+
token_endpoint_auth_method: 'private_key_jwt',
|
|
256
|
+
scope: options.scope
|
|
254
257
|
};
|
|
255
258
|
const assertion = options.jwtBearerAssertion;
|
|
256
259
|
this.addClientAuthentication = async (_headers, params) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-extensions.js","sourceRoot":"","sources":["../../../src/client/auth-extensions.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;AAaH,0DAwEC;AA/ED;;;;;;GAMG;AACH,SAAgB,uBAAuB,CAAC,OAQvC;IACG,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE;QAC7C,oDAAoD;QACpD,IAAI,OAAO,UAAU,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;YAC3C,MAAM,IAAI,SAAS,CACf,qNAAqN,CACxN,CAAC;QACN,CAAC;QAED,MAAM,IAAI,GAAG,wDAAa,MAAM,GAAC,CAAC;QAElC,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,IAAI,QAAQ,EAAE,MAAM,IAAI,GAAG,CAAC,CAAC;QACrE,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,GAAG,CAAC;QAEvD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;QAC1C,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QAEnE,MAAM,UAAU,GAAG;YACf,GAAG,EAAE,OAAO,CAAC,MAAM;YACnB,GAAG,EAAE,OAAO,CAAC,OAAO;YACpB,GAAG,EAAE,QAAQ;YACb,GAAG,EAAE,GAAG,GAA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BAAuB;QACnB,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;IACvF,CAAC;IAED,gBAAgB;QACZ,kCAAkC;IACtC,CAAC;IAED,YAAY;QACR,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;IAC5E,CAAC;IAED,mBAAmB,CAAC,KAAc;QAC9B,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,EAAE,UAAU,EAAE,oBAAoB,EAAE,CAAC,CAAC;QACzE,IAAI,KAAK;YAAE,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACtC,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AAlED,kEAkEC"}
|
|
@@ -13,284 +13,289 @@ const mcp_js_1 = require("../../server/mcp.js");
|
|
|
13
13
|
const streamableHttp_js_1 = require("../../server/streamableHttp.js");
|
|
14
14
|
const types_js_1 = require("../../types.js");
|
|
15
15
|
const express_js_1 = require("../../server/express.js");
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
16
|
+
// Factory to create a new MCP server per session.
|
|
17
|
+
// Each session needs its own server+transport pair to avoid cross-session contamination.
|
|
18
|
+
const getServer = () => {
|
|
19
|
+
// Create MCP server - it will automatically use AjvJsonSchemaValidator with sensible defaults
|
|
20
|
+
// The validator supports format validation (email, date, etc.) if ajv-formats is installed
|
|
21
|
+
const mcpServer = new mcp_js_1.McpServer({
|
|
22
|
+
name: 'form-elicitation-example-server',
|
|
23
|
+
version: '1.0.0'
|
|
24
|
+
}, {
|
|
25
|
+
capabilities: {}
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* Example 1: Simple user registration tool
|
|
29
|
+
* Collects username, email, and password from the user
|
|
30
|
+
*/
|
|
31
|
+
mcpServer.registerTool('register_user', {
|
|
32
|
+
description: 'Register a new user account by collecting their information',
|
|
33
|
+
inputSchema: {}
|
|
34
|
+
}, async () => {
|
|
35
|
+
try {
|
|
36
|
+
// Request user information through form elicitation
|
|
37
|
+
const result = await mcpServer.server.elicitInput({
|
|
38
|
+
mode: 'form',
|
|
39
|
+
message: 'Please provide your registration information:',
|
|
40
|
+
requestedSchema: {
|
|
41
|
+
type: 'object',
|
|
42
|
+
properties: {
|
|
43
|
+
username: {
|
|
44
|
+
type: 'string',
|
|
45
|
+
title: 'Username',
|
|
46
|
+
description: 'Your desired username (3-20 characters)',
|
|
47
|
+
minLength: 3,
|
|
48
|
+
maxLength: 20
|
|
49
|
+
},
|
|
50
|
+
email: {
|
|
51
|
+
type: 'string',
|
|
52
|
+
title: 'Email',
|
|
53
|
+
description: 'Your email address',
|
|
54
|
+
format: 'email'
|
|
55
|
+
},
|
|
56
|
+
password: {
|
|
57
|
+
type: 'string',
|
|
58
|
+
title: 'Password',
|
|
59
|
+
description: 'Your password (min 8 characters)',
|
|
60
|
+
minLength: 8
|
|
61
|
+
},
|
|
62
|
+
newsletter: {
|
|
63
|
+
type: 'boolean',
|
|
64
|
+
title: 'Newsletter',
|
|
65
|
+
description: 'Subscribe to newsletter?',
|
|
66
|
+
default: false
|
|
67
|
+
}
|
|
58
68
|
},
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
69
|
+
required: ['username', 'email', 'password']
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
// Handle the different possible actions
|
|
73
|
+
if (result.action === 'accept' && result.content) {
|
|
74
|
+
const { username, email, newsletter } = result.content;
|
|
75
|
+
return {
|
|
76
|
+
content: [
|
|
77
|
+
{
|
|
78
|
+
type: 'text',
|
|
79
|
+
text: `Registration successful!\n\nUsername: ${username}\nEmail: ${email}\nNewsletter: ${newsletter ? 'Yes' : 'No'}`
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
else if (result.action === 'decline') {
|
|
85
|
+
return {
|
|
86
|
+
content: [
|
|
87
|
+
{
|
|
88
|
+
type: 'text',
|
|
89
|
+
text: 'Registration cancelled by user.'
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
};
|
|
67
93
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
94
|
+
else {
|
|
95
|
+
return {
|
|
96
|
+
content: [
|
|
97
|
+
{
|
|
98
|
+
type: 'text',
|
|
99
|
+
text: 'Registration was cancelled.'
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
72
106
|
return {
|
|
73
107
|
content: [
|
|
74
108
|
{
|
|
75
109
|
type: 'text',
|
|
76
|
-
text: `Registration
|
|
110
|
+
text: `Registration failed: ${error instanceof Error ? error.message : String(error)}`
|
|
77
111
|
}
|
|
78
|
-
]
|
|
112
|
+
],
|
|
113
|
+
isError: true
|
|
79
114
|
};
|
|
80
115
|
}
|
|
81
|
-
|
|
116
|
+
});
|
|
117
|
+
/**
|
|
118
|
+
* Example 2: Multi-step workflow with multiple form elicitation requests
|
|
119
|
+
* Demonstrates how to collect information in multiple steps
|
|
120
|
+
*/
|
|
121
|
+
mcpServer.registerTool('create_event', {
|
|
122
|
+
description: 'Create a calendar event by collecting event details',
|
|
123
|
+
inputSchema: {}
|
|
124
|
+
}, async () => {
|
|
125
|
+
try {
|
|
126
|
+
// Step 1: Collect basic event information
|
|
127
|
+
const basicInfo = await mcpServer.server.elicitInput({
|
|
128
|
+
mode: 'form',
|
|
129
|
+
message: 'Step 1: Enter basic event information',
|
|
130
|
+
requestedSchema: {
|
|
131
|
+
type: 'object',
|
|
132
|
+
properties: {
|
|
133
|
+
title: {
|
|
134
|
+
type: 'string',
|
|
135
|
+
title: 'Event Title',
|
|
136
|
+
description: 'Name of the event',
|
|
137
|
+
minLength: 1
|
|
138
|
+
},
|
|
139
|
+
description: {
|
|
140
|
+
type: 'string',
|
|
141
|
+
title: 'Description',
|
|
142
|
+
description: 'Event description (optional)'
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
required: ['title']
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
if (basicInfo.action !== 'accept' || !basicInfo.content) {
|
|
149
|
+
return {
|
|
150
|
+
content: [{ type: 'text', text: 'Event creation cancelled.' }]
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
// Step 2: Collect date and time
|
|
154
|
+
const dateTime = await mcpServer.server.elicitInput({
|
|
155
|
+
mode: 'form',
|
|
156
|
+
message: 'Step 2: Enter date and time',
|
|
157
|
+
requestedSchema: {
|
|
158
|
+
type: 'object',
|
|
159
|
+
properties: {
|
|
160
|
+
date: {
|
|
161
|
+
type: 'string',
|
|
162
|
+
title: 'Date',
|
|
163
|
+
description: 'Event date',
|
|
164
|
+
format: 'date'
|
|
165
|
+
},
|
|
166
|
+
startTime: {
|
|
167
|
+
type: 'string',
|
|
168
|
+
title: 'Start Time',
|
|
169
|
+
description: 'Event start time (HH:MM)'
|
|
170
|
+
},
|
|
171
|
+
duration: {
|
|
172
|
+
type: 'integer',
|
|
173
|
+
title: 'Duration',
|
|
174
|
+
description: 'Duration in minutes',
|
|
175
|
+
minimum: 15,
|
|
176
|
+
maximum: 480
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
required: ['date', 'startTime', 'duration']
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
if (dateTime.action !== 'accept' || !dateTime.content) {
|
|
183
|
+
return {
|
|
184
|
+
content: [{ type: 'text', text: 'Event creation cancelled.' }]
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
// Combine all collected information
|
|
188
|
+
const event = {
|
|
189
|
+
...basicInfo.content,
|
|
190
|
+
...dateTime.content
|
|
191
|
+
};
|
|
82
192
|
return {
|
|
83
193
|
content: [
|
|
84
194
|
{
|
|
85
195
|
type: 'text',
|
|
86
|
-
text:
|
|
196
|
+
text: `Event created successfully!\n\n${JSON.stringify(event, null, 2)}`
|
|
87
197
|
}
|
|
88
198
|
]
|
|
89
199
|
};
|
|
90
200
|
}
|
|
91
|
-
|
|
201
|
+
catch (error) {
|
|
92
202
|
return {
|
|
93
203
|
content: [
|
|
94
204
|
{
|
|
95
205
|
type: 'text',
|
|
96
|
-
text:
|
|
206
|
+
text: `Event creation failed: ${error instanceof Error ? error.message : String(error)}`
|
|
97
207
|
}
|
|
98
|
-
]
|
|
208
|
+
],
|
|
209
|
+
isError: true
|
|
99
210
|
};
|
|
100
211
|
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
212
|
+
});
|
|
213
|
+
/**
|
|
214
|
+
* Example 3: Collecting address information
|
|
215
|
+
* Demonstrates validation with patterns and optional fields
|
|
216
|
+
*/
|
|
217
|
+
mcpServer.registerTool('update_shipping_address', {
|
|
218
|
+
description: 'Update shipping address with validation',
|
|
219
|
+
inputSchema: {}
|
|
220
|
+
}, async () => {
|
|
221
|
+
try {
|
|
222
|
+
const result = await mcpServer.server.elicitInput({
|
|
223
|
+
mode: 'form',
|
|
224
|
+
message: 'Please provide your shipping address:',
|
|
225
|
+
requestedSchema: {
|
|
226
|
+
type: 'object',
|
|
227
|
+
properties: {
|
|
228
|
+
name: {
|
|
229
|
+
type: 'string',
|
|
230
|
+
title: 'Full Name',
|
|
231
|
+
description: 'Recipient name',
|
|
232
|
+
minLength: 1
|
|
233
|
+
},
|
|
234
|
+
street: {
|
|
235
|
+
type: 'string',
|
|
236
|
+
title: 'Street Address',
|
|
237
|
+
minLength: 1
|
|
238
|
+
},
|
|
239
|
+
city: {
|
|
240
|
+
type: 'string',
|
|
241
|
+
title: 'City',
|
|
242
|
+
minLength: 1
|
|
243
|
+
},
|
|
244
|
+
state: {
|
|
245
|
+
type: 'string',
|
|
246
|
+
title: 'State/Province',
|
|
247
|
+
minLength: 2,
|
|
248
|
+
maxLength: 2
|
|
249
|
+
},
|
|
250
|
+
zipCode: {
|
|
251
|
+
type: 'string',
|
|
252
|
+
title: 'ZIP/Postal Code',
|
|
253
|
+
description: '5-digit ZIP code'
|
|
254
|
+
},
|
|
255
|
+
phone: {
|
|
256
|
+
type: 'string',
|
|
257
|
+
title: 'Phone Number (optional)',
|
|
258
|
+
description: 'Contact phone number'
|
|
259
|
+
}
|
|
135
260
|
},
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
261
|
+
required: ['name', 'street', 'city', 'state', 'zipCode']
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
if (result.action === 'accept' && result.content) {
|
|
265
|
+
return {
|
|
266
|
+
content: [
|
|
267
|
+
{
|
|
268
|
+
type: 'text',
|
|
269
|
+
text: `Address updated successfully!\n\n${JSON.stringify(result.content, null, 2)}`
|
|
270
|
+
}
|
|
271
|
+
]
|
|
272
|
+
};
|
|
143
273
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
// Step 2: Collect date and time
|
|
151
|
-
const dateTime = await mcpServer.server.elicitInput({
|
|
152
|
-
mode: 'form',
|
|
153
|
-
message: 'Step 2: Enter date and time',
|
|
154
|
-
requestedSchema: {
|
|
155
|
-
type: 'object',
|
|
156
|
-
properties: {
|
|
157
|
-
date: {
|
|
158
|
-
type: 'string',
|
|
159
|
-
title: 'Date',
|
|
160
|
-
description: 'Event date',
|
|
161
|
-
format: 'date'
|
|
162
|
-
},
|
|
163
|
-
startTime: {
|
|
164
|
-
type: 'string',
|
|
165
|
-
title: 'Start Time',
|
|
166
|
-
description: 'Event start time (HH:MM)'
|
|
167
|
-
},
|
|
168
|
-
duration: {
|
|
169
|
-
type: 'integer',
|
|
170
|
-
title: 'Duration',
|
|
171
|
-
description: 'Duration in minutes',
|
|
172
|
-
minimum: 15,
|
|
173
|
-
maximum: 480
|
|
174
|
-
}
|
|
175
|
-
},
|
|
176
|
-
required: ['date', 'startTime', 'duration']
|
|
274
|
+
else if (result.action === 'decline') {
|
|
275
|
+
return {
|
|
276
|
+
content: [{ type: 'text', text: 'Address update cancelled by user.' }]
|
|
277
|
+
};
|
|
177
278
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
// Combine all collected information
|
|
185
|
-
const event = {
|
|
186
|
-
...basicInfo.content,
|
|
187
|
-
...dateTime.content
|
|
188
|
-
};
|
|
189
|
-
return {
|
|
190
|
-
content: [
|
|
191
|
-
{
|
|
192
|
-
type: 'text',
|
|
193
|
-
text: `Event created successfully!\n\n${JSON.stringify(event, null, 2)}`
|
|
194
|
-
}
|
|
195
|
-
]
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
catch (error) {
|
|
199
|
-
return {
|
|
200
|
-
content: [
|
|
201
|
-
{
|
|
202
|
-
type: 'text',
|
|
203
|
-
text: `Event creation failed: ${error instanceof Error ? error.message : String(error)}`
|
|
204
|
-
}
|
|
205
|
-
],
|
|
206
|
-
isError: true
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
/**
|
|
211
|
-
* Example 3: Collecting address information
|
|
212
|
-
* Demonstrates validation with patterns and optional fields
|
|
213
|
-
*/
|
|
214
|
-
mcpServer.registerTool('update_shipping_address', {
|
|
215
|
-
description: 'Update shipping address with validation',
|
|
216
|
-
inputSchema: {}
|
|
217
|
-
}, async () => {
|
|
218
|
-
try {
|
|
219
|
-
const result = await mcpServer.server.elicitInput({
|
|
220
|
-
mode: 'form',
|
|
221
|
-
message: 'Please provide your shipping address:',
|
|
222
|
-
requestedSchema: {
|
|
223
|
-
type: 'object',
|
|
224
|
-
properties: {
|
|
225
|
-
name: {
|
|
226
|
-
type: 'string',
|
|
227
|
-
title: 'Full Name',
|
|
228
|
-
description: 'Recipient name',
|
|
229
|
-
minLength: 1
|
|
230
|
-
},
|
|
231
|
-
street: {
|
|
232
|
-
type: 'string',
|
|
233
|
-
title: 'Street Address',
|
|
234
|
-
minLength: 1
|
|
235
|
-
},
|
|
236
|
-
city: {
|
|
237
|
-
type: 'string',
|
|
238
|
-
title: 'City',
|
|
239
|
-
minLength: 1
|
|
240
|
-
},
|
|
241
|
-
state: {
|
|
242
|
-
type: 'string',
|
|
243
|
-
title: 'State/Province',
|
|
244
|
-
minLength: 2,
|
|
245
|
-
maxLength: 2
|
|
246
|
-
},
|
|
247
|
-
zipCode: {
|
|
248
|
-
type: 'string',
|
|
249
|
-
title: 'ZIP/Postal Code',
|
|
250
|
-
description: '5-digit ZIP code'
|
|
251
|
-
},
|
|
252
|
-
phone: {
|
|
253
|
-
type: 'string',
|
|
254
|
-
title: 'Phone Number (optional)',
|
|
255
|
-
description: 'Contact phone number'
|
|
256
|
-
}
|
|
257
|
-
},
|
|
258
|
-
required: ['name', 'street', 'city', 'state', 'zipCode']
|
|
279
|
+
else {
|
|
280
|
+
return {
|
|
281
|
+
content: [{ type: 'text', text: 'Address update was cancelled.' }]
|
|
282
|
+
};
|
|
259
283
|
}
|
|
260
|
-
}
|
|
261
|
-
|
|
284
|
+
}
|
|
285
|
+
catch (error) {
|
|
262
286
|
return {
|
|
263
287
|
content: [
|
|
264
288
|
{
|
|
265
289
|
type: 'text',
|
|
266
|
-
text: `Address
|
|
290
|
+
text: `Address update failed: ${error instanceof Error ? error.message : String(error)}`
|
|
267
291
|
}
|
|
268
|
-
]
|
|
292
|
+
],
|
|
293
|
+
isError: true
|
|
269
294
|
};
|
|
270
295
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
else {
|
|
277
|
-
return {
|
|
278
|
-
content: [{ type: 'text', text: 'Address update was cancelled.' }]
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
catch (error) {
|
|
283
|
-
return {
|
|
284
|
-
content: [
|
|
285
|
-
{
|
|
286
|
-
type: 'text',
|
|
287
|
-
text: `Address update failed: ${error instanceof Error ? error.message : String(error)}`
|
|
288
|
-
}
|
|
289
|
-
],
|
|
290
|
-
isError: true
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
});
|
|
296
|
+
});
|
|
297
|
+
return mcpServer;
|
|
298
|
+
};
|
|
294
299
|
async function main() {
|
|
295
300
|
const PORT = process.env.PORT ? parseInt(process.env.PORT, 10) : 3000;
|
|
296
301
|
const app = (0, express_js_1.createMcpExpressApp)();
|
|
@@ -326,7 +331,8 @@ async function main() {
|
|
|
326
331
|
delete transports[sid];
|
|
327
332
|
}
|
|
328
333
|
};
|
|
329
|
-
//
|
|
334
|
+
// Create a new server per session and connect it to the transport
|
|
335
|
+
const mcpServer = getServer();
|
|
330
336
|
await mcpServer.connect(transport);
|
|
331
337
|
await transport.handleRequest(req, res, req.body);
|
|
332
338
|
return;
|