@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.
Files changed (57) hide show
  1. package/README.md +34 -11
  2. package/dist/assets/skills/tool-design/SKILL.md +107 -0
  3. package/dist/assets/skills/tool-design/references/examples.md +273 -0
  4. package/dist/assets/skills/tool-design/references/principles.md +261 -0
  5. package/dist/assets/skills/tool-design/references/testing.md +195 -0
  6. package/dist/cli.d.ts +1 -0
  7. package/dist/cli.js +5 -3
  8. package/dist/cli.test.js +19 -0
  9. package/dist/deprecations.d.ts +7 -0
  10. package/dist/deprecations.js +17 -0
  11. package/dist/deprecations.test.d.ts +1 -0
  12. package/dist/deprecations.test.js +24 -0
  13. package/dist/index.js +1 -0
  14. package/dist/interactive.js +10 -2
  15. package/dist/project-generator.d.ts +1 -0
  16. package/dist/project-generator.js +30 -4
  17. package/dist/skills.d.ts +43 -0
  18. package/dist/skills.js +64 -0
  19. package/dist/skills.test.d.ts +1 -0
  20. package/dist/skills.test.js +85 -0
  21. package/dist/templates/common/agents.md.d.ts +9 -0
  22. package/dist/templates/common/agents.md.js +221 -0
  23. package/dist/templates/common/agents.md.test.d.ts +1 -0
  24. package/dist/templates/common/agents.md.test.js +142 -0
  25. package/dist/templates/common/package.json.js +19 -8
  26. package/dist/templates/common/tsconfig.json.d.ts +3 -1
  27. package/dist/templates/common/tsconfig.json.js +8 -2
  28. package/dist/templates/fastmcp/index.js +5 -3
  29. package/dist/templates/fastmcp/readme.js +13 -0
  30. package/dist/templates/sdk/stateful/auth.js +5 -1
  31. package/dist/templates/sdk/stateful/auth.test.js +6 -2
  32. package/dist/templates/sdk/stateful/index.d.ts +6 -0
  33. package/dist/templates/sdk/stateful/index.js +7 -1
  34. package/dist/templates/sdk/stateful/readme.js +1 -1
  35. package/dist/templates/sdk/stateful/templates.test.js +6 -7
  36. package/dist/templates/sdk/stateless/index.d.ts +6 -0
  37. package/dist/templates/sdk/stateless/index.js +10 -1
  38. package/dist/templates/sdk/stateless/prompts.d.ts +1 -0
  39. package/dist/templates/sdk/stateless/prompts.js +32 -0
  40. package/dist/templates/sdk/stateless/readme.js +72 -13
  41. package/dist/templates/sdk/stateless/resources.d.ts +1 -0
  42. package/dist/templates/sdk/stateless/resources.js +49 -0
  43. package/dist/templates/sdk/stateless/server-test.d.ts +1 -0
  44. package/dist/templates/sdk/stateless/server-test.js +175 -0
  45. package/dist/templates/sdk/stateless/server.js +14 -68
  46. package/dist/templates/sdk/stateless/store-test.d.ts +1 -0
  47. package/dist/templates/sdk/stateless/store-test.js +38 -0
  48. package/dist/templates/sdk/stateless/store.d.ts +1 -0
  49. package/dist/templates/sdk/stateless/store.js +107 -0
  50. package/dist/templates/sdk/stateless/templates.test.js +160 -14
  51. package/dist/templates/sdk/stateless/tools.d.ts +1 -0
  52. package/dist/templates/sdk/stateless/tools.js +172 -0
  53. package/dist/templates/sdk/stdio/index.d.ts +6 -0
  54. package/dist/templates/sdk/stdio/index.js +6 -0
  55. package/dist/templates/sdk/stdio/readme.js +64 -11
  56. package/dist/templates/sdk/stdio/templates.test.js +11 -13
  57. package/package.json +2 -2
@@ -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: '^6.0.3',
9
- '@modelcontextprotocol/inspector': '^2.0.0',
10
- '@types/node': '^26.0.0',
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.3.2',
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.11.5',
54
+ hono: '^4.13.8',
46
55
  ...zodDependency,
47
56
  ...dotEnvDependency,
48
57
  };
49
58
  if (withOAuth) {
50
- dependencies['jose'] = '^6.2.3';
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 +1,3 @@
1
- export declare function getTsconfigTemplate(): string;
1
+ export declare function getTsconfigTemplate(options?: {
2
+ withTests?: boolean;
3
+ }): string;
@@ -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: ['node_modules', 'dist'],
23
+ exclude,
18
24
  };
