@agentailor/create-mcp-server 0.11.0 → 0.12.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/README.md +6 -0
- package/dist/cli.js +1 -1
- package/dist/project-generator.js +18 -15
- package/dist/skills.d.ts +9 -0
- package/dist/skills.js +9 -0
- package/dist/templates/common/agents.md.js +60 -3
- package/dist/templates/common/agents.md.test.js +28 -0
- package/dist/templates/common/skill-readme.d.ts +8 -0
- package/dist/templates/common/skill-readme.js +35 -0
- package/dist/templates/common/skill-readme.test.d.ts +1 -0
- package/dist/templates/common/skill-readme.test.js +25 -0
- package/dist/templates/common/types.d.ts +5 -0
- package/dist/templates/sdk/http/readme.js +9 -13
- package/dist/templates/sdk/http/server-test.js +59 -3
- package/dist/templates/sdk/http/store.js +5 -0
- package/dist/templates/sdk/http/templates.test.js +29 -0
- package/dist/templates/sdk/http/tools.js +135 -1
- package/dist/templates/sdk/stdio/readme.js +9 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -139,6 +139,12 @@ to the protocol over stdio).
|
|
|
139
139
|
- `npm test` — run the test suite
|
|
140
140
|
- `npm run inspect` — open MCP Inspector (update URL in `package.json` if needed)
|
|
141
141
|
|
|
142
|
+
## Examples
|
|
143
|
+
|
|
144
|
+
Complete servers built with the CLI, each runnable on its own:
|
|
145
|
+
|
|
146
|
+
- [notes-oauth-keycloak](examples/notes-oauth-keycloak/): `--oauth` end to end, with a local Keycloak (realm already set up) via Docker Compose and notes kept per user.
|
|
147
|
+
|
|
142
148
|
## Learning Resources
|
|
143
149
|
|
|
144
150
|
| Guide | Description |
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Command, Option, InvalidArgumentError } from 'commander';
|
|
2
2
|
const NAME_REGEX = /^[a-z0-9-_]+$/i;
|
|
3
|
-
const VERSION = '0.
|
|
3
|
+
const VERSION = '0.12.0';
|
|
4
4
|
export const FASTMCP_REMOVED_MESSAGE = [
|
|
5
5
|
'FastMCP support was removed in 0.10.0. New projects use the Official MCP SDK;',
|
|
6
6
|
'drop --framework, or pass --framework=sdk.',
|
|
@@ -17,15 +17,29 @@ export const packageManagerCommands = {
|
|
|
17
17
|
};
|
|
18
18
|
export async function generateProject(config) {
|
|
19
19
|
const { projectName, packageManager, transport, withOAuth, withGitInit, withSkills } = config;
|
|
20
|
+
const projectPath = join(process.cwd(), projectName);
|
|
21
|
+
const srcPath = join(projectPath, 'src');
|
|
22
|
+
// Create directories
|
|
23
|
+
await mkdir(srcPath, { recursive: true });
|
|
24
|
+
// The skill is vendored, so this is a file copy. It never fails the scaffold:
|
|
25
|
+
// the project is complete without it. It runs before the templates so the
|
|
26
|
+
// README and AGENTS.md describe what is actually on disk — a project without
|
|
27
|
+
// the skill must not point at a directory that does not exist.
|
|
28
|
+
let skillCopied = false;
|
|
29
|
+
if (withSkills) {
|
|
30
|
+
const result = await copySkill(projectPath);
|
|
31
|
+
skillCopied = result.copied;
|
|
32
|
+
if (!result.copied) {
|
|
33
|
+
console.log(`\n Could not add the tool-design skill (${result.reason}).`);
|
|
34
|
+
console.log(` To add it by hand: ${SKILLS_INSTALL_HINT}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
20
37
|
const templateOptions = {
|
|
21
38
|
withOAuth: transport === 'http' ? withOAuth : false,
|
|
22
39
|
packageManager,
|
|
23
40
|
transport,
|
|
41
|
+
withSkills: skillCopied,
|
|
24
42
|
};
|
|
25
|
-
const projectPath = join(process.cwd(), projectName);
|
|
26
|
-
const srcPath = join(projectPath, 'src');
|
|
27
|
-
// Create directories
|
|
28
|
-
await mkdir(srcPath, { recursive: true });
|
|
29
43
|
// Build list of files to write
|
|
30
44
|
const filesToWrite = [];
|
|
31
45
|
if (transport === 'stdio') {
|
|
@@ -59,17 +73,6 @@ export async function generateProject(config) {
|
|
|
59
73
|
console.log('\n Could not initialize git repository (is git installed?)');
|
|
60
74
|
}
|
|
61
75
|
}
|
|
62
|
-
// The skill is vendored, so this is a file copy. It never fails the scaffold:
|
|
63
|
-
// the project is complete without it.
|
|
64
|
-
let skillCopied = false;
|
|
65
|
-
if (withSkills) {
|
|
66
|
-
const result = await copySkill(projectPath);
|
|
67
|
-
skillCopied = result.copied;
|
|
68
|
-
if (!result.copied) {
|
|
69
|
-
console.log(`\n Could not add the tool-design skill (${result.reason}).`);
|
|
70
|
-
console.log(` To add it by hand: ${SKILLS_INSTALL_HINT}`);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
76
|
const commands = packageManagerCommands[packageManager];
|
|
74
77
|
console.log(`\nCreated ${projectName} with MCP SDK (${transport}) at ${projectPath}`);
|
|
75
78
|
console.log(`\nNext steps:`);
|
package/dist/skills.d.ts
CHANGED
|
@@ -23,6 +23,15 @@ export declare const SKILLS_UPDATE_COMMAND = "npx skills update -p -y";
|
|
|
23
23
|
* tool-specific directory.
|
|
24
24
|
*/
|
|
25
25
|
export declare const SKILLS_INSTALL_HINT = "npx skills add agentailor/skills --skill tool-design -a universal";
|
|
26
|
+
/** Where the skill lives upstream, for projects scaffolded without it. */
|
|
27
|
+
export declare const SKILL_URL = "https://github.com/agentailor/skills/tree/main/tool-design";
|
|
28
|
+
/**
|
|
29
|
+
* Offered to projects scaffolded with `--no-skills`.
|
|
30
|
+
*
|
|
31
|
+
* No `-a universal` here: whoever opted out of the vendored copy gets to pick
|
|
32
|
+
* which agent the skills CLI installs for.
|
|
33
|
+
*/
|
|
34
|
+
export declare const SKILLS_ADD_COMMAND = "npx skills add agentailor/skills --skill tool-design";
|
|
26
35
|
export interface SkillCopyResult {
|
|
27
36
|
copied: boolean;
|
|
28
37
|
/** Present on failure; suitable for a one-line notice. */
|
package/dist/skills.js
CHANGED
|
@@ -27,6 +27,15 @@ export const SKILLS_UPDATE_COMMAND = 'npx skills update -p -y';
|
|
|
27
27
|
* tool-specific directory.
|
|
28
28
|
*/
|
|
29
29
|
export const SKILLS_INSTALL_HINT = `npx skills add ${SKILL_REPO} --skill ${SKILL_NAME} -a universal`;
|
|
30
|
+
/** Where the skill lives upstream, for projects scaffolded without it. */
|
|
31
|
+
export const SKILL_URL = `https://github.com/${SKILL_REPO}/tree/main/${SKILL_NAME}`;
|
|
32
|
+
/**
|
|
33
|
+
* Offered to projects scaffolded with `--no-skills`.
|
|
34
|
+
*
|
|
35
|
+
* No `-a universal` here: whoever opted out of the vendored copy gets to pick
|
|
36
|
+
* which agent the skills CLI installs for.
|
|
37
|
+
*/
|
|
38
|
+
export const SKILLS_ADD_COMMAND = `npx skills add ${SKILL_REPO} --skill ${SKILL_NAME}`;
|
|
30
39
|
/**
|
|
31
40
|
* The vendored skill, copied verbatim from `agentailor/skills`.
|
|
32
41
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SKILLS_UPDATE_COMMAND, SKILLS_INSTALL_HINT, SKILLS_DIR } from '../../skills.js';
|
|
1
|
+
import { SKILLS_UPDATE_COMMAND, SKILLS_INSTALL_HINT, SKILLS_DIR, SKILLS_ADD_COMMAND, SKILL_URL, } from '../../skills.js';
|
|
2
2
|
/**
|
|
3
3
|
* AGENTS.md for the generated project.
|
|
4
4
|
*
|
|
@@ -10,6 +10,7 @@ export function getAgentsMdTemplate(projectName, options) {
|
|
|
10
10
|
const transport = options?.transport ?? 'http';
|
|
11
11
|
const withOAuth = options?.withOAuth ?? false;
|
|
12
12
|
const packageManager = options?.packageManager ?? 'npm';
|
|
13
|
+
const withSkills = options?.withSkills ?? true;
|
|
13
14
|
const isStdio = transport === 'stdio';
|
|
14
15
|
const run = {
|
|
15
16
|
npm: { build: 'npm run build', test: 'npm test', dev: 'npm run dev' },
|
|
@@ -72,6 +73,50 @@ server misconfiguration and belongs in the 500 bucket.
|
|
|
72
73
|
line, not inside it.
|
|
73
74
|
`
|
|
74
75
|
: '';
|
|
76
|
+
const elicitationSection = `
|
|
77
|
+
## Asking the user before acting
|
|
78
|
+
|
|
79
|
+
Elicitation lets a tool pause and ask the user a question through the client,
|
|
80
|
+
then finish with their answer. Reach for it when:
|
|
81
|
+
|
|
82
|
+
- **The action is consequential** — deleting, sending, paying, sharing data.
|
|
83
|
+
Confirm before acting, rather than trusting that the agent asked.
|
|
84
|
+
- **A required input is missing** and only the user knows it, such as which of
|
|
85
|
+
two accounts to use.
|
|
86
|
+
|
|
87
|
+
Do not use it for anything the agent could pass as a parameter, and **never to
|
|
88
|
+
collect passwords, API keys, tokens or other secrets** — the spec forbids it.
|
|
89
|
+
Credentials belong in an OAuth flow or in configuration.
|
|
90
|
+
|
|
91
|
+
On protocol \`2026-07-28\` the tool does not send a request mid-call. It returns
|
|
92
|
+
\`inputRequired({ inputRequests: { ... } })\`, the client asks the user, and the
|
|
93
|
+
tool is called again with the answers in \`ctx.mcpReq.inputResponses\`. Read them
|
|
94
|
+
with \`inputResponse()\` for the action and \`acceptedContent(..., schema)\` for
|
|
95
|
+
validated content. A handler written this way also serves 2025-era clients${isStdio ? '' : ' where the connection allows it'}.
|
|
96
|
+
|
|
97
|
+
Three rules keep it honest:
|
|
98
|
+
|
|
99
|
+
- **Check the capability first.** Returning \`inputRequired\` to a client that did
|
|
100
|
+
not declare \`elicitation\` fails the whole call. A \`2026-07-28\` client sends
|
|
101
|
+
its capabilities with every request (\`ctx.mcpReq.envelope\`, under
|
|
102
|
+
\`CLIENT_CAPABILITIES_META_KEY\`); a 2025-era client declared them once
|
|
103
|
+
(\`server.server.getClientCapabilities()\`). Read the first, fall back to the
|
|
104
|
+
second, and when neither has \`elicitation\`, return a result that says the
|
|
105
|
+
user could not be asked.${isStdio
|
|
106
|
+
? ''
|
|
107
|
+
: `
|
|
108
|
+
Over HTTP this is also how 2025-era clients look: each request gets a fresh
|
|
109
|
+
server, so there is no connection left to carry the question.`}
|
|
110
|
+
- **Give every outcome its own result.** Accept, decline and cancel are three
|
|
111
|
+
different answers. Anything short of an explicit yes must say nothing happened
|
|
112
|
+
and why — never a result that reads like success.
|
|
113
|
+
- **Treat the answer as input, not proof.** It arrives from the client like any
|
|
114
|
+
parameter. Validate it, and do not rely on elicitation alone where a real
|
|
115
|
+
authorization check belongs.
|
|
116
|
+
|
|
117
|
+
Keep forms to one or two fields. For a choice, use \`oneOf\` entries with
|
|
118
|
+
\`const\` and \`title\`, so clients show readable labels such as "Delete it".
|
|
119
|
+
`;
|
|
75
120
|
const testingSection = `
|
|
76
121
|
## Adding a tool means adding a test
|
|
77
122
|
|
|
@@ -139,7 +184,8 @@ Whichever shape you land on, keep two things: \`server.ts\` stays a composition
|
|
|
139
184
|
root, and domain logic stays free of MCP imports so it remains testable on its
|
|
140
185
|
own.
|
|
141
186
|
`;
|
|
142
|
-
const skillSection =
|
|
187
|
+
const skillSection = withSkills
|
|
188
|
+
? `
|
|
143
189
|
## The tool-design skill
|
|
144
190
|
|
|
145
191
|
\`${SKILLS_DIR}/skills/tool-design/SKILL.md\` is the long form of the guidance above,
|
|
@@ -159,6 +205,17 @@ That is yours to run, not something this project does for you. If the directory
|
|
|
159
205
|
is missing entirely, add it with \`${SKILLS_INSTALL_HINT}\`.
|
|
160
206
|
|
|
161
207
|
Commit \`${SKILLS_DIR}/\` so everyone working on this project gets the same copy.
|
|
208
|
+
`
|
|
209
|
+
: `
|
|
210
|
+
## The tool-design skill
|
|
211
|
+
|
|
212
|
+
The guidance above is the short form of Agentailor's
|
|
213
|
+
[tool-design](${SKILL_URL}) skill, which has the long form with worked
|
|
214
|
+
examples. It is not installed in this project. To add it:
|
|
215
|
+
|
|
216
|
+
\`\`\`bash
|
|
217
|
+
${SKILLS_ADD_COMMAND}
|
|
218
|
+
\`\`\`
|
|
162
219
|
`;
|
|
163
220
|
const conventions = `
|
|
164
221
|
## Conventions worth keeping
|
|
@@ -190,7 +247,7 @@ code.
|
|
|
190
247
|
## Layout
|
|
191
248
|
|
|
192
249
|
${layout}
|
|
193
|
-
${perRequestSection}${stdioSection}${toolDesignSection}${testingSection}${skillSection}${oauthSection}${conventions}
|
|
250
|
+
${perRequestSection}${stdioSection}${toolDesignSection}${elicitationSection}${testingSection}${skillSection}${oauthSection}${conventions}
|
|
194
251
|
## Commands
|
|
195
252
|
|
|
196
253
|
\`\`\`bash
|
|
@@ -16,6 +16,7 @@ describe('getAgentsMdTemplate', () => {
|
|
|
16
16
|
expect(template).not.toContain('list_notes');
|
|
17
17
|
expect(template).not.toContain('get_note');
|
|
18
18
|
expect(template).not.toContain('create_note');
|
|
19
|
+
expect(template).not.toContain('delete_note');
|
|
19
20
|
expect(template).not.toContain('summarize-notes');
|
|
20
21
|
}
|
|
21
22
|
});
|
|
@@ -44,6 +45,23 @@ describe('getAgentsMdTemplate', () => {
|
|
|
44
45
|
expect(template).toContain('isError');
|
|
45
46
|
expect(template).toContain('Document every parameter');
|
|
46
47
|
});
|
|
48
|
+
it('should cover elicitation for every transport', () => {
|
|
49
|
+
for (const options of [sdkHttp, sdkStdio]) {
|
|
50
|
+
const template = getAgentsMdTemplate(projectName, options);
|
|
51
|
+
expect(template).toContain('## Asking the user before acting');
|
|
52
|
+
expect(template).toContain('inputRequired');
|
|
53
|
+
expect(template).toContain('Check the capability first');
|
|
54
|
+
// The spec forbids eliciting credentials; the rule must survive edits.
|
|
55
|
+
expect(template).toContain('collect passwords, API keys, tokens or other secrets');
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
// Only HTTP serves 2025-era clients without a connection to carry the
|
|
59
|
+
// question, so only HTTP should warn about it.
|
|
60
|
+
it('should explain the HTTP-only 2025 limitation only for HTTP', () => {
|
|
61
|
+
const marker = 'no connection left to carry the question';
|
|
62
|
+
expect(getAgentsMdTemplate(projectName, sdkHttp)).toContain(marker);
|
|
63
|
+
expect(getAgentsMdTemplate(projectName, sdkStdio)).not.toContain(marker);
|
|
64
|
+
});
|
|
47
65
|
it('should say how to organize tools as they grow', () => {
|
|
48
66
|
const template = getAgentsMdTemplate(projectName, sdkHttp);
|
|
49
67
|
expect(template).toContain('Organizing tools as they grow');
|
|
@@ -115,6 +133,16 @@ describe('getAgentsMdTemplate', () => {
|
|
|
115
133
|
const template = getAgentsMdTemplate(projectName, sdkHttp);
|
|
116
134
|
expect(template).toContain('Commit `.agents/`');
|
|
117
135
|
});
|
|
136
|
+
// With --no-skills there is no .agents/ to point at; send the reader upstream.
|
|
137
|
+
it('should link upstream and give the install command when the skill is absent', () => {
|
|
138
|
+
for (const options of [sdkHttp, sdkStdio]) {
|
|
139
|
+
const template = getAgentsMdTemplate(projectName, { ...options, withSkills: false });
|
|
140
|
+
expect(template).not.toContain('.agents/');
|
|
141
|
+
expect(template).not.toContain('npx skills update');
|
|
142
|
+
expect(template).toContain('https://github.com/agentailor/skills/tree/main/tool-design');
|
|
143
|
+
expect(template).toContain('npx skills add agentailor/skills --skill tool-design');
|
|
144
|
+
}
|
|
145
|
+
});
|
|
118
146
|
// The copy is vendored, so updating is the user's choice, not automatic.
|
|
119
147
|
it("should frame the update as the reader's choice", () => {
|
|
120
148
|
const template = getAgentsMdTemplate(projectName, sdkHttp);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The README's "Tool design skill" section, shared by every transport.
|
|
3
|
+
*
|
|
4
|
+
* Branches on whether the skill is actually in the project: pointing at
|
|
5
|
+
* `.agents/skills/tool-design/` in a project scaffolded with `--no-skills` sends
|
|
6
|
+
* the reader to a directory that does not exist.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getSkillReadmeSection(withSkills: boolean): string;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { SKILLS_ADD_COMMAND, SKILLS_DIR, SKILLS_UPDATE_COMMAND, SKILL_URL } from '../../skills.js';
|
|
2
|
+
/**
|
|
3
|
+
* The README's "Tool design skill" section, shared by every transport.
|
|
4
|
+
*
|
|
5
|
+
* Branches on whether the skill is actually in the project: pointing at
|
|
6
|
+
* `.agents/skills/tool-design/` in a project scaffolded with `--no-skills` sends
|
|
7
|
+
* the reader to a directory that does not exist.
|
|
8
|
+
*/
|
|
9
|
+
export function getSkillReadmeSection(withSkills) {
|
|
10
|
+
if (!withSkills) {
|
|
11
|
+
return `## Tool design skill
|
|
12
|
+
|
|
13
|
+
Agentailor's [tool-design](${SKILL_URL}) skill gives a coding agent working here
|
|
14
|
+
detailed guidance on designing MCP tools. It is not installed in this project.
|
|
15
|
+
To add it:
|
|
16
|
+
|
|
17
|
+
\`\`\`bash
|
|
18
|
+
${SKILLS_ADD_COMMAND}
|
|
19
|
+
\`\`\`
|
|
20
|
+
`;
|
|
21
|
+
}
|
|
22
|
+
return `## Tool design skill
|
|
23
|
+
|
|
24
|
+
Agentailor's [tool-design](${SKILL_URL}) skill is
|
|
25
|
+
included at \`${SKILLS_DIR}/skills/tool-design/\`, so a coding agent working here has
|
|
26
|
+
the guidance on hand. Commit it so the whole team gets the same copy.
|
|
27
|
+
|
|
28
|
+
It is the version that shipped with the scaffolding CLI. To check for a newer
|
|
29
|
+
one — your call, not automatic:
|
|
30
|
+
|
|
31
|
+
\`\`\`bash
|
|
32
|
+
${SKILLS_UPDATE_COMMAND}
|
|
33
|
+
\`\`\`
|
|
34
|
+
`;
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { getSkillReadmeSection } from './skill-readme.js';
|
|
3
|
+
import { getReadmeTemplate as getHttpReadme } from '../sdk/http/index.js';
|
|
4
|
+
import { getReadmeTemplate as getStdioReadme } from '../sdk/stdio/index.js';
|
|
5
|
+
describe('getSkillReadmeSection', () => {
|
|
6
|
+
it('should point at the installed skill and how to update it', () => {
|
|
7
|
+
const section = getSkillReadmeSection(true);
|
|
8
|
+
expect(section).toContain('.agents/skills/tool-design/');
|
|
9
|
+
expect(section).toContain('npx skills update -p -y');
|
|
10
|
+
});
|
|
11
|
+
// A --no-skills project has no .agents/; send the reader upstream instead.
|
|
12
|
+
it('should link upstream and give the install command when the skill is absent', () => {
|
|
13
|
+
const section = getSkillReadmeSection(false);
|
|
14
|
+
expect(section).not.toContain('.agents/');
|
|
15
|
+
expect(section).not.toContain('npx skills update');
|
|
16
|
+
expect(section).toContain('https://github.com/agentailor/skills/tree/main/tool-design');
|
|
17
|
+
expect(section).toContain('npx skills add agentailor/skills --skill tool-design');
|
|
18
|
+
});
|
|
19
|
+
it('should follow withSkills in both transport READMEs', () => {
|
|
20
|
+
for (const getReadme of [getHttpReadme, getStdioReadme]) {
|
|
21
|
+
expect(getReadme('p')).toContain('.agents/skills/tool-design/');
|
|
22
|
+
expect(getReadme('p', { withSkills: false })).not.toContain('.agents/');
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -5,6 +5,11 @@ export type TransportType = 'http' | 'stdio';
|
|
|
5
5
|
*/
|
|
6
6
|
export interface BaseTemplateOptions {
|
|
7
7
|
packageManager?: PackageManager;
|
|
8
|
+
/**
|
|
9
|
+
* Whether the tool-design skill is present in the project. Defaults to true.
|
|
10
|
+
* The generator sets it from the copy's actual outcome, not just the flag.
|
|
11
|
+
*/
|
|
12
|
+
withSkills?: boolean;
|
|
8
13
|
}
|
|
9
14
|
/**
|
|
10
15
|
* Template options for SDK templates (http and stdio)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getSkillReadmeSection } from '../../common/skill-readme.js';
|
|
1
2
|
/**
|
|
2
3
|
* Shared README template, used by both SDK HTTP template types.
|
|
3
4
|
* Varies only by `options.withOAuth`.
|
|
@@ -187,6 +188,13 @@ well. Notes are held in memory, so they last until the process restarts.
|
|
|
187
188
|
- \`body\`: Plain text
|
|
188
189
|
- \`tags\` (optional): Tags used to filter in \`list_notes\`
|
|
189
190
|
|
|
191
|
+
- **delete_note** - Delete a note, after asking the user to confirm.
|
|
192
|
+
- \`id\`: Note id as returned by \`list_notes\` or \`create_note\`
|
|
193
|
+
|
|
194
|
+
Uses elicitation: the client shows the user a Delete it / Keep it choice
|
|
195
|
+
before anything happens. Declining, dismissing, or a client that cannot ask
|
|
196
|
+
all return \`deleted: false\` with the reason, never a silent success.
|
|
197
|
+
|
|
190
198
|
### Resources
|
|
191
199
|
|
|
192
200
|
- **notes://{id}** - A single note as JSON. Listing the resource enumerates
|
|
@@ -236,19 +244,7 @@ docker run -p 3000:3000 ${projectName}
|
|
|
236
244
|
instance is discarded between calls.
|
|
237
245
|
- Modify the HTTP handler and Express configuration in \`src/index.ts\`${customizationOAuthNote}
|
|
238
246
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
Agentailor's [tool-design](https://github.com/agentailor/skills) skill is
|
|
242
|
-
included at \`.agents/skills/tool-design/\`, so a coding agent working here has
|
|
243
|
-
the guidance on hand. Commit it so the whole team gets the same copy.
|
|
244
|
-
|
|
245
|
-
It is the version that shipped with the scaffolding CLI. To check for a newer
|
|
246
|
-
one — your call, not automatic:
|
|
247
|
-
|
|
248
|
-
\`\`\`bash
|
|
249
|
-
npx skills update -p -y
|
|
250
|
-
\`\`\`
|
|
251
|
-
|
|
247
|
+
${getSkillReadmeSection(options?.withSkills ?? true)}
|
|
252
248
|
## Learn More
|
|
253
249
|
|
|
254
250
|
- [Model Context Protocol](https://modelcontextprotocol.io/)
|
|
@@ -2,7 +2,7 @@ export function getServerTestTemplate() {
|
|
|
2
2
|
return `import { describe, it, expect, beforeEach } from 'vitest';
|
|
3
3
|
import { InMemoryTransport } from '@modelcontextprotocol/server';
|
|
4
4
|
import { Client } from '@modelcontextprotocol/client';
|
|
5
|
-
import type { CallToolResult } from '@modelcontextprotocol/server';
|
|
5
|
+
import type { CallToolResult, ElicitResult } from '@modelcontextprotocol/server';
|
|
6
6
|
import { getServer } from './server.js';
|
|
7
7
|
import * as notes from './notes-store.js';
|
|
8
8
|
|
|
@@ -16,9 +16,20 @@ import * as notes from './notes-store.js';
|
|
|
16
16
|
// the surface an agent reads, and a tool can be internally correct while still
|
|
17
17
|
// returning something misleading.
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Connects a client. Pass an answer to make it a client that supports
|
|
21
|
+
* elicitation: it answers every question the server asks with that result,
|
|
22
|
+
* standing in for the user.
|
|
23
|
+
*/
|
|
24
|
+
async function connect(answer?: ElicitResult): Promise<Client> {
|
|
20
25
|
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
21
|
-
const client = new Client(
|
|
26
|
+
const client = new Client(
|
|
27
|
+
{ name: 'test', version: '1.0.0' },
|
|
28
|
+
{ capabilities: answer ? { elicitation: { form: {} } } : {} }
|
|
29
|
+
);
|
|
30
|
+
if (answer) {
|
|
31
|
+
client.setRequestHandler('elicitation/create', async () => answer);
|
|
32
|
+
}
|
|
22
33
|
await Promise.all([getServer().connect(serverTransport), client.connect(clientTransport)]);
|
|
23
34
|
return client;
|
|
24
35
|
}
|
|
@@ -170,6 +181,51 @@ describe('server', () => {
|
|
|
170
181
|
const read = await client.readResource({ uri });
|
|
171
182
|
expect(JSON.parse(read.contents[0].text as string).title).toBe('Ship v2');
|
|
172
183
|
});
|
|
184
|
+
|
|
185
|
+
it('deletes only when the user says yes', async () => {
|
|
186
|
+
// Every way of not saying yes must leave the note in place and say why.
|
|
187
|
+
// A bare success here would let the agent tell the user it deleted
|
|
188
|
+
// something it did not.
|
|
189
|
+
const answers: Array<[ElicitResult, boolean]> = [
|
|
190
|
+
[{ action: 'accept', content: { decision: 'delete' } }, true],
|
|
191
|
+
[{ action: 'accept', content: { decision: 'keep' } }, false],
|
|
192
|
+
[{ action: 'decline' }, false],
|
|
193
|
+
[{ action: 'cancel' }, false],
|
|
194
|
+
];
|
|
195
|
+
|
|
196
|
+
for (const [answer, deleted] of answers) {
|
|
197
|
+
const asking = await connect(answer);
|
|
198
|
+
const note = notes.create({ title: 'Ship v2', body: '' });
|
|
199
|
+
|
|
200
|
+
const result = payload(
|
|
201
|
+
(await asking.callTool({
|
|
202
|
+
name: 'delete_note',
|
|
203
|
+
arguments: { id: note.id },
|
|
204
|
+
})) as CallToolResult
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
expect(result.deleted, answer.action).toBe(deleted);
|
|
208
|
+
expect(notes.get(note.id) === undefined).toBe(deleted);
|
|
209
|
+
if (!deleted) expect(result.reason).toBeTruthy();
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it('says so when the client cannot ask the user', async () => {
|
|
214
|
+
// Asking a client without the elicitation capability fails the call, so
|
|
215
|
+
// the tool has to notice first and explain, rather than error or guess.
|
|
216
|
+
const note = notes.create({ title: 'Ship v2', body: '' });
|
|
217
|
+
|
|
218
|
+
const result = payload(
|
|
219
|
+
(await client.callTool({
|
|
220
|
+
name: 'delete_note',
|
|
221
|
+
arguments: { id: note.id },
|
|
222
|
+
})) as CallToolResult
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
expect(result.deleted).toBe(false);
|
|
226
|
+
expect(result.reason).toContain('could not be asked');
|
|
227
|
+
expect(notes.get(note.id)).toBeDefined();
|
|
228
|
+
});
|
|
173
229
|
});
|
|
174
230
|
`;
|
|
175
231
|
}
|
|
@@ -97,6 +97,11 @@ export function create(input: { title: string; body: string; tags?: string[] }):
|
|
|
97
97
|
return note;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
/** Deletes a note. Returns false when no note had that id. */
|
|
101
|
+
export function remove(id: string): boolean {
|
|
102
|
+
return notes.delete(id);
|
|
103
|
+
}
|
|
104
|
+
|
|
100
105
|
/** Test helper: replaces all notes. Not part of the tool surface. */
|
|
101
106
|
export function seedForTests(seed: Note[]): void {
|
|
102
107
|
notes.clear();
|
|
@@ -43,6 +43,35 @@ describe('sdk/http templates', () => {
|
|
|
43
43
|
expect(template).toContain("'list_notes'");
|
|
44
44
|
expect(template).toContain("'get_note'");
|
|
45
45
|
expect(template).toContain("'create_note'");
|
|
46
|
+
expect(template).toContain("'delete_note'");
|
|
47
|
+
});
|
|
48
|
+
// delete_note is the elicitation example. These pin the parts that are
|
|
49
|
+
// easy to lose in an edit and fail quietly when they go.
|
|
50
|
+
describe('delete_note elicitation', () => {
|
|
51
|
+
it('asks with the 2026-07-28 input-required return, not a mid-call request', () => {
|
|
52
|
+
const template = getToolsTemplate();
|
|
53
|
+
expect(template).toContain('inputRequired({');
|
|
54
|
+
expect(template).toContain('inputRequired.elicit(');
|
|
55
|
+
expect(template).not.toContain('elicitInput');
|
|
56
|
+
});
|
|
57
|
+
it('checks the client capability before asking', () => {
|
|
58
|
+
// Without it, a client that cannot elicit gets a protocol error.
|
|
59
|
+
const template = getToolsTemplate();
|
|
60
|
+
expect(template).toContain('CLIENT_CAPABILITIES_META_KEY');
|
|
61
|
+
expect(template).toContain('getClientCapabilities()');
|
|
62
|
+
});
|
|
63
|
+
it('validates the answer and reports every way of not saying yes', () => {
|
|
64
|
+
const template = getToolsTemplate();
|
|
65
|
+
expect(template).toContain('acceptedContent(ctx.mcpReq.inputResponses');
|
|
66
|
+
for (const action of ['accept:', 'decline:', 'cancel:']) {
|
|
67
|
+
expect(template).toContain(action);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
it('uses a labelled single-select choice', () => {
|
|
71
|
+
const template = getToolsTemplate();
|
|
72
|
+
expect(template).toContain("{ const: 'delete', title: 'Delete it' }");
|
|
73
|
+
expect(template).toContain("{ const: 'keep', title: 'Keep it' }");
|
|
74
|
+
});
|
|
46
75
|
});
|
|
47
76
|
// Most MCP clients prepend the server name, so a hardcoded prefix would
|
|
48
77
|
// surface as "my-server_notes_list".
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
export function getToolsTemplate() {
|
|
2
|
-
return `import
|
|
2
|
+
return `import {
|
|
3
|
+
acceptedContent,
|
|
4
|
+
CLIENT_CAPABILITIES_META_KEY,
|
|
5
|
+
inputRequired,
|
|
6
|
+
inputResponse,
|
|
7
|
+
} from '@modelcontextprotocol/server';
|
|
8
|
+
import type {
|
|
9
|
+
CallToolResult,
|
|
10
|
+
ClientCapabilities,
|
|
11
|
+
InputRequiredResult,
|
|
12
|
+
McpServer,
|
|
13
|
+
ServerContext,
|
|
14
|
+
} from '@modelcontextprotocol/server';
|
|
3
15
|
import { z } from 'zod';
|
|
4
16
|
import * as notes from './notes-store.js';
|
|
5
17
|
|
|
@@ -148,6 +160,128 @@ export function registerTools(server: McpServer): void {
|
|
|
148
160
|
}
|
|
149
161
|
}
|
|
150
162
|
);
|
|
163
|
+
|
|
164
|
+
server.registerTool(
|
|
165
|
+
'delete_note',
|
|
166
|
+
{
|
|
167
|
+
description:
|
|
168
|
+
'Permanently delete a note by its id. The user is asked to confirm ' +
|
|
169
|
+
'first, and nothing is deleted without their yes. Returns deleted: true ' +
|
|
170
|
+
'when the note is gone, or deleted: false with the reason - the user ' +
|
|
171
|
+
'kept it, dismissed the question, or this client cannot ask them.',
|
|
172
|
+
inputSchema: z.object({
|
|
173
|
+
id: z
|
|
174
|
+
.string()
|
|
175
|
+
.describe(
|
|
176
|
+
'Id of the note to delete, exactly as returned by list_notes or ' +
|
|
177
|
+
'create_note. Example: "note_0000000a".'
|
|
178
|
+
),
|
|
179
|
+
}),
|
|
180
|
+
annotations: { destructiveHint: true },
|
|
181
|
+
},
|
|
182
|
+
async ({ id }, ctx): Promise<CallToolResult | InputRequiredResult> => {
|
|
183
|
+
const note = notes.get(id);
|
|
184
|
+
if (!note) {
|
|
185
|
+
return toolError(
|
|
186
|
+
\`No note has id "\${id}", so nothing was deleted. \` +
|
|
187
|
+
'Call list_notes to see the available notes and their ids.'
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Elicitation runs in two rounds. The first call has no answer yet, so
|
|
192
|
+
// the tool returns the question instead of a result. The client shows it
|
|
193
|
+
// to the user and calls the tool again with their answer attached.
|
|
194
|
+
const answer = inputResponse(ctx.mcpReq.inputResponses, CONFIRM_KEY);
|
|
195
|
+
|
|
196
|
+
if (answer.kind !== 'elicit') {
|
|
197
|
+
// Asking a client that cannot answer fails the whole call, so check
|
|
198
|
+
// first and say plainly why nothing happened.
|
|
199
|
+
if (!canAskUser(server, ctx)) {
|
|
200
|
+
return toolJson({
|
|
201
|
+
deleted: false,
|
|
202
|
+
id,
|
|
203
|
+
reason:
|
|
204
|
+
'The user could not be asked to confirm (this client or connection ' +
|
|
205
|
+
'does not support elicitation), so the note was not deleted. Ask ' +
|
|
206
|
+
'the user to delete it themselves.',
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return inputRequired({
|
|
211
|
+
inputRequests: {
|
|
212
|
+
[CONFIRM_KEY]: inputRequired.elicit({
|
|
213
|
+
message: \`Delete the note "\${note.title}"? This cannot be undone.\`,
|
|
214
|
+
requestedSchema: CONFIRM_FORM,
|
|
215
|
+
}),
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// The answer comes from the client, so validate it rather than trust it.
|
|
221
|
+
const decision = acceptedContent(ctx.mcpReq.inputResponses, CONFIRM_KEY, ConfirmAnswer);
|
|
222
|
+
|
|
223
|
+
if (decision?.decision !== 'delete') {
|
|
224
|
+
const reason =
|
|
225
|
+
answer.action === 'accept' && decision === undefined
|
|
226
|
+
? 'The answer did not match the form, so the note was kept.'
|
|
227
|
+
: NOT_DELETED[answer.action];
|
|
228
|
+
return toolJson({ deleted: false, id, reason });
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (!notes.remove(id)) {
|
|
232
|
+
return toolError(\`Note "\${id}" was already deleted.\`);
|
|
233
|
+
}
|
|
234
|
+
return toolJson({ deleted: true, id });
|
|
235
|
+
}
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const CONFIRM_KEY = 'confirm';
|
|
240
|
+
|
|
241
|
+
// The form the user sees: one required choice. oneOf with const + title is the
|
|
242
|
+
// spec's labelled single-select, so clients can show "Delete it" rather than
|
|
243
|
+
// the raw value. Keep elicitation forms this small - they interrupt the user.
|
|
244
|
+
const CONFIRM_FORM = {
|
|
245
|
+
type: 'object' as const,
|
|
246
|
+
properties: {
|
|
247
|
+
decision: {
|
|
248
|
+
type: 'string' as const,
|
|
249
|
+
title: 'Delete this note?',
|
|
250
|
+
oneOf: [
|
|
251
|
+
{ const: 'delete', title: 'Delete it' },
|
|
252
|
+
{ const: 'keep', title: 'Keep it' },
|
|
253
|
+
],
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
required: ['decision'],
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
const ConfirmAnswer = z.object({ decision: z.enum(['delete', 'keep']) });
|
|
260
|
+
|
|
261
|
+
// Each way of not saying yes gets its own reason, so the agent can report what
|
|
262
|
+
// actually happened instead of a bare "not deleted".
|
|
263
|
+
const NOT_DELETED = {
|
|
264
|
+
accept: 'The user chose to keep the note.',
|
|
265
|
+
decline: 'The user declined to delete the note.',
|
|
266
|
+
cancel: 'The user dismissed the question without answering, so the note was kept.',
|
|
267
|
+
} as const;
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* True when the client can show the user a form on this request.
|
|
271
|
+
*
|
|
272
|
+
* 2026-07-28 clients send their capabilities with every request; 2025-era
|
|
273
|
+
* clients declared them once, when they connected. Over HTTP a 2025-era client
|
|
274
|
+
* reads as unable to ask: each request gets a fresh server, so there is no
|
|
275
|
+
* connection to carry the question back.
|
|
276
|
+
*/
|
|
277
|
+
function canAskUser(server: McpServer, ctx: ServerContext): boolean {
|
|
278
|
+
const envelope = ctx.mcpReq.envelope as Record<string, unknown> | undefined;
|
|
279
|
+
const capabilities =
|
|
280
|
+
(envelope?.[CLIENT_CAPABILITIES_META_KEY] as ClientCapabilities | undefined) ??
|
|
281
|
+
server.server.getClientCapabilities();
|
|
282
|
+
const elicitation = capabilities?.elicitation;
|
|
283
|
+
// An empty elicitation capability means form mode, from before modes existed.
|
|
284
|
+
return elicitation !== undefined && (elicitation.form !== undefined || elicitation.url === undefined);
|
|
151
285
|
}
|
|
152
286
|
|
|
153
287
|
/** Wraps a payload as the JSON text result an agent reads. */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getSkillReadmeSection } from '../../common/skill-readme.js';
|
|
1
2
|
export function getReadmeTemplate(projectName, options) {
|
|
2
3
|
const packageManager = options?.packageManager ?? 'npm';
|
|
3
4
|
const commands = {
|
|
@@ -103,6 +104,13 @@ well. Notes are held in memory, so they last until the process restarts.
|
|
|
103
104
|
- \`body\`: Plain text
|
|
104
105
|
- \`tags\` (optional): Tags used to filter in \`list_notes\`
|
|
105
106
|
|
|
107
|
+
- **delete_note** - Delete a note, after asking the user to confirm.
|
|
108
|
+
- \`id\`: Note id as returned by \`list_notes\` or \`create_note\`
|
|
109
|
+
|
|
110
|
+
Uses elicitation: the client shows the user a Delete it / Keep it choice
|
|
111
|
+
before anything happens. Declining, dismissing, or a client that cannot ask
|
|
112
|
+
all return \`deleted: false\` with the reason, never a silent success.
|
|
113
|
+
|
|
106
114
|
### Resources
|
|
107
115
|
|
|
108
116
|
- **notes://{id}** - A single note as JSON. Listing the resource enumerates
|
|
@@ -151,19 +159,7 @@ ${projectName}/
|
|
|
151
159
|
imports so it stays testable on its own.
|
|
152
160
|
- Modify transport configuration in \`src/index.ts\`
|
|
153
161
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
Agentailor's [tool-design](https://github.com/agentailor/skills) skill is
|
|
157
|
-
included at \`.agents/skills/tool-design/\`, so a coding agent working here has
|
|
158
|
-
the guidance on hand. Commit it so the whole team gets the same copy.
|
|
159
|
-
|
|
160
|
-
It is the version that shipped with the scaffolding CLI. To check for a newer
|
|
161
|
-
one — your call, not automatic:
|
|
162
|
-
|
|
163
|
-
\`\`\`bash
|
|
164
|
-
npx skills update -p -y
|
|
165
|
-
\`\`\`
|
|
166
|
-
|
|
162
|
+
${getSkillReadmeSection(options?.withSkills ?? true)}
|
|
167
163
|
## Learn More
|
|
168
164
|
|
|
169
165
|
- [Model Context Protocol](https://modelcontextprotocol.io/)
|