@agentailor/create-mcp-server 0.7.0 → 0.8.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 +27 -3
- 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 +4 -2
- package/dist/cli.test.js +19 -0
- package/dist/index.js +1 -0
- package/dist/interactive.js +8 -0
- package/dist/project-generator.d.ts +1 -0
- package/dist/project-generator.js +27 -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 +19 -4
- package/dist/templates/sdk/stateful/auth.test.js +35 -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
package/dist/skills.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export declare const SKILL_REPO = "agentailor/skills";
|
|
2
|
+
export declare const SKILL_NAME = "tool-design";
|
|
3
|
+
/**
|
|
4
|
+
* Where skills go in a generated project.
|
|
5
|
+
*
|
|
6
|
+
* `.agents/` rather than `.claude/`: the ecosystem is converging on
|
|
7
|
+
* tool-agnostic locations, the same way AGENTS.md replaced CLAUDE.md. Agents
|
|
8
|
+
* that only look in `.claude/` today are expected to follow.
|
|
9
|
+
*/
|
|
10
|
+
export declare const SKILLS_DIR = ".agents";
|
|
11
|
+
/**
|
|
12
|
+
* Pulls a newer copy of the skill than the one this CLI vendored.
|
|
13
|
+
*
|
|
14
|
+
* Surfaced in the generated README and AGENTS.md. Running it is the user's
|
|
15
|
+
* choice: the vendored copy works offline and is current as of the version of
|
|
16
|
+
* this CLI they used.
|
|
17
|
+
*/
|
|
18
|
+
export declare const SKILLS_UPDATE_COMMAND = "npx skills update -p -y";
|
|
19
|
+
/**
|
|
20
|
+
* Shown if the vendored copy could not be written, so it can be added by hand.
|
|
21
|
+
*
|
|
22
|
+
* `-a universal` is what puts the skill in `.agents/` rather than a
|
|
23
|
+
* tool-specific directory.
|
|
24
|
+
*/
|
|
25
|
+
export declare const SKILLS_INSTALL_HINT = "npx skills add agentailor/skills --skill tool-design -a universal";
|
|
26
|
+
export interface SkillCopyResult {
|
|
27
|
+
copied: boolean;
|
|
28
|
+
/** Present on failure; suitable for a one-line notice. */
|
|
29
|
+
reason?: string;
|
|
30
|
+
}
|
|
31
|
+
interface SkillCopyDeps {
|
|
32
|
+
copyDir?: (from: string, to: string) => Promise<void>;
|
|
33
|
+
exists?: (path: string) => boolean;
|
|
34
|
+
sourceDir?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Writes the vendored skill into a generated project.
|
|
38
|
+
*
|
|
39
|
+
* Never throws. The project is complete and usable without the skill, so a
|
|
40
|
+
* failure here is reported and stepped over rather than failing the scaffold.
|
|
41
|
+
*/
|
|
42
|
+
export declare function copySkill(projectPath: string, deps?: SkillCopyDeps): Promise<SkillCopyResult>;
|
|
43
|
+
export {};
|
package/dist/skills.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { cp } from 'node:fs/promises';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { join, dirname } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
export const SKILL_REPO = 'agentailor/skills';
|
|
6
|
+
export const SKILL_NAME = 'tool-design';
|
|
7
|
+
/**
|
|
8
|
+
* Where skills go in a generated project.
|
|
9
|
+
*
|
|
10
|
+
* `.agents/` rather than `.claude/`: the ecosystem is converging on
|
|
11
|
+
* tool-agnostic locations, the same way AGENTS.md replaced CLAUDE.md. Agents
|
|
12
|
+
* that only look in `.claude/` today are expected to follow.
|
|
13
|
+
*/
|
|
14
|
+
export const SKILLS_DIR = '.agents';
|
|
15
|
+
/**
|
|
16
|
+
* Pulls a newer copy of the skill than the one this CLI vendored.
|
|
17
|
+
*
|
|
18
|
+
* Surfaced in the generated README and AGENTS.md. Running it is the user's
|
|
19
|
+
* choice: the vendored copy works offline and is current as of the version of
|
|
20
|
+
* this CLI they used.
|
|
21
|
+
*/
|
|
22
|
+
export const SKILLS_UPDATE_COMMAND = 'npx skills update -p -y';
|
|
23
|
+
/**
|
|
24
|
+
* Shown if the vendored copy could not be written, so it can be added by hand.
|
|
25
|
+
*
|
|
26
|
+
* `-a universal` is what puts the skill in `.agents/` rather than a
|
|
27
|
+
* tool-specific directory.
|
|
28
|
+
*/
|
|
29
|
+
export const SKILLS_INSTALL_HINT = `npx skills add ${SKILL_REPO} --skill ${SKILL_NAME} -a universal`;
|
|
30
|
+
/**
|
|
31
|
+
* The vendored skill, copied verbatim from `agentailor/skills`.
|
|
32
|
+
*
|
|
33
|
+
* Kept as real files rather than string templates: it is ~50KB of markdown
|
|
34
|
+
* full of code fences, which would need escaping in a template literal and
|
|
35
|
+
* would be unreadable and unreviewable. See "The tool-design skill" in
|
|
36
|
+
* AGENTS.md for how to refresh it.
|
|
37
|
+
*/
|
|
38
|
+
function skillSourceDir() {
|
|
39
|
+
// dist/skills.js -> dist/assets/skills/tool-design
|
|
40
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
41
|
+
return join(here, 'assets', 'skills', SKILL_NAME);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Writes the vendored skill into a generated project.
|
|
45
|
+
*
|
|
46
|
+
* Never throws. The project is complete and usable without the skill, so a
|
|
47
|
+
* failure here is reported and stepped over rather than failing the scaffold.
|
|
48
|
+
*/
|
|
49
|
+
export async function copySkill(projectPath, deps = {}) {
|
|
50
|
+
const exists = deps.exists ?? existsSync;
|
|
51
|
+
const copyDir = deps.copyDir ?? ((from, to) => cp(from, to, { recursive: true }));
|
|
52
|
+
const source = deps.sourceDir ?? skillSourceDir();
|
|
53
|
+
if (!exists(source)) {
|
|
54
|
+
return { copied: false, reason: 'the bundled skill files are missing' };
|
|
55
|
+
}
|
|
56
|
+
const destination = join(projectPath, SKILLS_DIR, 'skills', SKILL_NAME);
|
|
57
|
+
try {
|
|
58
|
+
await copyDir(source, destination);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
return { copied: false, reason: error instanceof Error ? error.message : String(error) };
|
|
62
|
+
}
|
|
63
|
+
return { copied: true };
|
|
64
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { readFile, readdir } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { copySkill, SKILL_NAME, SKILL_REPO, SKILLS_DIR, SKILLS_UPDATE_COMMAND, SKILLS_INSTALL_HINT, } from './skills.js';
|
|
5
|
+
const ASSET_DIR = join(process.cwd(), 'src', 'assets', 'skills', SKILL_NAME);
|
|
6
|
+
describe('vendored skill assets', () => {
|
|
7
|
+
it('should ship the skill and its references', async () => {
|
|
8
|
+
const root = await readdir(ASSET_DIR);
|
|
9
|
+
expect(root).toContain('SKILL.md');
|
|
10
|
+
expect(root).toContain('references');
|
|
11
|
+
const references = await readdir(join(ASSET_DIR, 'references'));
|
|
12
|
+
expect(references.sort()).toEqual(['examples.md', 'principles.md', 'testing.md']);
|
|
13
|
+
});
|
|
14
|
+
// The frontmatter is what makes it loadable as a skill rather than a doc.
|
|
15
|
+
it('should keep the skill frontmatter intact', async () => {
|
|
16
|
+
const skill = await readFile(join(ASSET_DIR, 'SKILL.md'), 'utf8');
|
|
17
|
+
// Line endings vary by checkout, so normalise before asserting.
|
|
18
|
+
expect(skill.replace(/\r\n/g, '\n').startsWith('---\n')).toBe(true);
|
|
19
|
+
expect(skill).toContain(`name: ${SKILL_NAME}`);
|
|
20
|
+
expect(skill).toContain('description:');
|
|
21
|
+
});
|
|
22
|
+
it('should be copied verbatim, not rewritten', async () => {
|
|
23
|
+
const skill = await readFile(join(ASSET_DIR, 'SKILL.md'), 'utf8');
|
|
24
|
+
// Spot-check content that would vanish if someone summarised the file.
|
|
25
|
+
expect(skill).toContain('Validation Checklist');
|
|
26
|
+
expect(skill).toContain('references/principles.md');
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
describe('commands', () => {
|
|
30
|
+
it('should point the update command at project scope, without prompting', () => {
|
|
31
|
+
expect(SKILLS_UPDATE_COMMAND).toBe('npx skills update -p -y');
|
|
32
|
+
});
|
|
33
|
+
it('should name the agentailor skill in the manual hint', () => {
|
|
34
|
+
expect(SKILLS_INSTALL_HINT).toContain(SKILL_REPO);
|
|
35
|
+
expect(SKILLS_INSTALL_HINT).toContain(SKILL_NAME);
|
|
36
|
+
});
|
|
37
|
+
// `-a universal` is what puts the skill in .agents/ rather than a
|
|
38
|
+
// tool-specific directory like .claude/.
|
|
39
|
+
it('should target the tool-agnostic directory in the manual hint', () => {
|
|
40
|
+
expect(SKILLS_INSTALL_HINT).toContain('-a universal');
|
|
41
|
+
});
|
|
42
|
+
it('should place skills in a tool-agnostic directory', () => {
|
|
43
|
+
expect(SKILLS_DIR).toBe('.agents');
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
describe('copySkill', () => {
|
|
47
|
+
it('should copy the bundled skill into the project skills directory', async () => {
|
|
48
|
+
let from;
|
|
49
|
+
let to;
|
|
50
|
+
const result = await copySkill('/project', {
|
|
51
|
+
sourceDir: '/bundled',
|
|
52
|
+
exists: () => true,
|
|
53
|
+
copyDir: async (source, destination) => {
|
|
54
|
+
from = source;
|
|
55
|
+
to = destination;
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
expect(result).toEqual({ copied: true });
|
|
59
|
+
expect(from).toBe('/bundled');
|
|
60
|
+
expect(to).toContain(join(SKILLS_DIR, 'skills', SKILL_NAME));
|
|
61
|
+
});
|
|
62
|
+
// Would mean a broken install of the CLI itself; say so rather than crashing.
|
|
63
|
+
it('should report failure when the bundled files are missing', async () => {
|
|
64
|
+
const result = await copySkill('/project', {
|
|
65
|
+
sourceDir: '/bundled',
|
|
66
|
+
exists: () => false,
|
|
67
|
+
copyDir: async () => {
|
|
68
|
+
throw new Error('should not be called');
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
expect(result.copied).toBe(false);
|
|
72
|
+
expect(result.reason).toContain('missing');
|
|
73
|
+
});
|
|
74
|
+
it('should report a copy failure rather than throwing', async () => {
|
|
75
|
+
const result = await copySkill('/project', {
|
|
76
|
+
sourceDir: '/bundled',
|
|
77
|
+
exists: () => true,
|
|
78
|
+
copyDir: async () => {
|
|
79
|
+
throw new Error('EACCES: permission denied');
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
expect(result.copied).toBe(false);
|
|
83
|
+
expect(result.reason).toContain('EACCES');
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CommonTemplateOptions } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* AGENTS.md for the generated project.
|
|
4
|
+
*
|
|
5
|
+
* Deliberately not a second README. The README explains how to run the server;
|
|
6
|
+
* this explains the things that are not obvious from reading the code, and that
|
|
7
|
+
* someone changing it will otherwise get wrong.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getAgentsMdTemplate(projectName: string, options?: CommonTemplateOptions): string;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { SKILLS_UPDATE_COMMAND, SKILLS_INSTALL_HINT, SKILLS_DIR } from '../../skills.js';
|
|
2
|
+
/**
|
|
3
|
+
* AGENTS.md for the generated project.
|
|
4
|
+
*
|
|
5
|
+
* Deliberately not a second README. The README explains how to run the server;
|
|
6
|
+
* this explains the things that are not obvious from reading the code, and that
|
|
7
|
+
* someone changing it will otherwise get wrong.
|
|
8
|
+
*/
|
|
9
|
+
export function getAgentsMdTemplate(projectName, options) {
|
|
10
|
+
const framework = options?.framework ?? 'sdk';
|
|
11
|
+
const transport = options?.transport ?? 'http';
|
|
12
|
+
const withOAuth = options?.withOAuth ?? false;
|
|
13
|
+
const packageManager = options?.packageManager ?? 'npm';
|
|
14
|
+
const isSdk = framework === 'sdk';
|
|
15
|
+
const isStdio = transport === 'stdio';
|
|
16
|
+
const run = {
|
|
17
|
+
npm: { build: 'npm run build', test: 'npm test', dev: 'npm run dev' },
|
|
18
|
+
pnpm: { build: 'pnpm build', test: 'pnpm test', dev: 'pnpm dev' },
|
|
19
|
+
yarn: { build: 'yarn build', test: 'yarn test', dev: 'yarn dev' },
|
|
20
|
+
}[packageManager];
|
|
21
|
+
const layout = isSdk
|
|
22
|
+
? `- \`src/server.ts\` — creates the \`McpServer\` and registers the primitives. It
|
|
23
|
+
should stay a composition root; definitions do not belong here.
|
|
24
|
+
- \`src/tools.ts\`, \`src/prompts.ts\`, \`src/resources.ts\` — one file per MCP
|
|
25
|
+
primitive, each exporting a \`register*(server)\` function.
|
|
26
|
+
- Your data layer — the shipped example keeps this in its own module with **no
|
|
27
|
+
MCP imports**, so it can be tested without a server. Keep that seam.
|
|
28
|
+
- \`src/index.ts\` — ${isStdio ? 'stdio transport startup' : 'Express app and HTTP handler wiring'}.${withOAuth ? '\n- `src/auth.ts` — OAuth middleware and token verification.' : ''}
|
|
29
|
+
|
|
30
|
+
The project is generated with a small example so nothing starts empty. It is
|
|
31
|
+
meant to be replaced — delete it once your own tools exist. The guidance below
|
|
32
|
+
applies to whatever replaces it.`
|
|
33
|
+
: `- \`src/server.ts\` — the FastMCP server and its tools, prompts and resources.
|
|
34
|
+
- \`src/index.ts\` — transport startup.
|
|
35
|
+
|
|
36
|
+
The project is generated with a small example so nothing starts empty. It is
|
|
37
|
+
meant to be replaced — delete it once your own tools exist.`;
|
|
38
|
+
const perRequestSection = isSdk && !isStdio
|
|
39
|
+
? `
|
|
40
|
+
## State lives in the module, not the server
|
|
41
|
+
|
|
42
|
+
\`createMcpHandler\` runs the server factory **once per request**. A fresh
|
|
43
|
+
\`McpServer\` serves every call, so anything you store on the server instance is
|
|
44
|
+
discarded when the request ends.
|
|
45
|
+
|
|
46
|
+
This is the most common way to break this project. If you add state — a cache, a
|
|
47
|
+
connection pool, a counter — put it at module scope, in its own module. State
|
|
48
|
+
created inside \`getServer()\` will silently vanish between calls: a tool that
|
|
49
|
+
writes will appear to work, and a later read will return nothing.
|
|
50
|
+
`
|
|
51
|
+
: '';
|
|
52
|
+
const stdioSection = isStdio
|
|
53
|
+
? `
|
|
54
|
+
## stdout belongs to the protocol
|
|
55
|
+
|
|
56
|
+
This server speaks MCP over stdio, so **stdout carries JSON-RPC and nothing
|
|
57
|
+
else**. A stray \`console.log\`, a banner from a library, or a debug print will
|
|
58
|
+
corrupt the stream and the client will fail to parse it.
|
|
59
|
+
|
|
60
|
+
Log to \`console.error\` instead. The same rule is why this project does not load
|
|
61
|
+
\`dotenv\` — its startup summary is noise on a channel that has to stay clean.
|
|
62
|
+
`
|
|
63
|
+
: '';
|
|
64
|
+
const oauthSection = withOAuth
|
|
65
|
+
? `
|
|
66
|
+
## OAuth: throw OAuthError, never a plain Error
|
|
67
|
+
|
|
68
|
+
\`requireBearerAuth\` maps only \`OAuthError\` to a \`401\` with a
|
|
69
|
+
\`WWW-Authenticate\` challenge. Any other thrown error becomes a \`500\` with no
|
|
70
|
+
challenge header, which leaves the client no signal that it should
|
|
71
|
+
re-authenticate — it just sees a broken server.
|
|
72
|
+
|
|
73
|
+
So every token rejection in \`src/auth.ts\` — bad signature, expired, wrong
|
|
74
|
+
issuer or audience — is converted into \`OAuthError\`. The one deliberate
|
|
75
|
+
exception is the missing-JWKS guard, which stays a plain \`Error\`: that is a
|
|
76
|
+
server misconfiguration and belongs in the 500 bucket.
|
|
77
|
+
|
|
78
|
+
\`OAuthError\` and \`OAuthErrorCode\` are **value** exports of
|
|
79
|
+
\`@modelcontextprotocol/server\`, so import them alongside the \`import type\`
|
|
80
|
+
line, not inside it.
|
|
81
|
+
`
|
|
82
|
+
: '';
|
|
83
|
+
const testingSection = isSdk
|
|
84
|
+
? `
|
|
85
|
+
## Adding a tool means adding a test
|
|
86
|
+
|
|
87
|
+
\`${run.test}\` runs two layers:
|
|
88
|
+
|
|
89
|
+
- Data-layer tests — your logic on its own, no server and no transport.
|
|
90
|
+
- \`src/server.test.ts\` — a real MCP client over an in-memory transport,
|
|
91
|
+
asserting on the **payload a tool actually returns**.
|
|
92
|
+
|
|
93
|
+
A tool description is a contract with a caller that cannot read your code. If
|
|
94
|
+
nothing checks that contract, the implementation drifts and the agent keeps
|
|
95
|
+
believing the description. That is the failure these tests exist to prevent.
|
|
96
|
+
|
|
97
|
+
**One test per tool, in that spirit, is enough.** The existing tests are a worked
|
|
98
|
+
example, not a quota to match: each pins something a description promises and
|
|
99
|
+
nothing else verifies — that a truncated list says so, that an error names a next
|
|
100
|
+
step, that an unknown filter is distinguishable from an empty result. Do not add
|
|
101
|
+
tests that exercise your data structures; those teach nothing about the tool.
|
|
102
|
+
|
|
103
|
+
Assert on the parsed payload rather than on internal calls. It is the surface the
|
|
104
|
+
agent sees, and it survives refactoring underneath.
|
|
105
|
+
`
|
|
106
|
+
: `
|
|
107
|
+
## Testing
|
|
108
|
+
|
|
109
|
+
This project ships without a test setup. If you add one, assert on the **payload
|
|
110
|
+
a tool returns** rather than on internal function calls — that is the surface an
|
|
111
|
+
agent reads, and a tool can be internally correct while returning something
|
|
112
|
+
misleading.
|
|
113
|
+
`;
|
|
114
|
+
const toolDesignSection = isSdk
|
|
115
|
+
? `
|
|
116
|
+
## Writing a good tool
|
|
117
|
+
|
|
118
|
+
A tool is a contract with a non-deterministic caller. It cannot ask what you
|
|
119
|
+
meant, so the description and the payload have to carry everything.
|
|
120
|
+
|
|
121
|
+
When adding one:
|
|
122
|
+
|
|
123
|
+
- **Name it for the action, with its noun** — \`list_invoices\`, not a bare
|
|
124
|
+
\`list\` and not \`invoices_list\`. Most MCP clients prepend the server name, so a
|
|
125
|
+
hardcoded namespace becomes \`${projectName}_invoices_list\`; a bare verb collides
|
|
126
|
+
with every other server's \`list\` on the clients that do not prefix.
|
|
127
|
+
- **Describe what it does, when to reach for it, and what it returns.** Include
|
|
128
|
+
example queries — this text is prompt engineering, not documentation.
|
|
129
|
+
- **Document every parameter with a format, an example and its constraints.**
|
|
130
|
+
\`'Invoice id as returned by list_invoices. Example: "inv_4821"'\` beats
|
|
131
|
+
\`id: string\`.
|
|
132
|
+
- **Bound anything that returns a collection.** Give it a default limit, and when
|
|
133
|
+
you truncate, *say so and say how to continue*. A silently capped list is a
|
|
134
|
+
tool that lies: the caller cannot tell a complete answer from a partial one.
|
|
135
|
+
- **Return errors as \`isError\` with a next move**, not thrown exceptions and not
|
|
136
|
+
bare codes. "No invoice has id X — call list_invoices to see the ids" is
|
|
137
|
+
actionable; "not found" is not.
|
|
138
|
+
- **Do not let two different situations produce the same payload.** An unknown
|
|
139
|
+
filter and a genuinely empty result must read differently, or the agent will
|
|
140
|
+
confidently report "you have none" when the truth is "you misspelled it".
|
|
141
|
+
- **Return what the next call needs.** If a create returns the new id, the agent
|
|
142
|
+
can chain straight into a read without a lookup.
|
|
143
|
+
|
|
144
|
+
### Organizing tools as they grow
|
|
145
|
+
|
|
146
|
+
The flat layout here suits a handful of tools. It is not meant to be permanent:
|
|
147
|
+
|
|
148
|
+
- **A few tools** — keep them in \`src/tools.ts\`, as now.
|
|
149
|
+
- **Enough that the file is hard to scan** — split into \`src/tools/\`, one file
|
|
150
|
+
per tool, with an \`index.ts\` that re-exports a single \`registerTools\`. Do the
|
|
151
|
+
same for prompts and resources when they earn it.
|
|
152
|
+
- **Several unrelated domains** — group by feature instead of by primitive:
|
|
153
|
+
\`src/invoices/{tools,resources,store}.ts\`, \`src/search/...\`, each exposing its
|
|
154
|
+
own register function that \`server.ts\` calls.
|
|
155
|
+
|
|
156
|
+
Whichever shape you land on, keep two things: \`server.ts\` stays a composition
|
|
157
|
+
root, and domain logic stays free of MCP imports so it remains testable on its
|
|
158
|
+
own.
|
|
159
|
+
`
|
|
160
|
+
: '';
|
|
161
|
+
const skillSection = `
|
|
162
|
+
## The tool-design skill
|
|
163
|
+
|
|
164
|
+
\`${SKILLS_DIR}/skills/tool-design/SKILL.md\` is the long form of the guidance above,
|
|
165
|
+
with worked examples under \`references/\`. Read it before designing a tool
|
|
166
|
+
surface, not after.
|
|
167
|
+
|
|
168
|
+
It was copied in when this project was scaffolded, so it is the version that
|
|
169
|
+
shipped with the CLI you used — no network needed, and it will not change
|
|
170
|
+
underneath you. The skill does get updated upstream. To pull a newer copy when
|
|
171
|
+
you want one:
|
|
172
|
+
|
|
173
|
+
\`\`\`bash
|
|
174
|
+
${SKILLS_UPDATE_COMMAND}
|
|
175
|
+
\`\`\`
|
|
176
|
+
|
|
177
|
+
That is yours to run, not something this project does for you. If the directory
|
|
178
|
+
is missing entirely, add it with \`${SKILLS_INSTALL_HINT}\`.
|
|
179
|
+
|
|
180
|
+
Commit \`${SKILLS_DIR}/\` so everyone working on this project gets the same copy.
|
|
181
|
+
`;
|
|
182
|
+
const conventions = isSdk
|
|
183
|
+
? `
|
|
184
|
+
## Conventions worth keeping
|
|
185
|
+
|
|
186
|
+
- This project uses the **MCP TypeScript SDK v2** split packages
|
|
187
|
+
(\`@modelcontextprotocol/server\`, \`/express\`, \`/node\`). Do not add the v1
|
|
188
|
+
\`@modelcontextprotocol/sdk\` monolith — it is a different package line.
|
|
189
|
+
- Schemas are **Standard Schema** objects: \`inputSchema: z.object({ ... })\`, not
|
|
190
|
+
a raw shape. This needs zod ≥ 4.2; zod 3 fails silently on \`tools/list\`.
|
|
191
|
+
- A tool handler's second argument is \`ctx\` (\`ctx.mcpReq.signal\`,
|
|
192
|
+
\`ctx.http?.authInfo\`), not the v1 \`extra\`.
|
|
193
|
+
- Logging, sampling and roots are deprecated in v2 — avoid \`sendLoggingMessage\`.
|
|
194
|
+
`
|
|
195
|
+
: '';
|
|
196
|
+
const commands = [
|
|
197
|
+
[run.dev, 'build and run'],
|
|
198
|
+
...(isSdk ? [[run.test, 'run the tests']] : []),
|
|
199
|
+
[run.build, 'type-check and compile'],
|
|
200
|
+
];
|
|
201
|
+
const commandWidth = Math.max(...commands.map(([cmd]) => cmd.length));
|
|
202
|
+
const commandLines = commands
|
|
203
|
+
.map(([cmd, note]) => `${cmd.padEnd(commandWidth)} # ${note}`)
|
|
204
|
+
.join('\n');
|
|
205
|
+
return `# ${projectName}
|
|
206
|
+
|
|
207
|
+
Notes for anyone — human or coding agent — working on this project. The
|
|
208
|
+
[README](README.md) covers running it; this covers what is not obvious from the
|
|
209
|
+
code.
|
|
210
|
+
|
|
211
|
+
## Layout
|
|
212
|
+
|
|
213
|
+
${layout}
|
|
214
|
+
${perRequestSection}${stdioSection}${toolDesignSection}${testingSection}${skillSection}${oauthSection}${conventions}
|
|
215
|
+
## Commands
|
|
216
|
+
|
|
217
|
+
\`\`\`bash
|
|
218
|
+
${commandLines}
|
|
219
|
+
\`\`\`
|
|
220
|
+
`;
|
|
221
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { getAgentsMdTemplate } from './agents.md.js';
|
|
3
|
+
describe('getAgentsMdTemplate', () => {
|
|
4
|
+
const projectName = 'test-project';
|
|
5
|
+
const sdkHttp = { framework: 'sdk', transport: 'http' };
|
|
6
|
+
const sdkStdio = { framework: 'sdk', transport: 'stdio' };
|
|
7
|
+
const fastmcp = { framework: 'fastmcp', transport: 'http' };
|
|
8
|
+
it('should title the document with the project name', () => {
|
|
9
|
+
expect(getAgentsMdTemplate(projectName, sdkHttp)).toContain(`# ${projectName}`);
|
|
10
|
+
});
|
|
11
|
+
// The shipped example is meant to be deleted once real tools exist, but
|
|
12
|
+
// AGENTS.md stays. Anything naming the example rots the moment it goes.
|
|
13
|
+
it('should not reference the shipped example', () => {
|
|
14
|
+
for (const options of [sdkHttp, sdkStdio, fastmcp]) {
|
|
15
|
+
const template = getAgentsMdTemplate(projectName, options);
|
|
16
|
+
expect(template).not.toContain('notes-store');
|
|
17
|
+
expect(template).not.toContain('list_notes');
|
|
18
|
+
expect(template).not.toContain('get_note');
|
|
19
|
+
expect(template).not.toContain('create_note');
|
|
20
|
+
expect(template).not.toContain('summarize-notes');
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
it('should say the example is meant to be replaced', () => {
|
|
24
|
+
for (const options of [sdkHttp, fastmcp]) {
|
|
25
|
+
expect(getAgentsMdTemplate(projectName, options)).toContain('meant to be replaced');
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
// The README covers running the project; this file covers changing it.
|
|
29
|
+
it('should point at the README rather than restate it', () => {
|
|
30
|
+
const template = getAgentsMdTemplate(projectName, sdkHttp);
|
|
31
|
+
expect(template).toContain('[README](README.md)');
|
|
32
|
+
expect(template).not.toContain('docker build');
|
|
33
|
+
expect(template).not.toContain('OAUTH_ISSUER_URL');
|
|
34
|
+
});
|
|
35
|
+
describe('tool guidance', () => {
|
|
36
|
+
it('should carry the naming rule and its reason', () => {
|
|
37
|
+
const template = getAgentsMdTemplate(projectName, sdkHttp);
|
|
38
|
+
expect(template).toContain('Name it for the action, with its noun');
|
|
39
|
+
// The generated name is interpolated so the warning is concrete.
|
|
40
|
+
expect(template).toContain(`${projectName}_invoices_list`);
|
|
41
|
+
});
|
|
42
|
+
it('should cover the contracts a description makes', () => {
|
|
43
|
+
const template = getAgentsMdTemplate(projectName, sdkHttp);
|
|
44
|
+
expect(template).toContain('say so and say how to continue');
|
|
45
|
+
expect(template).toContain('isError');
|
|
46
|
+
expect(template).toContain('Document every parameter');
|
|
47
|
+
});
|
|
48
|
+
it('should say how to organize tools as they grow', () => {
|
|
49
|
+
const template = getAgentsMdTemplate(projectName, sdkHttp);
|
|
50
|
+
expect(template).toContain('Organizing tools as they grow');
|
|
51
|
+
expect(template).toContain('src/tools/');
|
|
52
|
+
expect(template).toContain('composition root');
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
describe('per-transport guidance', () => {
|
|
56
|
+
it('should warn HTTP projects about per-request server state', () => {
|
|
57
|
+
const template = getAgentsMdTemplate(projectName, sdkHttp);
|
|
58
|
+
expect(template).toContain('once per request');
|
|
59
|
+
expect(template).toContain('module scope');
|
|
60
|
+
});
|
|
61
|
+
it('should give stdio projects the stdout rule instead', () => {
|
|
62
|
+
const template = getAgentsMdTemplate(projectName, sdkStdio);
|
|
63
|
+
expect(template).toContain('stdout belongs to the protocol');
|
|
64
|
+
expect(template).toContain('console.error');
|
|
65
|
+
expect(template).not.toContain('once per request');
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
describe('OAuth', () => {
|
|
69
|
+
it('should explain the OAuthError requirement when OAuth is enabled', () => {
|
|
70
|
+
const template = getAgentsMdTemplate(projectName, { ...sdkHttp, withOAuth: true });
|
|
71
|
+
expect(template).toContain('OAuthError');
|
|
72
|
+
expect(template).toContain('WWW-Authenticate');
|
|
73
|
+
expect(template).toContain('src/auth.ts');
|
|
74
|
+
});
|
|
75
|
+
it('should omit the OAuth section when OAuth is disabled', () => {
|
|
76
|
+
const template = getAgentsMdTemplate(projectName, sdkHttp);
|
|
77
|
+
expect(template).not.toContain('OAuthError');
|
|
78
|
+
expect(template).not.toContain('src/auth.ts');
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
describe('testing guidance', () => {
|
|
82
|
+
it('should frame the suite as an example rather than a quota', () => {
|
|
83
|
+
const template = getAgentsMdTemplate(projectName, sdkHttp);
|
|
84
|
+
expect(template).toContain('not a quota to match');
|
|
85
|
+
expect(template).toContain('src/server.test.ts');
|
|
86
|
+
});
|
|
87
|
+
it('should not promise tests FastMCP projects do not ship', () => {
|
|
88
|
+
const template = getAgentsMdTemplate(projectName, fastmcp);
|
|
89
|
+
expect(template).toContain('ships without a test setup');
|
|
90
|
+
expect(template).not.toContain('src/server.test.ts');
|
|
91
|
+
expect(template).not.toContain('npm test');
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
describe('layout', () => {
|
|
95
|
+
it('should describe the split primitives for SDK projects', () => {
|
|
96
|
+
const template = getAgentsMdTemplate(projectName, sdkHttp);
|
|
97
|
+
expect(template).toContain('src/tools.ts');
|
|
98
|
+
expect(template).toContain('MCP imports');
|
|
99
|
+
expect(template).toContain('Keep that seam');
|
|
100
|
+
});
|
|
101
|
+
it('should describe the single-file layout for FastMCP projects', () => {
|
|
102
|
+
const template = getAgentsMdTemplate(projectName, fastmcp);
|
|
103
|
+
expect(template).toContain('the FastMCP server and its tools');
|
|
104
|
+
expect(template).not.toContain('src/tools.ts');
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
describe('commands', () => {
|
|
108
|
+
it('should use the selected package manager', () => {
|
|
109
|
+
const template = getAgentsMdTemplate(projectName, { ...sdkHttp, packageManager: 'yarn' });
|
|
110
|
+
expect(template).toContain('yarn dev');
|
|
111
|
+
expect(template).toContain('yarn build');
|
|
112
|
+
expect(template).not.toContain('npm run');
|
|
113
|
+
});
|
|
114
|
+
it('should omit the test command for FastMCP projects', () => {
|
|
115
|
+
const template = getAgentsMdTemplate(projectName, fastmcp);
|
|
116
|
+
expect(template).toContain('npm run build');
|
|
117
|
+
expect(template).not.toContain('npm test');
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
describe('tool-design skill', () => {
|
|
121
|
+
it('should point at the installed skill and how to update it', () => {
|
|
122
|
+
const template = getAgentsMdTemplate(projectName, sdkHttp);
|
|
123
|
+
expect(template).toContain('.agents/skills/tool-design/SKILL.md');
|
|
124
|
+
expect(template).toContain('npx skills update -p -y');
|
|
125
|
+
});
|
|
126
|
+
it('should say how to add the skill when it is absent', () => {
|
|
127
|
+
const template = getAgentsMdTemplate(projectName, sdkHttp);
|
|
128
|
+
expect(template).toContain('npx skills add agentailor/skills --skill tool-design -a universal');
|
|
129
|
+
});
|
|
130
|
+
// The skill is meant to be shared, so .agents/ belongs in version control.
|
|
131
|
+
it('should say to commit the skill directory', () => {
|
|
132
|
+
const template = getAgentsMdTemplate(projectName, sdkHttp);
|
|
133
|
+
expect(template).toContain('Commit `.agents/`');
|
|
134
|
+
});
|
|
135
|
+
// The copy is vendored, so updating is the user's choice, not automatic.
|
|
136
|
+
it("should frame the update as the reader's choice", () => {
|
|
137
|
+
const template = getAgentsMdTemplate(projectName, sdkHttp);
|
|
138
|
+
expect(template).toContain('yours to run');
|
|
139
|
+
expect(template).toContain('shipped with the CLI you used');
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
});
|
|
@@ -2,20 +2,28 @@ export function getPackageJsonTemplate(projectName, options) {
|
|
|
2
2
|
const withOAuth = options?.withOAuth ?? false;
|
|
3
3
|
const framework = options?.framework ?? 'sdk';
|
|
4
4
|
const transport = options?.transport ?? 'http';
|
|
5
|
+
// Tests ship with SDK projects only; FastMCP has no test setup yet.
|
|
6
|
+
const withTests = framework === 'sdk';
|
|
5
7
|
let dependencies;
|
|
6
8
|
let devDependencies;
|
|
7
9
|
const commonDevDependencies = {
|
|
8
|
-
typescript: '^
|
|
9
|
-
'@modelcontextprotocol/inspector': '^2.
|
|
10
|
-
'@types/node': '^26.
|
|
10
|
+
typescript: '^7.0.2',
|
|
11
|
+
'@modelcontextprotocol/inspector': '^2.7.0',
|
|
12
|
+
'@types/node': '^26.6.2',
|
|
13
|
+
};
|
|
14
|
+
const zodDependency = { zod: '^4.6.5' };
|
|
15
|
+
const dotEnvDependency = { dotenv: '^18.0.1' };
|
|
16
|
+
// The client drives the server over an in-memory transport in the generated
|
|
17
|
+
// tests, so it must track @modelcontextprotocol/server's major.
|
|
18
|
+
const testDevDependencies = {
|
|
19
|
+
vitest: '^5.0.1',
|
|
20
|
+
'@modelcontextprotocol/client': '^2.0.0',
|
|
11
21
|
};
|
|
12
|
-
const zodDependency = { zod: '^4.4.3' };
|
|
13
|
-
const dotEnvDependency = { dotenv: '^17.4.2' };
|
|
14
22
|
if (framework === 'fastmcp') {
|
|
15
23
|
// FastMCP pulls in @modelcontextprotocol/sdk v1 itself, so this branch
|
|
16
24
|
// stays on v1 and must not gain the v2 packages.
|
|
17
25
|
dependencies = {
|
|
18
|
-
fastmcp: '^4.
|
|
26
|
+
fastmcp: '^4.20.14',
|
|
19
27
|
...zodDependency,
|
|
20
28
|
...dotEnvDependency,
|
|
21
29
|
};
|
|
@@ -32,6 +40,7 @@ export function getPackageJsonTemplate(projectName, options) {
|
|
|
32
40
|
};
|
|
33
41
|
devDependencies = {
|
|
34
42
|
...commonDevDependencies,
|
|
43
|
+
...testDevDependencies,
|
|
35
44
|
};
|
|
36
45
|
}
|
|
37
46
|
else {
|
|
@@ -42,16 +51,17 @@ export function getPackageJsonTemplate(projectName, options) {
|
|
|
42
51
|
'@modelcontextprotocol/express': '^2.0.0',
|
|
43
52
|
'@modelcontextprotocol/node': '^2.0.0',
|
|
44
53
|
express: '^5.2.1',
|
|
45
|
-
hono: '^4.
|
|
54
|
+
hono: '^4.13.8',
|
|
46
55
|
...zodDependency,
|
|
47
56
|
...dotEnvDependency,
|
|
48
57
|
};
|
|
49
58
|
if (withOAuth) {
|
|
50
|
-
dependencies['jose'] = '^6.2.
|
|
59
|
+
dependencies['jose'] = '^6.2.12';
|
|
51
60
|
}
|
|
52
61
|
devDependencies = {
|
|
53
62
|
'@types/express': '^5.0.6',
|
|
54
63
|
...commonDevDependencies,
|
|
64
|
+
...testDevDependencies,
|
|
55
65
|
};
|
|
56
66
|
}
|
|
57
67
|
const inspectScripts = transport === 'stdio'
|
|
@@ -70,6 +80,7 @@ export function getPackageJsonTemplate(projectName, options) {
|
|
|
70
80
|
build: 'tsc',
|
|
71
81
|
dev: 'tsc && node dist/index.js',
|
|
72
82
|
start: 'node dist/index.js',
|
|
83
|
+
...(withTests ? { test: 'vitest run', 'test:watch': 'vitest' } : {}),
|
|
73
84
|
...inspectScripts,
|
|
74
85
|
},
|
|
75
86
|
dependencies,
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
export function getTsconfigTemplate() {
|
|
1
|
+
export function getTsconfigTemplate(options) {
|
|
2
|
+
const withTests = options?.withTests ?? false;
|
|
3
|
+
// Test files are type-checked by the editor and by vitest, but kept out of
|
|
4
|
+
// the build so they never reach dist/ or the production Docker image.
|
|
5
|
+
const exclude = withTests
|
|
6
|
+
? ['node_modules', 'dist', 'src/**/*.test.ts']
|
|
7
|
+
: ['node_modules', 'dist'];
|
|
2
8
|
const tsconfig = {
|
|
3
9
|
compilerOptions: {
|
|
4
10
|
target: 'ES2022',
|
|
@@ -14,7 +20,7 @@ export function getTsconfigTemplate() {
|
|
|
14
20
|
types: ['node'],
|
|
15
21
|
},
|
|
16
22
|
include: ['src/**/*'],
|
|
17
|
-
exclude
|
|
23
|
+
exclude,
|
|
18
24
|
};
|
|
19
25
|
return JSON.stringify(tsconfig, null, 2) + '\n';
|
|
20
26
|
}
|