@jrmc/adonis-mcp 1.0.0-beta.4 → 1.0.0-beta.6

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 (77) hide show
  1. package/README.md +25 -5
  2. package/build/configure.d.ts.map +1 -1
  3. package/build/configure.js +5 -1
  4. package/build/providers/mcp_provider.d.ts.map +1 -1
  5. package/build/providers/mcp_provider.js +14 -5
  6. package/build/providers/vinejs_provider.d.ts +13 -0
  7. package/build/providers/vinejs_provider.d.ts.map +1 -0
  8. package/build/providers/vinejs_provider.js +10 -0
  9. package/build/src/request.d.ts +6 -2
  10. package/build/src/request.d.ts.map +1 -1
  11. package/build/src/request.js +6 -2
  12. package/build/src/response.d.ts +1 -1
  13. package/build/src/response.d.ts.map +1 -1
  14. package/build/src/response.js +1 -1
  15. package/build/src/server/annotations/is_destructive.d.ts +1 -1
  16. package/build/src/server/annotations/is_destructive.d.ts.map +1 -1
  17. package/build/src/server/annotations/is_idempotent.d.ts +1 -1
  18. package/build/src/server/annotations/is_idempotent.d.ts.map +1 -1
  19. package/build/src/server/annotations/is_open_world.d.ts +1 -1
  20. package/build/src/server/annotations/is_open_world.d.ts.map +1 -1
  21. package/build/src/server/annotations/is_read_only.d.ts +1 -1
  22. package/build/src/server/annotations/is_read_only.d.ts.map +1 -1
  23. package/build/src/server/contents/embedded_resource.js +1 -1
  24. package/build/src/server/contents/error.d.ts +5 -0
  25. package/build/src/server/contents/error.d.ts.map +1 -1
  26. package/build/src/server/contents/error.js +10 -1
  27. package/build/src/server/contents/resource_link.js +1 -1
  28. package/build/src/server/context.d.ts +1 -3
  29. package/build/src/server/context.d.ts.map +1 -1
  30. package/build/src/server/context.js +3 -21
  31. package/build/src/server/contracts/context.d.ts +2 -3
  32. package/build/src/server/contracts/context.d.ts.map +1 -1
  33. package/build/src/server/contracts/request.d.ts +12 -0
  34. package/build/src/server/contracts/request.d.ts.map +1 -0
  35. package/build/src/server/contracts/request.js +1 -0
  36. package/build/src/server/contracts/response.d.ts +1 -1
  37. package/build/src/server/contracts/response.d.ts.map +1 -1
  38. package/build/src/server/exceptions/jsonrpc_error.d.ts +7 -0
  39. package/build/src/server/exceptions/jsonrpc_error.d.ts.map +1 -0
  40. package/build/src/server/exceptions/jsonrpc_error.js +10 -0
  41. package/build/src/server/methods/call_tool.d.ts.map +1 -1
  42. package/build/src/server/methods/call_tool.js +13 -4
  43. package/build/src/server/methods/completion.js +5 -5
  44. package/build/src/server/methods/get_prompt.js +3 -3
  45. package/build/src/server/methods/list_prompts.d.ts.map +1 -1
  46. package/build/src/server/methods/list_prompts.js +1 -12
  47. package/build/src/server/methods/list_resource_templates.d.ts.map +1 -1
  48. package/build/src/server/methods/list_resource_templates.js +2 -13
  49. package/build/src/server/methods/list_resources.d.ts.map +1 -1
  50. package/build/src/server/methods/list_resources.js +2 -13
  51. package/build/src/server/methods/list_tools.d.ts.map +1 -1
  52. package/build/src/server/methods/list_tools.js +1 -12
  53. package/build/src/server/methods/read_resource.d.ts.map +1 -1
  54. package/build/src/server/methods/read_resource.js +11 -4
  55. package/build/src/server/pagination/cursor_paginator.d.ts +6 -4
  56. package/build/src/server/pagination/cursor_paginator.d.ts.map +1 -1
  57. package/build/src/server/pagination/cursor_paginator.js +4 -4
  58. package/build/src/server/prompt.d.ts +2 -1
  59. package/build/src/server/prompt.d.ts.map +1 -1
  60. package/build/src/server/requests/request_validator.d.ts +15 -0
  61. package/build/src/server/requests/request_validator.d.ts.map +1 -0
  62. package/build/src/server/requests/request_validator.js +25 -0
  63. package/build/src/server.d.ts +2 -0
  64. package/build/src/server.d.ts.map +1 -1
  65. package/build/src/server.js +5 -0
  66. package/build/src/types/context.d.ts +7 -6
  67. package/build/src/types/context.d.ts.map +1 -1
  68. package/build/src/types/method.d.ts +19 -11
  69. package/build/src/types/method.d.ts.map +1 -1
  70. package/build/src/types/request.d.ts +25 -2
  71. package/build/src/types/request.d.ts.map +1 -1
  72. package/build/src/types/response.d.ts +10 -3
  73. package/build/src/types/response.d.ts.map +1 -1
  74. package/build/src/utils/find_resource_pattern.js +1 -1
  75. package/build/stubs/make/mcp/prompts/main.ts.stub +2 -2
  76. package/build/tsconfig.tsbuildinfo +1 -1
  77. package/package.json +6 -2
