@agentailor/create-mcp-server 0.7.1 → 0.9.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 +34 -11
- package/dist/assets/skills/tool-design/SKILL.md +107 -0
- package/dist/assets/skills/tool-design/references/examples.md +273 -0
- package/dist/assets/skills/tool-design/references/principles.md +261 -0
- package/dist/assets/skills/tool-design/references/testing.md +195 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +5 -3
- package/dist/cli.test.js +19 -0
- package/dist/deprecations.d.ts +7 -0
- package/dist/deprecations.js +17 -0
- package/dist/deprecations.test.d.ts +1 -0
- package/dist/deprecations.test.js +24 -0
- package/dist/index.js +1 -0
- package/dist/interactive.js +10 -2
- package/dist/project-generator.d.ts +1 -0
- package/dist/project-generator.js +30 -4
- package/dist/skills.d.ts +43 -0
- package/dist/skills.js +64 -0
- package/dist/skills.test.d.ts +1 -0
- package/dist/skills.test.js +85 -0
- package/dist/templates/common/agents.md.d.ts +9 -0
- package/dist/templates/common/agents.md.js +221 -0
- package/dist/templates/common/agents.md.test.d.ts +1 -0
- package/dist/templates/common/agents.md.test.js +142 -0
- package/dist/templates/common/package.json.js +19 -8
- package/dist/templates/common/tsconfig.json.d.ts +3 -1
- package/dist/templates/common/tsconfig.json.js +8 -2
- package/dist/templates/fastmcp/index.js +5 -3
- package/dist/templates/fastmcp/readme.js +13 -0
- package/dist/templates/sdk/stateful/auth.js +5 -1
- package/dist/templates/sdk/stateful/auth.test.js +6 -2
- package/dist/templates/sdk/stateful/index.d.ts +6 -0
- package/dist/templates/sdk/stateful/index.js +7 -1
- package/dist/templates/sdk/stateful/readme.js +1 -1
- package/dist/templates/sdk/stateful/templates.test.js +6 -7
- package/dist/templates/sdk/stateless/index.d.ts +6 -0
- package/dist/templates/sdk/stateless/index.js +10 -1
- package/dist/templates/sdk/stateless/prompts.d.ts +1 -0
- package/dist/templates/sdk/stateless/prompts.js +32 -0
- package/dist/templates/sdk/stateless/readme.js +72 -13
- package/dist/templates/sdk/stateless/resources.d.ts +1 -0
- package/dist/templates/sdk/stateless/resources.js +49 -0
- package/dist/templates/sdk/stateless/server-test.d.ts +1 -0
- package/dist/templates/sdk/stateless/server-test.js +175 -0
- package/dist/templates/sdk/stateless/server.js +14 -68
- package/dist/templates/sdk/stateless/store-test.d.ts +1 -0
- package/dist/templates/sdk/stateless/store-test.js +38 -0
- package/dist/templates/sdk/stateless/store.d.ts +1 -0
- package/dist/templates/sdk/stateless/store.js +107 -0
- package/dist/templates/sdk/stateless/templates.test.js +160 -14
- package/dist/templates/sdk/stateless/tools.d.ts +1 -0
- package/dist/templates/sdk/stateless/tools.js +172 -0
- package/dist/templates/sdk/stdio/index.d.ts +6 -0
- package/dist/templates/sdk/stdio/index.js +6 -0
- package/dist/templates/sdk/stdio/readme.js +64 -11
- package/dist/templates/sdk/stdio/templates.test.js +11 -13
- package/package.json +2 -2
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
export function getToolsTemplate() {
|
|
2
|
+
return `import type { CallToolResult, McpServer } from '@modelcontextprotocol/server';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import * as notes from './notes-store.js';
|
|
5
|
+
|
|
6
|
+
const DEFAULT_LIMIT = 20;
|
|
7
|
+
const MAX_LIMIT = 100;
|
|
8
|
+
|
|
9
|
+
// Names are action-oriented and carry their noun ("list_notes", not "list").
|
|
10
|
+
// Most MCP clients prepend the server name, so an extra "notes_" prefix here
|
|
11
|
+
// would surface as "my-server_notes_list". A bare verb would collide with every
|
|
12
|
+
// other server's "list" on the clients that do not prefix.
|
|
13
|
+
|
|
14
|
+
export function registerTools(server: McpServer): void {
|
|
15
|
+
server.registerTool(
|
|
16
|
+
'list_notes',
|
|
17
|
+
{
|
|
18
|
+
description:
|
|
19
|
+
'List saved notes, newest first, optionally filtered by tag. Use this to ' +
|
|
20
|
+
'find a note before reading or referencing it - for example "what notes do ' +
|
|
21
|
+
'I have?" or "show me my notes tagged release". Returns a page of notes ' +
|
|
22
|
+
'plus the total number that matched, so a truncated result is explicit.',
|
|
23
|
+
inputSchema: z.object({
|
|
24
|
+
tag: z
|
|
25
|
+
.string()
|
|
26
|
+
.optional()
|
|
27
|
+
.describe(
|
|
28
|
+
'Only return notes carrying this tag. Exact match, case-sensitive. ' +
|
|
29
|
+
'Example: "release". Omit to list every note.'
|
|
30
|
+
),
|
|
31
|
+
limit: z
|
|
32
|
+
.number()
|
|
33
|
+
.int()
|
|
34
|
+
.min(1)
|
|
35
|
+
.max(MAX_LIMIT)
|
|
36
|
+
.optional()
|
|
37
|
+
.describe(
|
|
38
|
+
\`Maximum notes to return. Integer between 1 and \${MAX_LIMIT}. \` +
|
|
39
|
+
\`Defaults to \${DEFAULT_LIMIT}.\`
|
|
40
|
+
),
|
|
41
|
+
}),
|
|
42
|
+
},
|
|
43
|
+
async ({ tag, limit }): Promise<CallToolResult> => {
|
|
44
|
+
const effectiveLimit = limit ?? DEFAULT_LIMIT;
|
|
45
|
+
|
|
46
|
+
let result;
|
|
47
|
+
try {
|
|
48
|
+
result = notes.list({ tag, limit: effectiveLimit });
|
|
49
|
+
} catch (error) {
|
|
50
|
+
if (error instanceof notes.UnknownTagError) {
|
|
51
|
+
// An unknown tag and a tag with no notes both produce an empty list.
|
|
52
|
+
// Saying which one happened stops the agent reporting "you have no
|
|
53
|
+
// notes" when the truth is "that tag does not exist".
|
|
54
|
+
const available = notes.knownTags();
|
|
55
|
+
return toolError(
|
|
56
|
+
\`No tag "\${error.tag}" exists, so no notes could match. \` +
|
|
57
|
+
(available.length > 0
|
|
58
|
+
? \`Available tags: \${available.join(', ')}.\`
|
|
59
|
+
: 'No notes carry tags yet.') +
|
|
60
|
+
' Call list_notes with no tag to see every note.'
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const truncated = result.total > result.rows.length;
|
|
67
|
+
|
|
68
|
+
return toolJson({
|
|
69
|
+
notes: result.rows,
|
|
70
|
+
returned: result.rows.length,
|
|
71
|
+
matched: result.total,
|
|
72
|
+
truncated,
|
|
73
|
+
...(truncated
|
|
74
|
+
? {
|
|
75
|
+
hint:
|
|
76
|
+
\`Showing \${result.rows.length} of \${result.total} matches. \` +
|
|
77
|
+
'Narrow the result with a tag filter, or raise limit ' +
|
|
78
|
+
\`(maximum \${MAX_LIMIT}).\`,
|
|
79
|
+
}
|
|
80
|
+
: {}),
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
server.registerTool(
|
|
86
|
+
'get_note',
|
|
87
|
+
{
|
|
88
|
+
description:
|
|
89
|
+
'Read one note in full by its id. Use this after list_notes has given ' +
|
|
90
|
+
'you an id. Returns the note including its body and tags.',
|
|
91
|
+
inputSchema: z.object({
|
|
92
|
+
id: z
|
|
93
|
+
.string()
|
|
94
|
+
.describe(
|
|
95
|
+
'Note id, exactly as returned by list_notes or create_note. ' +
|
|
96
|
+
'Format: "note_" followed by 8 hex characters. Example: "note_0000000a".'
|
|
97
|
+
),
|
|
98
|
+
}),
|
|
99
|
+
},
|
|
100
|
+
async ({ id }): Promise<CallToolResult> => {
|
|
101
|
+
const note = notes.get(id);
|
|
102
|
+
|
|
103
|
+
if (!note) {
|
|
104
|
+
return toolError(
|
|
105
|
+
\`No note has id "\${id}". Ids look like "note_0000000a". \` +
|
|
106
|
+
'Call list_notes to see the available notes and their ids.'
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return toolJson(note);
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
server.registerTool(
|
|
115
|
+
'create_note',
|
|
116
|
+
{
|
|
117
|
+
description:
|
|
118
|
+
'Save a new note and return it, including the id assigned to it. Use ' +
|
|
119
|
+
'the returned id to read the note back with get_note - no lookup needed.',
|
|
120
|
+
inputSchema: z.object({
|
|
121
|
+
title: z
|
|
122
|
+
.string()
|
|
123
|
+
.describe(
|
|
124
|
+
'Short title. Must be non-empty and at most ' +
|
|
125
|
+
\`\${notes.MAX_TITLE_LENGTH} characters. Example: "Ship v2 checklist".\`
|
|
126
|
+
),
|
|
127
|
+
body: z.string().describe('Note contents as plain text. May be empty.'),
|
|
128
|
+
tags: z
|
|
129
|
+
.array(z.string())
|
|
130
|
+
.optional()
|
|
131
|
+
.describe(
|
|
132
|
+
'Tags used to filter in list_notes. Lowercase, no spaces. ' +
|
|
133
|
+
'Example: ["release", "checklist"]. Defaults to no tags.'
|
|
134
|
+
),
|
|
135
|
+
}),
|
|
136
|
+
},
|
|
137
|
+
async ({ title, body, tags }): Promise<CallToolResult> => {
|
|
138
|
+
try {
|
|
139
|
+
return toolJson(notes.create({ title, body, tags }));
|
|
140
|
+
} catch (error) {
|
|
141
|
+
if (error instanceof RangeError) {
|
|
142
|
+
return toolError(
|
|
143
|
+
\`Could not save the note: \${error.message}. \` +
|
|
144
|
+
'Retry with a corrected title, for example "Ship v2 checklist".'
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
throw error;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Wraps a payload as the JSON text result an agent reads. */
|
|
154
|
+
function toolJson(payload: unknown): CallToolResult {
|
|
155
|
+
return {
|
|
156
|
+
content: [{ type: 'text', text: JSON.stringify(payload, null, 2) }],
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* An error the agent is meant to act on: it says what went wrong and what to
|
|
162
|
+
* try next. isError keeps it a normal result rather than a protocol failure,
|
|
163
|
+
* so the agent can recover instead of giving up.
|
|
164
|
+
*/
|
|
165
|
+
function toolError(message: string): CallToolResult {
|
|
166
|
+
return {
|
|
167
|
+
isError: true,
|
|
168
|
+
content: [{ type: 'text', text: message }],
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
`;
|
|
172
|
+
}
|
|
@@ -3,3 +3,9 @@ import type { SdkTemplateOptions } from '../../common/types.js';
|
|
|
3
3
|
export declare function getIndexTemplate(_options?: SdkTemplateOptions): string;
|
|
4
4
|
export { getServerTemplate } from './server.js';
|
|
5
5
|
export { getReadmeTemplate } from './readme.js';
|
|
6
|
+
export { getStoreTemplate } from '../stateless/store.js';
|
|
7
|
+
export { getToolsTemplate } from '../stateless/tools.js';
|
|
8
|
+
export { getPromptsTemplate } from '../stateless/prompts.js';
|
|
9
|
+
export { getResourcesTemplate } from '../stateless/resources.js';
|
|
10
|
+
export { getStoreTestTemplate } from '../stateless/store-test.js';
|
|
11
|
+
export { getServerTestTemplate } from '../stateless/server-test.js';
|
|
@@ -12,3 +12,9 @@ console.error('MCP Server running on stdio');
|
|
|
12
12
|
}
|
|
13
13
|
export { getServerTemplate } from './server.js';
|
|
14
14
|
export { getReadmeTemplate } from './readme.js';
|
|
15
|
+
export { getStoreTemplate } from '../stateless/store.js';
|
|
16
|
+
export { getToolsTemplate } from '../stateless/tools.js';
|
|
17
|
+
export { getPromptsTemplate } from '../stateless/prompts.js';
|
|
18
|
+
export { getResourcesTemplate } from '../stateless/resources.js';
|
|
19
|
+
export { getStoreTestTemplate } from '../stateless/store-test.js';
|
|
20
|
+
export { getServerTestTemplate } from '../stateless/server-test.js';
|
|
@@ -9,6 +9,7 @@ export function getReadmeTemplate(projectName, options) {
|
|
|
9
9
|
inspectTools: 'npm run inspect:tools',
|
|
10
10
|
inspectPrompts: 'npm run inspect:prompts',
|
|
11
11
|
inspectResources: 'npm run inspect:resources',
|
|
12
|
+
test: 'npm test',
|
|
12
13
|
},
|
|
13
14
|
pnpm: {
|
|
14
15
|
install: 'pnpm install',
|
|
@@ -18,6 +19,7 @@ export function getReadmeTemplate(projectName, options) {
|
|
|
18
19
|
inspectTools: 'pnpm inspect:tools',
|
|
19
20
|
inspectPrompts: 'pnpm inspect:prompts',
|
|
20
21
|
inspectResources: 'pnpm inspect:resources',
|
|
22
|
+
test: 'pnpm test',
|
|
21
23
|
},
|
|
22
24
|
yarn: {
|
|
23
25
|
install: 'yarn',
|
|
@@ -27,6 +29,7 @@ export function getReadmeTemplate(projectName, options) {
|
|
|
27
29
|
inspectTools: 'yarn inspect:tools',
|
|
28
30
|
inspectPrompts: 'yarn inspect:prompts',
|
|
29
31
|
inspectResources: 'yarn inspect:resources',
|
|
32
|
+
test: 'yarn test',
|
|
30
33
|
},
|
|
31
34
|
}[packageManager];
|
|
32
35
|
return `# ${projectName}
|
|
@@ -74,33 +77,67 @@ You can also call tools directly:
|
|
|
74
77
|
|
|
75
78
|
\`\`\`bash
|
|
76
79
|
# Call a tool
|
|
77
|
-
npx @modelcontextprotocol/inspector --cli node dist/index.js --method tools/call --tool-name
|
|
80
|
+
npx @modelcontextprotocol/inspector --cli node dist/index.js --method tools/call --tool-name create_note --tool-arg title="Ship v2" --tool-arg body="Draft the checklist"
|
|
78
81
|
\`\`\`
|
|
79
82
|
|
|
80
83
|
## Included Examples
|
|
81
84
|
|
|
82
|
-
|
|
85
|
+
A small notes server, included as a worked example of tools an agent can use
|
|
86
|
+
well. Notes are held in memory, so they last until the process restarts.
|
|
83
87
|
|
|
84
|
-
###
|
|
88
|
+
### Tools
|
|
85
89
|
|
|
86
|
-
- **
|
|
90
|
+
- **list_notes** - List notes, newest first, optionally filtered by tag.
|
|
91
|
+
- \`tag\` (optional): Only return notes carrying this tag
|
|
92
|
+
- \`limit\` (optional): Maximum to return, 1-100, defaults to 20
|
|
87
93
|
|
|
88
|
-
|
|
94
|
+
Returns the page plus \`matched\`, \`returned\` and \`truncated\`, so a capped
|
|
95
|
+
result says so and suggests how to narrow it. An unknown tag is reported as
|
|
96
|
+
an error listing the tags that do exist, rather than as an empty list.
|
|
89
97
|
|
|
90
|
-
- **
|
|
91
|
-
- \`
|
|
98
|
+
- **get_note** - Read one note in full by its id.
|
|
99
|
+
- \`id\`: Note id as returned by \`list_notes\` or \`create_note\`
|
|
100
|
+
|
|
101
|
+
- **create_note** - Save a note and return it, including its new id.
|
|
102
|
+
- \`title\`: Non-empty, at most 120 characters
|
|
103
|
+
- \`body\`: Plain text
|
|
104
|
+
- \`tags\` (optional): Tags used to filter in \`list_notes\`
|
|
92
105
|
|
|
93
106
|
### Resources
|
|
94
107
|
|
|
95
|
-
- **
|
|
108
|
+
- **notes://{id}** - A single note as JSON. Listing the resource enumerates
|
|
109
|
+
the saved notes.
|
|
110
|
+
|
|
111
|
+
### Prompts
|
|
112
|
+
|
|
113
|
+
- **summarize-notes** - Summarize the notes carrying a given tag
|
|
114
|
+
|
|
115
|
+
## Tests
|
|
116
|
+
|
|
117
|
+
\`\`\`bash
|
|
118
|
+
${commands.test}
|
|
119
|
+
\`\`\`
|
|
120
|
+
|
|
121
|
+
Two layers: \`src/notes-store.test.ts\` covers the data layer on its own, and
|
|
122
|
+
\`src/server.test.ts\` drives a real MCP client over an in-memory transport and
|
|
123
|
+
asserts on the payload a tool actually returns.
|
|
124
|
+
|
|
125
|
+
These are a worked example, not a quota. Each one pins something a tool's
|
|
126
|
+
description promises but nothing else checks - that a truncated list says so,
|
|
127
|
+
that an error names a next step, that an unknown filter is distinguishable from
|
|
128
|
+
an empty result. When you add a tool, one test in that spirit is enough.
|
|
96
129
|
|
|
97
130
|
## Project Structure
|
|
98
131
|
|
|
99
132
|
\`\`\`
|
|
100
133
|
${projectName}/
|
|
101
134
|
├── src/
|
|
102
|
-
│ ├── server.ts
|
|
103
|
-
│
|
|
135
|
+
│ ├── server.ts # Creates the McpServer and registers the primitives
|
|
136
|
+
│ ├── tools.ts # Tool definitions
|
|
137
|
+
│ ├── prompts.ts # Prompt definitions
|
|
138
|
+
│ ├── resources.ts # Resource definitions
|
|
139
|
+
│ ├── notes-store.ts # Example data layer, no MCP imports
|
|
140
|
+
│ └── index.ts # stdio transport startup
|
|
104
141
|
├── package.json
|
|
105
142
|
├── tsconfig.json
|
|
106
143
|
└── README.md
|
|
@@ -108,9 +145,25 @@ ${projectName}/
|
|
|
108
145
|
|
|
109
146
|
## Customization
|
|
110
147
|
|
|
111
|
-
- Add
|
|
148
|
+
- Add tools in \`src/tools.ts\`, prompts in \`src/prompts.ts\`, resources in
|
|
149
|
+
\`src/resources.ts\`. \`src/server.ts\` only wires them together.
|
|
150
|
+
- Replace the example's data layer in \`src/notes-store.ts\`. Keep it free of MCP
|
|
151
|
+
imports so it stays testable on its own.
|
|
112
152
|
- Modify transport configuration in \`src/index.ts\`
|
|
113
153
|
|
|
154
|
+
## Tool design skill
|
|
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
|
+
|
|
114
167
|
## Learn More
|
|
115
168
|
|
|
116
169
|
- [Model Context Protocol](https://modelcontextprotocol.io/)
|
|
@@ -12,20 +12,13 @@ describe('sdk/stdio templates', () => {
|
|
|
12
12
|
expect(template).toContain("from '@modelcontextprotocol/server'");
|
|
13
13
|
expect(template).not.toContain('@modelcontextprotocol/sdk');
|
|
14
14
|
});
|
|
15
|
-
|
|
15
|
+
// The server is re-exported from stateless/, so this only checks that the
|
|
16
|
+
// same composition arrives here - its detail is tested in stateless/.
|
|
17
|
+
it('should compose the shared primitives', () => {
|
|
16
18
|
const template = getServerTemplate(projectName);
|
|
17
|
-
expect(template).toContain('
|
|
18
|
-
expect(template).toContain('
|
|
19
|
-
|
|
20
|
-
it('should include example tool', () => {
|
|
21
|
-
const template = getServerTemplate(projectName);
|
|
22
|
-
expect(template).toContain('greet');
|
|
23
|
-
expect(template).toContain('registerTool');
|
|
24
|
-
});
|
|
25
|
-
it('should include example resource', () => {
|
|
26
|
-
const template = getServerTemplate(projectName);
|
|
27
|
-
expect(template).toContain('greeting-resource');
|
|
28
|
-
expect(template).toContain('registerResource');
|
|
19
|
+
expect(template).toContain('registerTools(server)');
|
|
20
|
+
expect(template).toContain('registerPrompts(server)');
|
|
21
|
+
expect(template).toContain('registerResources(server)');
|
|
29
22
|
});
|
|
30
23
|
});
|
|
31
24
|
describe('getIndexTemplate', () => {
|
|
@@ -55,6 +48,11 @@ describe('sdk/stdio templates', () => {
|
|
|
55
48
|
expect(template).toContain("console.error('MCP Server running on stdio')");
|
|
56
49
|
expect(template).not.toContain('console.log');
|
|
57
50
|
});
|
|
51
|
+
// stdout is the protocol channel here - keep dotenv off this path entirely.
|
|
52
|
+
it('should not load dotenv', () => {
|
|
53
|
+
const template = getIndexTemplate();
|
|
54
|
+
expect(template).not.toContain('dotenv');
|
|
55
|
+
});
|
|
58
56
|
});
|
|
59
57
|
describe('getReadmeTemplate', () => {
|
|
60
58
|
it('should include project name', () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentailor/create-mcp-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Create a new MCP (Model Context Protocol) server project",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"dist"
|
|
11
11
|
],
|
|
12
12
|
"scripts": {
|
|
13
|
-
"build": "tsc",
|
|
13
|
+
"build": "tsc && node scripts/copy-assets.mjs",
|
|
14
14
|
"test": "vitest run",
|
|
15
15
|
"test:watch": "vitest",
|
|
16
16
|
"lint": "eslint src/",
|