19
25
  return JSON.stringify(tsconfig, null, 2) + '\n';
20
26
  }
@@ -10,9 +10,11 @@ server.start({
10
10
  }
11
11
  const stateless = options?.stateless ?? false;
12
12
  const statelessConfig = stateless ? '\n stateless: true,' : '';
13
- return `
14
- import 'dotenv/config';
15
- import { server } from './server.js';
13
+ return `import { config } from 'dotenv';
14
+ import { server } from './server.js';
15
+
16
+ // quiet: dotenv >=18 logs a summary line on load; keep startup output clean.
17
+ config({ quiet: true });
16
18
 
17
19
  const PORT = Number(process.env.PORT) || 3000;
18
20
 
@@ -118,6 +118,19 @@ ${projectName}/
118
118
  - Add new tools, prompts, and resources in \`src/server.ts\`
119
119
  - Modify transport configuration in \`src/index.ts\`
120
120
 
121
+ ## Tool design skill
122
+
123
+ Agentailor's [tool-design](https://github.com/agentailor/skills) skill is
124
+ included at \`.agents/skills/tool-design/\`, so a coding agent working here has
125
+ the guidance on hand. Commit it so the whole team gets the same copy.
126
+
127
+ It is the version that shipped with the scaffolding CLI. To check for a newer
128
+ one — your call, not automatic:
129
+
130
+ \`\`\`bash
131
+ npx skills update -p -y
132
+ \`\`\`
133
+
121
134
  ## Learn More
122
135
 
123
136
  - [FastMCP](https://github.com/punkpeye/fastmcp) - The framework powering this server
@@ -1,5 +1,5 @@
1
1
  export function getAuthTemplate() {
2
- return `import 'dotenv/config';
2
+ return `import { config } from 'dotenv';
3
3
  import { createRemoteJWKSet, jwtVerify, type JWTPayload, type JWTVerifyGetKey } from 'jose';
4
4
  import {
5
5
  mcpAuthMetadataRouter,
@@ -10,6 +10,10 @@ import { OAuthError, OAuthErrorCode } from '@modelcontextprotocol/server';
10
10
  import type { OAuthMetadata, OAuthTokenVerifier } from '@modelcontextprotocol/server';
11
11
  import type { Express, RequestHandler } from 'express';
12
12
 
13
+ // Imports are hoisted, so this runs before index.ts's own config() call - load
14
+ // the env here too, or CONFIG below reads empty values.
15
+ config({ quiet: true });
16
+
13
17
  // OAuth configuration from environment variables
14
18
  const CONFIG = {
15
19
  host: process.env.HOST || 'localhost',
@@ -7,9 +7,13 @@ describe('auth template', () => {
7
7
  expect(template).toContain('OAUTH_ISSUER_URL');
8
8
  expect(template).toContain('OAUTH_AUDIENCE');
9
9
  });
10
- it('should include dotenv import', () => {
10
+ it('should load dotenv quietly before reading CONFIG', () => {
11
11
  const template = getAuthTemplate();
12
- expect(template).toContain("import 'dotenv/config'");
12
+ expect(template).toContain("import { config } from 'dotenv'");
13
+ expect(template).toContain('config({ quiet: true })');
14
+ // Imports are hoisted, so auth.ts must load the env itself rather than
15
+ // relying on index.ts having done it.
16
+ expect(template.indexOf('config({ quiet: true })')).toBeLessThan(template.indexOf('const CONFIG'));
13
17
  });
14
18
  it('should import jose for JWT verification', () => {
15
19
  const template = getAuthTemplate();
@@ -3,3 +3,9 @@ export { getIndexTemplate } from '../stateless/index.js';
3
3
  export { getServerTemplate } from './server.js';
4
4
  export { getReadmeTemplate } from './readme.js';
5
5
  export { getAuthTemplate } from './auth.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';
@@ -1,6 +1,12 @@
1
1
  // Intentionally identical to the stateless template - see "Why stateless and
2
- // stateful are identical" in CLAUDE.md. Edit behaviour in stateless/, not here.
2
+ // stateful are identical" in AGENTS.md. Edit behaviour in stateless/, not here.
3
3
  export { getIndexTemplate } from '../stateless/index.js';
4
4
  export { getServerTemplate } from './server.js';
5
5
  export { getReadmeTemplate } from './readme.js';
6
6
  export { getAuthTemplate } from './auth.js';
7
+ export { getStoreTemplate } from '../stateless/store.js';
8
+ export { getToolsTemplate } from '../stateless/tools.js';
9
+ export { getPromptsTemplate } from '../stateless/prompts.js';
10
+ export { getResourcesTemplate } from '../stateless/resources.js';
11
+ export { getStoreTestTemplate } from '../stateless/store-test.js';
12
+ export { getServerTestTemplate } from '../stateless/server-test.js';
@@ -1,3 +1,3 @@
1
1
  // Intentionally identical to the stateless template - see "Why stateless and
2
- // stateful are identical" in CLAUDE.md. Edit behaviour in stateless/, not here.
2
+ // stateful are identical" in AGENTS.md. Edit behaviour in stateless/, not here.
3
3
  export { getReadmeTemplate } from '../stateless/readme.js';
@@ -25,14 +25,13 @@ describe('sdk/stateful templates', () => {
25
25
  expect(template).toContain("from '@modelcontextprotocol/server'");
26
26
  expect(template).not.toContain('@modelcontextprotocol/sdk');
27
27
  });
28
- it('should include example prompt, tool and resource', () => {
28
+ // The server is re-exported from stateless/, so this only checks that the
29
+ // same composition arrives here - its detail is tested in stateless/.
30
+ it('should compose the shared primitives', () => {
29
31
  const template = getServerTemplate(projectName);
30
- expect(template).toContain('greeting-template');
31
- expect(template).toContain('registerPrompt');
32
- expect(template).toContain('greet');
33
- expect(template).toContain('registerTool');
34
- expect(template).toContain('greeting-resource');
35
- expect(template).toContain('registerResource');
32
+ expect(template).toContain('registerTools(server)');
33
+ expect(template).toContain('registerPrompts(server)');
34
+ expect(template).toContain('registerResources(server)');
36
35
  });
37
36
  });
38
37
  describe('getIndexTemplate', () => {
@@ -7,3 +7,9 @@ import type { SdkTemplateOptions } from '../../common/types.js';
7
7
  export declare function getIndexTemplate(options?: SdkTemplateOptions): string;
8
8
  export { getServerTemplate } from './server.js';
9
9
  export { getReadmeTemplate } from './readme.js';
10
+ export { getStoreTemplate } from './store.js';
11
+ export { getToolsTemplate } from './tools.js';
12
+ export { getPromptsTemplate } from './prompts.js';
13
+ export { getResourcesTemplate } from './resources.js';
14
+ export { getStoreTestTemplate } from './store-test.js';
15
+ export { getServerTestTemplate } from './server-test.js';
@@ -36,13 +36,16 @@ main().catch((error) => {
36
36
  ? `
37
37
  console.log(\`OAuth metadata available at \${getOAuthMetadataUrl()}\`);`
38
38
  : '';
39
- return `import 'dotenv/config';
39
+ return `import { config } from 'dotenv';
40
40
  import { type Request, type Response } from 'express';
41
41
  import { createMcpHandler } from '@modelcontextprotocol/server';
42
42
  import { createMcpExpressApp } from '@modelcontextprotocol/express';
43
43
  import { toNodeHandler } from '@modelcontextprotocol/node';
44
44
  import { getServer } from './server.js';${authImports}
45
45
 
46
+ // quiet: dotenv >=18 logs a summary line on load; keep startup output clean.
47
+ config({ quiet: true });
48
+
46
49
  const allowedHosts = process.env.ALLOWED_HOSTS?.split(',') ?? [];
47
50
 
48
51
  const app = createMcpExpressApp({
@@ -90,3 +93,9 @@ process.on('SIGINT', async () => {
90
93
  }
91
94
  export { getServerTemplate } from './server.js';
92
95
  export { getReadmeTemplate } from './readme.js';
96
+ export { getStoreTemplate } from './store.js';
97
+ export { getToolsTemplate } from './tools.js';
98
+ export { getPromptsTemplate } from './prompts.js';
99
+ export { getResourcesTemplate } from './resources.js';
100
+ export { getStoreTestTemplate } from './store-test.js';
101
+ export { getServerTestTemplate } from './server-test.js';
@@ -0,0 +1 @@
1
+ export declare function getPromptsTemplate(): string;
@@ -0,0 +1,32 @@
1
+ export function getPromptsTemplate() {
2
+ return `import type { GetPromptResult, McpServer } from '@modelcontextprotocol/server';
3
+ import { z } from 'zod';
4
+
5
+ export function registerPrompts(server: McpServer): void {
6
+ server.registerPrompt(
7
+ 'summarize-notes',
8
+ {
9
+ description: 'Summarize the notes carrying a given tag',
10
+ argsSchema: z.object({
11
+ tag: z.string().describe('Tag to summarize, e.g. "release"'),
12
+ }),
13
+ },
14
+ async ({ tag }): Promise<GetPromptResult> => {
15
+ return {
16
+ messages: [
17
+ {
18
+ role: 'user',
19
+ content: {
20
+ type: 'text',
21
+ text:
22
+ \`Call list_notes with tag "\${tag}", then summarize those notes \` +
23
+ 'in a short paragraph. Mention how many there are.',
24
+ },
25
+ },
26
+ ],
27
+ };
28
+ }
29
+ );
30
+ }
31
+ `;
32
+ }
@@ -12,6 +12,7 @@ export function getReadmeTemplate(projectName, options) {
12
12
  build: 'npm run build',
13
13
  start: 'npm start',
14
14
  inspect: 'npm run inspect',
15
+ test: 'npm test',
15
16
  },
16
17
  pnpm: {
17
18
  install: 'pnpm install',
@@ -19,6 +20,7 @@ export function getReadmeTemplate(projectName, options) {
19
20
  build: 'pnpm build',
20
21
  start: 'pnpm start',
21
22
  inspect: 'pnpm inspect',
23
+ test: 'pnpm test',
22
24
  },
23
25
  yarn: {
24
26
  install: 'yarn',
@@ -26,6 +28,7 @@ export function getReadmeTemplate(projectName, options) {
26
28
  build: 'yarn build',
27
29
  start: 'yarn start',
28
30
  inspect: 'yarn inspect',
31
+ test: 'yarn test',
29
32
  },
30
33
  }[packageManager];
31
34
  const description = withOAuth
@@ -83,9 +86,13 @@ This server uses OAuth 2.0 with JWT tokens for authentication. It works with any
83
86
  ? `\`\`\`
84
87
  ${projectName}/
85
88
  ├── src/
86
- │ ├── server.ts # MCP server definition (tools, prompts, resources)
87
- │ ├── index.ts # Express app and MCP HTTP handler setup
88
- │ └── auth.ts # OAuth configuration and middleware
89
+ │ ├── server.ts # Creates the McpServer and registers the primitives
90
+ │ ├── tools.ts # Tool definitions
91
+ │ ├── prompts.ts # Prompt definitions
92
+ │ ├── resources.ts # Resource definitions
93
+ │ ├── notes-store.ts # Example data layer, no MCP imports
94
+ │ ├── index.ts # Express app and MCP HTTP handler setup
95
+ │ └── auth.ts # OAuth configuration and middleware
89
96
  ├── Dockerfile # Multi-stage Docker build
90
97
  ├── package.json
91
98
  ├── tsconfig.json
@@ -94,8 +101,12 @@ ${projectName}/
94
101
  : `\`\`\`
95
102
  ${projectName}/
96
103
  ├── src/
97
- │ ├── server.ts # MCP server definition (tools, prompts, resources)
98
- │ └── index.ts # Express app and MCP HTTP handler setup
104
+ │ ├── server.ts # Creates the McpServer and registers the primitives
105
+ │ ├── tools.ts # Tool definitions
106
+ │ ├── prompts.ts # Prompt definitions
107
+ │ ├── resources.ts # Resource definitions
108
+ │ ├── notes-store.ts # Example data layer, no MCP imports
109
+ │ └── index.ts # Express app and MCP HTTP handler setup
99
110
  ├── Dockerfile # Multi-stage Docker build
100
111
  ├── package.json
101
112
  ├── tsconfig.json
@@ -155,20 +166,50 @@ ${oauthSection}
155
166
 
156
167
  ## Included Examples
157
168
 
158
- This server comes with example implementations to help you get started:
169
+ A small notes server, included as a worked example of tools an agent can use
170
+ well. Notes are held in memory, so they last until the process restarts.
159
171
 
160
- ### Prompts
172
+ ### Tools
161
173
 
162
- - **greeting-template** - A simple greeting prompt that takes a name parameter
174
+ - **list_notes** - List notes, newest first, optionally filtered by tag.
175
+ - \`tag\` (optional): Only return notes carrying this tag
176
+ - \`limit\` (optional): Maximum to return, 1-100, defaults to 20
163
177
 
164
- ### Tools
178
+ Returns the page plus \`matched\`, \`returned\` and \`truncated\`, so a capped
179
+ result says so and suggests how to narrow it. An unknown tag is reported as
180
+ an error listing the tags that do exist, rather than as an empty list.
165
181
 
166
- - **greet** - Greets a user by name. Parameters:
167
- - \`name\`: Name of the person to greet
182
+ - **get_note** - Read one note in full by its id.
183
+ - \`id\`: Note id as returned by \`list_notes\` or \`create_note\`
184
+
185
+ - **create_note** - Save a note and return it, including its new id.
186
+ - \`title\`: Non-empty, at most 120 characters
187
+ - \`body\`: Plain text
188
+ - \`tags\` (optional): Tags used to filter in \`list_notes\`
168
189
 
169
190
  ### Resources
170
191
 
171
- - **greeting-resource** - A simple text resource at \`https://example.com/greetings/default\`
192
+ - **notes://{id}** - A single note as JSON. Listing the resource enumerates
193
+ the saved notes.
194
+
195
+ ### Prompts
196
+
197
+ - **summarize-notes** - Summarize the notes carrying a given tag
198
+
199
+ ## Tests
200
+
201
+ \`\`\`bash
202
+ ${commands.test}
203
+ \`\`\`
204
+
205
+ Two layers: \`src/notes-store.test.ts\` covers the data layer on its own, and
206
+ \`src/server.test.ts\` drives a real MCP client over an in-memory transport and
207
+ asserts on the payload a tool actually returns.
208
+
209
+ These are a worked example, not a quota. Each one pins something a tool's
210
+ description promises but nothing else checks - that a truncated list says so,
211
+ that an error names a next step, that an unknown filter is distinguishable from
212
+ an empty result. When you add a tool, one test in that spirit is enough.
172
213
 
173
214
  ## Project Structure
174
215
 
@@ -187,9 +228,27 @@ docker run -p 3000:3000 ${projectName}
187
228
 
188
229
  ## Customization
189
230
 
190
- - Add new tools, prompts, and resources in \`src/server.ts\`
231
+ - Add tools in \`src/tools.ts\`, prompts in \`src/prompts.ts\`, resources in
232
+ \`src/resources.ts\`. \`src/server.ts\` only wires them together.
233
+ - Replace the example's data layer in \`src/notes-store.ts\`. Keep it free of MCP
234
+ imports so it stays testable on its own, and keep its state at module scope:
235
+ the server factory runs once per request, so anything held on the server
236
+ instance is discarded between calls.
191
237
  - Modify the HTTP handler and Express configuration in \`src/index.ts\`${customizationOAuthNote}
192
238
 
239
+ ## Tool design skill
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
+
193
252
  ## Learn More
194
253
 
195
254
  - [Model Context Protocol](https://modelcontextprotocol.io/)
@@ -0,0 +1 @@
1
+ export declare function getResourcesTemplate(): string;
@@ -0,0 +1,49 @@
1
+ export function getResourcesTemplate() {
2
+ return `import type { McpServer, ReadResourceResult } from '@modelcontextprotocol/server';
3
+ import { ResourceTemplate } from '@modelcontextprotocol/server';
4
+ import * as notes from './notes-store.js';
5
+
6
+ const MAX_LISTED = 100;
7
+
8
+ export function registerResources(server: McpServer): void {
9
+ server.registerResource(
10
+ 'note',
11
+ // \`list\` is a required key on this options object, not an optional one -
12
+ // omitting it fails to compile. Implementing it also lets clients enumerate
13
+ // the notes instead of only reading one by id.
14
+ new ResourceTemplate('notes://{id}', {
15
+ list: async () => ({
16
+ resources: notes.list({ limit: MAX_LISTED }).rows.map((note) => ({
17
+ uri: \`notes://\${note.id}\`,
18
+ name: note.title,
19
+ mimeType: 'application/json',
20
+ })),
21
+ }),
22
+ }),
23
+ {
24
+ title: 'Note',
25
+ description: 'A single saved note, addressed by its id.',
26
+ mimeType: 'application/json',
27
+ },
28
+ async (uri, variables): Promise<ReadResourceResult> => {
29
+ const id = String(variables.id);
30
+ const note = notes.get(id);
31
+
32
+ if (!note) {
33
+ throw new Error(\`No note has id "\${id}"\`);
34
+ }
35
+
36
+ return {
37
+ contents: [
38
+ {
39
+ uri: uri.href,
40
+ mimeType: 'application/json',
41
+ text: JSON.stringify(note, null, 2),
42
+ },
43
+ ],
44
+ };
45
+ }
46
+ );
47
+ }
48
+ `;
49
+ }
@@ -0,0 +1 @@
1
+ export declare function getServerTestTemplate(): string;