@@ -4,8 +4,6 @@
4
4
  * @license MIT
5
5
  * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
6
  */
7
- import { ErrorCode } from '../../enums/error.js';
8
- import JsonRpcException from '../exceptions/jsonrpc_exception.js';
9
7
  import { CursorPaginator } from '../pagination/cursor_paginator.js';
10
8
  import Response from '../../response.js';
11
9
  export default class ListPrompts {
@@ -13,16 +11,7 @@ export default class ListPrompts {
13
11
  let nextCursor;
14
12
  const paginator = new CursorPaginator(Object.values(ctx.prompts), ctx.getPerPage(), ctx.request.params?.cursor);
15
13
  const paginatedPrompts = paginator.paginate('prompts');
16
- const prompts = await Promise.all(paginatedPrompts['prompts'].map(async (filepath) => {
17
- try {
18
- const { default: Prompt } = await import(filepath);
19
- const prompt = new Prompt();
20
- return prompt.toJson();
21
- }
22
- catch (error) {
23
- throw new JsonRpcException(`Error listing prompt`, ErrorCode.InternalError, ctx.request.id, { error });
24
- }
25
- }));
14
+ const prompts = paginatedPrompts['prompts'].map((entry) => entry.json);
26
15
  if (paginatedPrompts.nextCursor) {
27
16
  nextCursor = paginatedPrompts.nextCursor;
28
17
  }
@@ -1 +1 @@
1
- {"version":3,"file":"list_resource_templates.d.ts","sourceRoot":"","sources":["../../../../src/server/methods/list_resource_templates.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAOnD,MAAM,CAAC,OAAO,OAAO,qBAAsB,YAAW,MAAM;IACpD,MAAM,CAAC,GAAG,EAAE,UAAU;CAoC7B"}
1
+ {"version":3,"file":"list_resource_templates.d.ts","sourceRoot":"","sources":["../../../../src/server/methods/list_resource_templates.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,KAAK,EAAE,MAAM,EAAoB,MAAM,uBAAuB,CAAA;AAKrE,MAAM,CAAC,OAAO,OAAO,qBAAsB,YAAW,MAAM;IACpD,MAAM,CAAC,GAAG,EAAE,UAAU;CAuB7B"}
@@ -4,25 +4,14 @@
4
4
  * @license MIT
5
5
  * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
6
  */
7
- import { ErrorCode } from '../../enums/error.js';
8
- import JsonRpcException from '../exceptions/jsonrpc_exception.js';
9
7
  import { CursorPaginator } from '../pagination/cursor_paginator.js';
10
8
  import Response from '../../response.js';
11
9
  export default class ListResourceTemplates {
12
10
  async handle(ctx) {
13
11
  let nextCursor;
14
- const paginator = new CursorPaginator(Object.values(await ctx.getResourceTemplates()), ctx.getPerPage(), ctx.request.params?.cursor);
12
+ const paginator = new CursorPaginator(Object.values(ctx.resourceTemplates), ctx.getPerPage(), ctx.request.params?.cursor);
15
13
  const paginatedResources = paginator.paginate('resourceTemplates');
16
- const resourceTemplates = await Promise.all(paginatedResources['resourceTemplates'].map(async (filepath) => {
17
- try {
18
- const { default: Resource } = await import(filepath);
19
- const resource = new Resource();
20
- return resource.toJson();
21
- }
22
- catch (error) {
23
- throw new JsonRpcException(`Error listing resource`, ErrorCode.InternalError, ctx.request.id, { error });
24
- }
25
- }));
14
+ const resourceTemplates = paginatedResources['resourceTemplates'].map((entry) => entry.json);
26
15
  if (paginatedResources.nextCursor) {
27
16
  nextCursor = paginatedResources.nextCursor;
28
17
  }
@@ -1 +1 @@
1
- {"version":3,"file":"list_resources.d.ts","sourceRoot":"","sources":["../../../../src/server/methods/list_resources.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAOnD,MAAM,CAAC,OAAO,OAAO,aAAc,YAAW,MAAM;IAC5C,MAAM,CAAC,GAAG,EAAE,UAAU;CAoC7B"}
1
+ {"version":3,"file":"list_resources.d.ts","sourceRoot":"","sources":["../../../../src/server/methods/list_resources.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,KAAK,EAAE,MAAM,EAAoB,MAAM,uBAAuB,CAAA;AAKrE,MAAM,CAAC,OAAO,OAAO,aAAc,YAAW,MAAM;IAC5C,MAAM,CAAC,GAAG,EAAE,UAAU;CAuB7B"}
@@ -4,25 +4,14 @@
4
4
  * @license MIT
5
5
  * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
6
  */
7
- import { ErrorCode } from '../../enums/error.js';
8
- import JsonRpcException from '../exceptions/jsonrpc_exception.js';
9
7
  import { CursorPaginator } from '../pagination/cursor_paginator.js';
10
8
  import Response from '../../response.js';
11
9
  export default class ListResources {
12
10
  async handle(ctx) {
13
11
  let nextCursor;
14
- const paginator = new CursorPaginator(Object.values(await ctx.getResources()), ctx.getPerPage(), ctx.request.params?.cursor);
12
+ const paginator = new CursorPaginator(Object.values(ctx.resources), ctx.getPerPage(), ctx.request.params?.cursor);
15
13
  const paginatedResources = paginator.paginate('resources');
16
- const resources = await Promise.all(paginatedResources['resources'].map(async (filepath) => {
17
- try {
18
- const { default: Resource } = await import(filepath);
19
- const resource = new Resource();
20
- return resource.toJson();
21
- }
22
- catch (error) {
23
- throw new JsonRpcException(`Error listing resource`, ErrorCode.InternalError, ctx.request.id, { error });
24
- }
25
- }));
14
+ const resources = paginatedResources['resources'].map((entry) => entry.json);
26
15
  if (paginatedResources.nextCursor) {
27
16
  nextCursor = paginatedResources.nextCursor;
28
17
  }
@@ -1 +1 @@
1
- {"version":3,"file":"list_tools.d.ts","sourceRoot":"","sources":["../../../../src/server/methods/list_tools.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAOnD,MAAM,CAAC,OAAO,OAAO,SAAU,YAAW,MAAM;IACxC,MAAM,CAAC,GAAG,EAAE,UAAU;CAoC7B"}
1
+ {"version":3,"file":"list_tools.d.ts","sourceRoot":"","sources":["../../../../src/server/methods/list_tools.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAMnD,MAAM,CAAC,OAAO,OAAO,SAAU,YAAW,MAAM;IACxC,MAAM,CAAC,GAAG,EAAE,UAAU;CAqB7B"}
@@ -4,8 +4,6 @@
4
4
  * @license MIT
5
5
  * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
6
  */
7
- import { ErrorCode } from '../../enums/error.js';
8
- import JsonRpcException from '../exceptions/jsonrpc_exception.js';
9
7
  import { CursorPaginator } from '../pagination/cursor_paginator.js';
10
8
  import Response from '../../response.js';
11
9
  export default class ListTools {
@@ -13,16 +11,7 @@ export default class ListTools {
13
11
  let nextCursor;
14
12
  const paginator = new CursorPaginator(Object.values(ctx.tools), ctx.getPerPage(), ctx.request.params?.cursor);
15
13
  const paginatedTools = paginator.paginate('tools');
16
- const tools = await Promise.all(paginatedTools['tools'].map(async (filepath) => {
17
- try {
18
- const { default: Tool } = await import(filepath);
19
- const tool = new Tool();
20
- return tool.toJson();
21
- }
22
- catch (error) {
23
- throw new JsonRpcException(`Error listing tool`, ErrorCode.InternalError, ctx.request.id, { error });
24
- }
25
- }));
14
+ const tools = paginatedTools['tools'].map((entry) => entry.json);
26
15
  if (paginatedTools.nextCursor) {
27
16
  nextCursor = paginatedTools.nextCursor;
28
17
  }
@@ -1 +1 @@
1
- {"version":3,"file":"read_resource.d.ts","sourceRoot":"","sources":["../../../../src/server/methods/read_resource.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAU7D,MAAM,CAAC,OAAO,OAAO,YAAa,YAAW,MAAM;IAC3C,MAAM,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,oDAAqB;CA6B5D"}
1
+ {"version":3,"file":"read_resource.d.ts","sourceRoot":"","sources":["../../../../src/server/methods/read_resource.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAU7D,MAAM,CAAC,OAAO,OAAO,YAAa,YAAW,MAAM;IAC3C,MAAM,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,oDAAqB;CAmC5D"}
@@ -18,15 +18,22 @@ export default class ReadResource {
18
18
  const resource = await findResource({
19
19
  app,
20
20
  uri: params.uri,
21
- resourceList: ctx.resources,
21
+ resourceList: { ...ctx.resources, ...ctx.resourceTemplates },
22
22
  ctx,
23
23
  });
24
24
  const content = await app.container.call(resource, 'handle', [ctx]);
25
25
  const data = [content];
26
26
  const result = { contents: [] };
27
- data.forEach(async (content) => {
28
- result.contents.push(await content.toResource(resource));
29
- });
27
+ for (const content of data) {
28
+ try {
29
+ result.contents.push(await content.toResource(resource));
30
+ }
31
+ catch (error) {
32
+ throw new JsonRpcException(error.message, ErrorCode.InvalidParams, ctx.request.id, {
33
+ uri: resource.uri,
34
+ });
35
+ }
36
+ }
30
37
  return Response.toJsonRpc({ id: ctx.request.id, result });
31
38
  }
32
39
  }
@@ -1,8 +1,10 @@
1
- export declare class CursorPaginator {
1
+ export declare class CursorPaginator<T> {
2
2
  #private;
3
- constructor(items: unknown[], perPage: number, cursor?: string);
4
- paginate(key?: string): {
5
- [key: string]: unknown;
3
+ constructor(items: T[], perPage: number, cursor?: string);
4
+ paginate<K extends string>(key: K): {
5
+ [P in K]: T[];
6
+ } & {
7
+ nextCursor?: string;
6
8
  };
7
9
  protected getStartOffsetFromCursor(): number;
8
10
  protected createCursor(offset: number): string;
@@ -1 +1 @@
1
- {"version":3,"file":"cursor_paginator.d.ts","sourceRoot":"","sources":["../../../../src/server/pagination/cursor_paginator.ts"],"names":[],"mappings":"AAAA,qBAAa,eAAe;;gBAKd,KAAK,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;IAMvD,QAAQ,CAAC,GAAG,GAAE,MAAgB,GAAG;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE;IAkBlE,SAAS,CAAC,wBAAwB;IA0BlC,SAAS,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM;CAGtC"}
1
+ {"version":3,"file":"cursor_paginator.d.ts","sourceRoot":"","sources":["../../../../src/server/pagination/cursor_paginator.ts"],"names":[],"mappings":"AAKA,qBAAa,eAAe,CAAC,CAAC;;gBAKhB,KAAK,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;IAMjD,QAAQ,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG;SAAG,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;KAAE,GAAG;QAAE,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE;IAkBtF,SAAS,CAAC,wBAAwB,IAAI,MAAM;IA0B5C,SAAS,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;CAG/C"}
@@ -7,7 +7,7 @@ export class CursorPaginator {
7
7
  this.#perPage = perPage;
8
8
  this.#cursor = cursor;
9
9
  }
10
- paginate(key = 'items') {
10
+ paginate(key) {
11
11
  const startOffset = this.getStartOffsetFromCursor();
12
12
  const paginatedItems = this.#items.slice(startOffset, startOffset + this.#perPage);
13
13
  const hasMorePages = this.#items.length > startOffset + this.#perPage;
@@ -29,12 +29,12 @@ export class CursorPaginator {
29
29
  return 0;
30
30
  }
31
31
  const cursorData = JSON.parse(decodedCursor);
32
- if (!cursorData.hasOwnProperty('offset')) {
32
+ if (!cursorData.hasOwnProperty('offset') || typeof cursorData.offset !== 'number') {
33
33
  return 0;
34
34
  }
35
- return parseInt(cursorData.offset);
35
+ return cursorData.offset;
36
36
  }
37
- catch (error) {
37
+ catch (_error) {
38
38
  //
39
39
  }
40
40
  return 0;
@@ -7,6 +7,7 @@
7
7
  import type { JSONSchema } from '../types/method.js';
8
8
  import type { Completion } from '../types/jsonrpc.js';
9
9
  import type { PromptContext, CompleteContext } from '../types/context.js';
10
+ import type { InferJSONSchema } from '../types/method.js';
10
11
  import type { Content } from './contracts/content.js';
11
12
  export declare abstract class Prompt<T extends JSONSchema = JSONSchema> {
12
13
  abstract name: string;
@@ -22,6 +23,6 @@ export declare abstract class Prompt<T extends JSONSchema = JSONSchema> {
22
23
  _meta: Record<string, unknown> | undefined;
23
24
  };
24
25
  abstract handle(ctx?: PromptContext<T>, ...args: unknown[]): Promise<Content | Content[]>;
25
- complete(ctx?: CompleteContext<T>, ..._args: unknown[]): Promise<Completion>;
26
+ complete(ctx?: CompleteContext<InferJSONSchema<T>>, ..._args: unknown[]): Promise<Completion>;
26
27
  }
27
28
  //# sourceMappingURL=prompt.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../../src/server/prompt.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,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MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAE9B,MAAM,IAAI,CAAC;IAOX,MAAM;;;;;;;IAYN,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,GAAG,OAAO,EAAE,CAAC;IAEnF,QAAQ,CACZ,GAAG,CAAC,EAAE,eAAe,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,EACzC,GAAG,KAAK,EAAE,OAAO,EAAE,GAClB,OAAO,CAAC,UAAU,CAAC;CAKvB"}
@@ -0,0 +1,15 @@
1
+ import type { VineValidator } from '@vinejs/vine';
2
+ import type { Infer, SchemaTypes } from '@vinejs/vine/types';
3
+ import type { ToolContext, ResourceContext, PromptContext, CompleteContext } from '../../types/context.js';
4
+ import type { ValidationOptions } from '@vinejs/vine/types';
5
+ type Context = ToolContext | ResourceContext | PromptContext | CompleteContext;
6
+ type RequestValidationOptions<MetaData extends undefined | Record<string, any>> = ValidationOptions<MetaData> & {
7
+ data?: any;
8
+ };
9
+ export declare class RequestValidator {
10
+ #private;
11
+ constructor(ctx: Context);
12
+ validateUsing<Schema extends SchemaTypes, MetaData extends undefined | Record<string, any>>(validator: VineValidator<Schema, MetaData>, ...[options]: [undefined] extends MetaData ? [options?: RequestValidationOptions<MetaData> | undefined] : [options: RequestValidationOptions<MetaData>]): Promise<Infer<Schema>>;
13
+ }
14
+ export {};
15
+ //# sourceMappingURL=request_validator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request_validator.d.ts","sourceRoot":"","sources":["../../../../src/server/requests/request_validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AACjD,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAC5D,OAAO,KAAK,EACV,WAAW,EACX,eAAe,EACf,aAAa,EACb,eAAe,EAChB,MAAM,wBAAwB,CAAA;AAE/B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAI3D,KAAK,OAAO,GAAG,WAAW,GAAG,eAAe,GAAG,aAAa,GAAG,eAAe,CAAA;AAE9E,KAAK,wBAAwB,CAAC,QAAQ,SAAS,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAC5E,iBAAiB,CAAC,QAAQ,CAAC,GAAG;IAAE,IAAI,CAAC,EAAE,GAAG,CAAA;CAAE,CAAA;AAK9C,qBAAa,gBAAgB;;gBAGf,GAAG,EAAE,OAAO;IAIlB,aAAa,CAAC,MAAM,SAAS,WAAW,EAAE,QAAQ,SAAS,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC9F,SAAS,EAAE,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,EAC1C,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,SAAS,CAAC,SAAS,QAAQ,GACtC,CAAC,OAAO,CAAC,EAAE,wBAAwB,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC,GAC1D,CAAC,OAAO,EAAE,wBAAwB,CAAC,QAAQ,CAAC,CAAC,GAChD,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;CAmB1B"}
@@ -0,0 +1,25 @@
1
+ import JsonRpcError from '../exceptions/jsonrpc_error.js';
2
+ import { ErrorCode } from '../../enums/error.js';
3
+ import JsonRpcException from '../exceptions/jsonrpc_exception.js';
4
+ export class RequestValidator {
5
+ #ctx;
6
+ constructor(ctx) {
7
+ this.#ctx = ctx;
8
+ }
9
+ async validateUsing(validator, ...[options]) {
10
+ const validatorOptions = options || {};
11
+ const data = validatorOptions.data || this.#ctx.args;
12
+ try {
13
+ return await validator.validate(data, validatorOptions);
14
+ }
15
+ catch (error) {
16
+ if (this.#ctx.request.method === 'tools/call') {
17
+ throw new JsonRpcError(error.messages).toJsonRpcResponse();
18
+ }
19
+ else {
20
+ const messages = error.messages.map((m) => m.message);
21
+ throw new JsonRpcException(messages.join(', '), ErrorCode.InvalidParams, this.#ctx.request.id);
22
+ }
23
+ }
24
+ }
25
+ }
@@ -19,6 +19,7 @@ export default class Server {
19
19
  capabilities: Record<string, any>;
20
20
  tools: ToolList;
21
21
  resources: ResourceList;
22
+ resourceTemplates: ResourceList;
22
23
  prompts: PromptList;
23
24
  maxPaginationLength: number;
24
25
  defaultPaginationLength: number;
@@ -38,6 +39,7 @@ export default class Server {
38
39
  addCapability(key: string, value?: boolean): void;
39
40
  addTool(item: ToolList): void;
40
41
  addResource(item: ResourceList): void;
42
+ addResourceTemplate(item: ResourceList): void;
41
43
  addPrompt(item: PromptList): void;
42
44
  connect(transport: Transport): Promise<void>;
43
45
  handle(jsonRequest: JsonRpcRequest): Promise<void | null>;
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,KAAK,EACV,QAAQ,EACR,YAAY,EACZ,UAAU,EAEX,MAAM,mBAAmB,CAAA;AAC1B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAA;AAIhE,OAAO,aAAa,MAAM,qBAAqB,CAAA;AAG/C,MAAM,CAAC,OAAO,OAAO,MAAM;;IAGzB,MAAM,EAAE,SAAS,CAAA;IACjB,IAAI,EAAE,MAAM,CAAwB;IACpC,OAAO,EAAE,MAAM,CAAU;IACzB,YAAY,EAAE,MAAM,CAA2E;IAE/F,wBAAwB,EAAE,MAAM,EAAE,CAA+B;IAEjE,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAUhC;IAED,KAAK,EAAE,QAAQ,CAAK;IACpB,SAAS,EAAE,YAAY,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,EAAE,MAAM,CAAK;IAChC,uBAAuB,EAAE,MAAM,CAAK;IAEpC,OAAO;;;;;;;;;;;MAWN;gBAEW,MAAM,EAAE,SAAS;IA4B7B,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,GAAE,OAAc;IAchD,OAAO,CAAC,IAAI,EAAE,QAAQ;IAGtB,WAAW,CAAC,IAAI,EAAE,YAAY;IAG9B,mBAAmB,CAAC,IAAI,EAAE,YAAY;IAGtC,SAAS,CAAC,IAAI,EAAE,UAAU;IAIpB,OAAO,CAAC,SAAS,EAAE,SAAS;IAI5B,MAAM,CAAC,WAAW,EAAE,cAAc;IA6CxC,aAAa,CAAC,cAAc,EAAE,cAAc;CAgB7C"}
@@ -28,6 +28,7 @@ export default class Server {
28
28
  };
29
29
  tools = {};
30
30
  resources = {};
31
+ resourceTemplates = {};
31
32
  prompts = {};
32
33
  maxPaginationLength = 50;
33
34
  defaultPaginationLength = 15;
@@ -80,6 +81,9 @@ export default class Server {
80
81
  addResource(item) {
81
82
  this.resources = { ...this.resources, ...item };
82
83
  }
84
+ addResourceTemplate(item) {
85
+ this.resourceTemplates = { ...this.resourceTemplates, ...item };
86
+ }
83
87
  addPrompt(item) {
84
88
  this.prompts = { ...this.prompts, ...item };
85
89
  }
@@ -133,6 +137,7 @@ export default class Server {
133
137
  defaultPaginationLength: this.defaultPaginationLength,
134
138
  tools: this.tools,
135
139
  resources: this.resources,
140
+ resourceTemplates: this.resourceTemplates,
136
141
  prompts: this.prompts,
137
142
  jsonRpcRequest,
138
143
  });
@@ -4,7 +4,8 @@
4
4
  * @license MIT
5
5
  * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
6
  */
7
- import type { JsonRpcRequest, CallToolRequest, ReadResourceRequest, GetPromptRequest, CompleteRequest } from './jsonrpc.js';
7
+ import type { JsonRpcRequest } from './jsonrpc.js';
8
+ import type { McpResourceRequest, McpToolRequest, McpPromptRequest, McpCompleteRequest } from './request.js';
8
9
  import type { McpResourceResponse, McpToolResponse, McpPromptResponse, McpCompleteResponse } from './response.js';
9
10
  import type { Context } from '../server/contracts/context.js';
10
11
  import type { InferJSONSchema, JSONSchema } from './method.js';
@@ -12,29 +13,29 @@ export interface McpContext extends Context {
12
13
  }
13
14
  export type ToolContext<T extends JSONSchema = JSONSchema> = Omit<McpContext, 'response' | 'requestMethod'> & {
14
15
  requestMethod: 'tools/call';
15
- request: CallToolRequest;
16
+ request: McpToolRequest;
16
17
  response: McpToolResponse;
17
18
  args?: InferJSONSchema<T>;
18
19
  };
19
20
  export type ResourceContext<T = {}> = Omit<McpContext, 'response' | 'requestMethod'> & {
20
21
  requestMethod: 'resources/read';
21
- request: ReadResourceRequest;
22
+ request: McpResourceRequest;
22
23
  response: McpResourceResponse;
23
24
  args?: T;
24
25
  };
25
26
  export type PromptContext<T extends JSONSchema = JSONSchema> = Omit<McpContext, 'response' | 'requestMethod'> & {
26
27
  requestMethod: 'prompts/get';
27
- request: GetPromptRequest;
28
+ request: McpPromptRequest;
28
29
  response: McpPromptResponse;
29
30
  args?: InferJSONSchema<T>;
30
31
  };
31
32
  export type CompleteContext<T = {}> = Omit<McpContext, 'response' | 'requestMethod'> & {
32
33
  requestMethod: 'completion/complete';
33
- request: CompleteRequest;
34
+ request: McpCompleteRequest;
34
35
  response: McpCompleteResponse;
35
36
  args?: T;
36
37
  };
37
- export type ServerContextOptions = Omit<McpContext, 'requestMethod' | 'response' | 'request' | 'getPerPage' | 'getResources' | 'getResourceTemplates'> & {
38
+ export type ServerContextOptions = Omit<McpContext, 'requestMethod' | 'response' | 'request' | 'getPerPage'> & {
38
39
  jsonRpcRequest: JsonRpcRequest;
39
40
  };
40
41
  //# sourceMappingURL=context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/types/context.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EACh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AAA;IAC/B,OAAO,EAAE,kBAAkB,CAAA;IAC3B,QAAQ,EAAE,mBAAmB,CAAA;IAC7B,IAAI,CAAC,EAAE,CAAC,CAAA;CACT,CAAA;AAED,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU,IAAI,IAAI,CACjE,UAAU,EACV,UAAU,GAAG,eAAe,CAC7B,GAAG;IACF,aAAa,EAAE,aAAa,CAAA;IAC5B,OAAO,EAAE,gBAAgB,CAAA;IACzB,QAAQ,EAAE,iBAAiB,CAAA;IAC3B,IAAI,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,CAAA;CAC1B,CAAA;AAED,MAAM,MAAM,eAAe,CAAC,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,UAAU,EAAE,UAAU,GAAG,eAAe,CAAC,GAAG;IACrF,aAAa,EAAE,qBAAqB,CAAA;IACpC,OAAO,EAAE,kBAAkB,CAAA;IAC3B,QAAQ,EAAE,mBAAmB,CAAA;IAC7B,IAAI,CAAC,EAAE,CAAC,CAAA;CACT,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG,IAAI,CACrC,UAAU,EACV,eAAe,GAAG,UAAU,GAAG,SAAS,GAAG,YAAY,CACxD,GAAG;IACF,cAAc,EAAE,cAAc,CAAA;CAC/B,CAAA"}
@@ -10,9 +10,13 @@ import type { JsonRpcResponse } from './jsonrpc.js';
10
10
  export interface Method {
11
11
  handle(ctx: McpContext, app?: ApplicationService): JsonRpcResponse | Promise<JsonRpcResponse>;
12
12
  }
13
- export type ToolList = Record<string, string>;
14
- export type ResourceList = Record<string, string>;
15
- export type PromptList = Record<string, string>;
13
+ export type McpRegistryEntry = {
14
+ path: string;
15
+ json: Record<string, unknown>;
16
+ };
17
+ export type ToolList = Record<string, McpRegistryEntry>;
18
+ export type ResourceList = Record<string, McpRegistryEntry>;
19
+ export type PromptList = Record<string, McpRegistryEntry>;
16
20
  export type JSONSchema = {
17
21
  type: 'string';
18
22
  } | {
@@ -22,18 +26,22 @@ export type JSONSchema = {
22
26
  } | {
23
27
  type: 'object';
24
28
  properties: Record<string, JSONSchema>;
25
- required?: string[];
29
+ required?: readonly string[];
26
30
  };
27
- type ObjectSchema = Extract<JSONSchema, {
31
+ export type InferJSONSchema<S extends JSONSchema> = S['type'] extends 'string' ? string : S['type'] extends 'number' ? number : S['type'] extends 'boolean' ? boolean : S extends {
28
32
  type: 'object';
29
- }>;
30
- export type InferJSONSchema<S extends JSONSchema> = S['type'] extends 'string' ? string : S['type'] extends 'number' ? number : S['type'] extends 'boolean' ? boolean : S extends ObjectSchema ? {
31
- [K in keyof S['properties'] as K extends string ? K : never]: K extends (S['required'] extends readonly string[] ? S['required'][number] : never) ? InferJSONSchema<S['properties'][K]> : InferJSONSchema<S['properties'][K]> | undefined;
33
+ properties: infer P extends Record<string, JSONSchema>;
34
+ required?: infer R;
35
+ } ? R extends readonly string[] ? {
36
+ [K in keyof P as K extends R[number] ? K : never]: InferJSONSchema<P[K]>;
37
+ } & {
38
+ [K in keyof P as K extends R[number] ? never : K]?: InferJSONSchema<P[K]>;
39
+ } : {
40
+ [K in keyof P]?: InferJSONSchema<P[K]>;
32
41
  } : never;
33
- export type BaseSchema<P extends Record<string, any> = {}> = {
42
+ export type BaseSchema<P extends Record<string, any> = {}, R extends readonly (keyof P & string)[] = readonly (keyof P & string)[]> = {
34
43
  type: 'object';
35
44
  properties: P;
36
- required?: (keyof P)[];
45
+ required?: R;
37
46
  };
38
- export {};
39
47
  //# sourceMappingURL=method.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"method.d.ts","sourceRoot":"","sources":["../../../src/types/method.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAC9D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAEnD,MAAM,WAAW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MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,GAAG,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,IACrE;IACF,IAAI,EAAE,QAAQ,CAAA;IACd,UAAU,EAAE,CAAC,CAAA;IACb,QAAQ,CAAC,EAAE,CAAC,CAAA;CACb,CAAA"}
@@ -5,6 +5,29 @@
5
5
  * @copyright Jeremy Chaufourier <jeremy@chaufourier.fr>
6
6
  */
7
7
  import type { CallToolRequest, ReadResourceRequest, GetPromptRequest, InitializeRequest, PingRequest, ListToolsRequest, ListResourcesRequest, ListResourceTemplatesRequest, ListPromptsRequest, CompleteRequest, SubscribeRequest, UnsubscribeRequest } from './jsonrpc.js';
8
- export type McpRequestType = 'tools/call' | 'resources/read' | 'prompts/get' | 'initialize' | 'ping' | 'tools/list' | 'resources/list' | 'resources/templates/list' | 'prompts/list' | 'completion/complete' | 'resources/subscribe' | 'resources/unsubscribe';
9
- export type McpRequest<T> = T extends 'tools/call' ? CallToolRequest : T extends 'resources/read' ? ReadResourceRequest : T extends 'prompts/get' ? GetPromptRequest : T extends 'initialize' ? InitializeRequest : T extends 'ping' ? PingRequest : T extends 'tools/list' ? ListToolsRequest : T extends 'resources/list' ? ListResourcesRequest : T extends 'resources/templates/list' ? ListResourceTemplatesRequest : T extends 'prompts/list' ? ListPromptsRequest : T extends 'completion/complete' ? CompleteRequest : T extends 'resources/subscribe' ? SubscribeRequest : T extends 'resources/unsubscribe' ? UnsubscribeRequest : never;
8
+ type RequestMap = {
9
+ 'tools/call': CallToolRequest;
10
+ 'resources/read': ReadResourceRequest;
11
+ 'prompts/get': GetPromptRequest;
12
+ 'initialize': InitializeRequest;
13
+ 'ping': PingRequest;
14
+ 'tools/list': ListToolsRequest;
15
+ 'resources/list': ListResourcesRequest;
16
+ 'resources/templates/list': ListResourceTemplatesRequest;
17
+ 'prompts/list': ListPromptsRequest;
18
+ 'completion/complete': CompleteRequest;
19
+ 'resources/subscribe': SubscribeRequest;
20
+ 'resources/unsubscribe': UnsubscribeRequest;
21
+ };
22
+ export type McpRequestType = keyof RequestMap;
23
+ export type McpRequest<T extends McpRequestType> = T extends keyof RequestMap ? RequestMap[T] : never;
24
+ export interface McpResourceRequest extends McpRequest<'resources/read'> {
25
+ }
26
+ export interface McpToolRequest extends McpRequest<'tools/call'> {
27
+ }
28
+ export interface McpPromptRequest extends McpRequest<'prompts/get'> {
29
+ }
30
+ export interface McpCompleteRequest extends McpRequest<'completion/complete'> {
31
+ }
32
+ export {};
10
33
  //# sourceMappingURL=request.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../src/types/request.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,gBAAgB,EAChB,oBAAoB,EACpB,4BAA4B,EAC5B,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,cAAc,CAAA;AAErB,MAAM,MAAM,cAAc,GACtB,YAAY,GACZ,gBAAgB,GAChB,aAAa,GACb,YAAY,GACZ,MAAM,GACN,YAAY,GACZ,gBAAgB,GAChB,0BAA0B,GAC1B,cAAc,GACd,qBAAqB,GACrB,qBAAqB,GACrB,uBAAuB,CAAA;AAE3B,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS,YAAY,GAC9C,eAAe,GACf,CAAC,SAAS,gBAAgB,GACxB,mBAAmB,GACnB,CAAC,SAAS,aAAa,GACrB,gBAAgB,GAChB,CAAC,SAAS,YAAY,GACpB,iBAAiB,GACjB,CAAC,SAAS,MAAM,GACd,WAAW,GACX,CAAC,SAAS,YAAY,GACpB,gBAAgB,GAChB,CAAC,SAAS,gBAAgB,GACxB,oBAAoB,GACpB,CAAC,SAAS,0BAA0B,GAClC,4BAA4B,GAC5B,CAAC,SAAS,cAAc,GACtB,kBAAkB,GAClB,CAAC,S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AAM,WAAW,kBAAmB,SAAQ,UAAU,CAAC,qBAAqB,CAAC;CAAG"}
@@ -10,8 +10,15 @@ export type ToolResponse = Promise<TextContent> | Promise<ImageContent> | Promis
10
10
  export type ResourceResponse = Promise<BlobResourceContents> | Promise<TextResourceContents>;
11
11
  export type PromptResponse = Promise<TextContent> | Promise<ImageContent> | Promise<AudioContent> | Promise<ErrorBuilder> | Promise<EmbeddedResource>;
12
12
  export type McpToolResponse = Pick<Response<'tools/call'>, 'text' | 'image' | 'audio' | 'structured' | 'resourceLink' | 'embeddedResource' | 'error'>;
13
- export type McpResourceResponse = Pick<Response<'resources/read'>, 'text' | 'blob'>;
14
- export type McpPromptResponse = Pick<Response<'prompts/get'>, 'text' | 'image' | 'audio' | 'embeddedResource' | 'error'>;
13
+ export type McpResourceResponse = Pick<Response<'resources/read'>, 'text' | 'blob' | 'error'>;
14
+ export type McpPromptResponse = Pick<Response<'prompts/get'>, 'text' | 'image' | 'audio' | 'embeddedResource'>;
15
15
  export type McpCompleteResponse = Pick<Response<'completion/complete'>, 'complete'>;
16
- export type McpResponse<T> = T extends 'resources/read' ? McpResourceResponse : T extends 'prompts/get' ? McpPromptResponse : T extends 'tools/call' ? McpToolResponse : T extends 'completion/complete' ? McpCompleteResponse : never;
16
+ type ResponseMap = {
17
+ 'tools/call': McpToolResponse;
18
+ 'resources/read': McpResourceResponse;
19
+ 'prompts/get': McpPromptResponse;
20
+ 'completion/complete': McpCompleteResponse;
21
+ };
22
+ export type McpResponse<T> = T extends keyof ResponseMap ? ResponseMap[T] : never;
23
+ export {};
17
24
  //# sourceMappingURL=response.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"response.d.ts","sourceRoot":"","sources":["../../../src/types/response.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAA;AAC/D,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACj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;AAC7F,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAClC,QAAQ,CAAC,aAAa,CAAC,EACvB,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,kBAAkB,CAChD,CAAA;AACD,MAAM,MAAM,mBAAmB,GAAG,IAAI,CAAC,QAAQ,CAAC,qBAAqB,CAAC,EAAE,UAAU,CAAC,CAAA;AAEnF,KAAK,WAAW,GAAG;IACjB,YAAY,EAAE,eAAe,CAAA;IAC7B,gBAAgB,EAAE,mBAAmB,CAAA;IACrC,aAAa,EAAE,iBAAiB,CAAA;IAChC,qBAAqB,EAAE,mBAAmB,CAAA;CAC3C,CAAA;AAED,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,WAAW,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,KAAK,CAAA"}
@@ -28,7 +28,7 @@ export async function findResource({ app, uri, resourceList, ctx, }) {
28
28
  if (!key) {
29
29
  throw new JsonRpcException(`The resource ${uri} was not found.`, ErrorCode.InvalidParams, ctx.request.id);
30
30
  }
31
- const { default: Resource } = await import(resourceList[key]);
31
+ const { default: Resource } = await import(resourceList[key].path);
32
32
  const resource = await app.container.make(Resource);
33
33
  resource.uri = uri;
34
34
  return resource;
@@ -22,9 +22,9 @@ export default class {{ className }} extends Prompt<Schema> {
22
22
  description = 'Prompt description'
23
23
 
24
24
  async handle({ args, response }: PromptContext<Schema>) {
25
- console.log(args?.text)
26
25
  return [
27
- response.text('Hello, world!')
26
+ response.text('Hello, world!'),
27
+ response.text(args?.text)
28
28
  ]
29
29
  }
30
30